|
| 1 | +const statusCodeResponseTypes = { |
| 2 | + 400: "400 Bad Request", |
| 3 | + 401: "401 Unauthorized", |
| 4 | + 405: "405 Method Not Allowed", |
| 5 | + 500: "500 Internal Server Error", |
| 6 | + 502: "502 Bad Gateway", |
| 7 | + 503: "503 Service Unavailable", |
| 8 | + 408: "408 Request Timeout", |
| 9 | + 200: "200 OK", |
| 10 | +} |
| 11 | + |
| 12 | +export const POST = async ({ request }) => { |
| 13 | + let api_key; |
| 14 | + let dataset_id; |
| 15 | + let organization_id; |
| 16 | + |
| 17 | + const requestJSON = await request.json(); |
| 18 | + let url = requestJSON.url; |
| 19 | + if (request && requestJSON.api_key) { |
| 20 | + api_key = requestJSON.api_key; |
| 21 | + }; |
| 22 | + if (request && requestJSON.organization_id) { |
| 23 | + organization_id = requestJSON.organization_id; |
| 24 | + }; |
| 25 | + if (request && requestJSON.dataset_id) { |
| 26 | + dataset_id = requestJSON.dataset_id; |
| 27 | + } |
| 28 | + |
| 29 | + const resp = await fetch(`${url}/api/chunk`, { |
| 30 | + method: "POST", |
| 31 | + headers: { |
| 32 | + "Content-Type": 'application/json', |
| 33 | + "Authorization": api_key, |
| 34 | + "TR-organization-id": organization_id, |
| 35 | + "TR-dataset-id": dataset_id |
| 36 | + } |
| 37 | + }); |
| 38 | + |
| 39 | + await new Promise(resolve => setTimeout(resolve, 1000)); |
| 40 | + |
| 41 | + const resp2 = await fetch(`${url}/api/chunk/${resp.id}`, { |
| 42 | + method: "DELETE", |
| 43 | + headers: { |
| 44 | + "Content-Type": 'application/json', |
| 45 | + "Authorization": api_key, |
| 46 | + "TR-Organization": organization_id, |
| 47 | + "TR-Dataset": dataset_id |
| 48 | + }, |
| 49 | + body: JSON.stringify({ |
| 50 | + "traking_id": resp.tracking_id |
| 51 | + }) |
| 52 | + }); |
| 53 | + |
| 54 | + return new Response(JSON.stringify({ |
| 55 | + "ok": true |
| 56 | + })); |
| 57 | +} |
0 commit comments