-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
654 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { NextApiRequest, NextApiResponse } from "next"; | ||
|
||
export default async function handler( | ||
req: NextApiRequest, | ||
res: NextApiResponse | ||
) { | ||
try { | ||
const headers = new Headers(req.headers as Record<string, string>); | ||
headers.set("content-type", "application/json"); | ||
headers.set("Authorization", `Bearer ${req.headers.authorization}`); | ||
|
||
const response = await fetch( | ||
`${global.process.env.NEXT_PUBLIC_API_URL}/api/ai/check`, | ||
{ | ||
method: "GET", | ||
headers, | ||
} | ||
); | ||
|
||
if (!response.ok) { | ||
throw new Error(`Error: ${response.statusText}`); | ||
} | ||
|
||
const result = await response.json(); | ||
res.status(200).json(result); | ||
} catch (error) { | ||
console.error("Error submitting scrape job:", error); | ||
res.status(500).json({ error: "Internal Server Error" }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { NextApiRequest, NextApiResponse } from "next"; | ||
|
||
export default async function handler( | ||
req: NextApiRequest, | ||
res: NextApiResponse | ||
) { | ||
const { data } = req.body; | ||
|
||
try { | ||
const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/ai`, { | ||
method: "POST", | ||
headers: { | ||
Accept: "text/event-stream", | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify(data), | ||
}); | ||
|
||
if (!response.ok) { | ||
const errorDetails = await response.text(); | ||
if (response.status === 422) { | ||
console.error(`422 Error: ${errorDetails}`); | ||
} | ||
throw new Error( | ||
`Error fetching logs: ${response.statusText} - ${errorDetails}` | ||
); | ||
} | ||
|
||
if (!response.body) { | ||
throw new Error(`No response body from API`); | ||
} | ||
|
||
res.writeHead(200, { | ||
"Content-Type": "text/event-stream", | ||
"Cache-Control": "no-cache, no-transform", | ||
Connection: "keep-alive", | ||
"Transfer-Encoding": "chunked", | ||
}); | ||
|
||
let responseStream = response.body; | ||
const reader = responseStream.getReader(); | ||
const decoder = new TextDecoder(); | ||
|
||
while (true) { | ||
const { done, value } = await reader.read(); | ||
if (done) break; | ||
const chunk = decoder.decode(value, { stream: true }); | ||
res.write(`${chunk}`); | ||
} | ||
|
||
res.end(); | ||
} catch (error) { | ||
console.error("Error streaming logs:", error); | ||
res.status(500).json({ error: "Internal Server Error" }); | ||
} | ||
} |
Oops, something went wrong.