Skip to content

Commit

Permalink
feat(chat2query-api): add job status api
Browse files Browse the repository at this point in the history
  • Loading branch information
baurine committed Jun 27, 2024
1 parent 3add94e commit aae6cef
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion netlify/edge-functions/chat2data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default async (req: Request, _context: Context) => {
return new Response(
JSON.stringify({
code: 400,
message: 'bad request params, database or question should not empty.',
message: 'bad request, database or question should not empty.',
data: {}
}),
{ status: 400 }
Expand Down
37 changes: 37 additions & 0 deletions netlify/edge-functions/job_status.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import type { Config, Context } from '@netlify/edge-functions'

const endpoint = Netlify.env.get('TIDBCLOUD_CHAT2QUERY_APP_URL_ENDPOINT')
const publicKey = Netlify.env.get('TIDBCLOUD_CHAT2QUERY_APP_PUBLIC_KEY')
const privateKey = Netlify.env.get('TIDBCLOUD_CHAT2QUERY_APP_PRIVATE_KEY')

export default async (req: Request, _context: Context) => {
const url = new URL(req.url)
const jobId = url.searchParams.get('job_id')
if (!jobId) {
return new Response(
JSON.stringify({
code: 400,
message: 'bad request, job_id is empty',
data: {}
}),
{ status: 400 }
)
}

const jobStatusUrl = endpoint + `/v2/jobs/${jobId}`

const fetchOptions = {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Authorization: 'Basic ' + btoa(`${publicKey}:${privateKey}`)
}
}

const res = await fetch(jobStatusUrl, fetchOptions).then((res) => res.json())

return new Response(JSON.stringify(res))
}

// /api/jobs?job_id=xxx
export const config: Config = { path: '/api/jobs' }

0 comments on commit aae6cef

Please sign in to comment.