MCPcopy
hub / github.com/deepnote/deepnote / initImport

Function initImport

packages/cli/src/utils/import-client.ts:32–62  ·  view source on GitHub ↗
(
  fileName: string,
  fileSize: number,
  domain: string = DEFAULT_DOMAIN
)

Source from the content-addressed store, hash-verified

30 * @throws Error if the request fails
31 */
32export async function initImport(
33 fileName: string,
34 fileSize: number,
35 domain: string = DEFAULT_DOMAIN
36): Promise<InitImportResponse> {
37 const apiEndpoint = getApiEndpoint(domain)
38 const url = `${apiEndpoint}/v1/import/init`
39
40 debug(`Initializing import at ${url}`)
41
42 const response = await fetch(url, {
43 method: 'POST',
44 headers: {
45 'Content-Type': 'application/json',
46 },
47 body: JSON.stringify({
48 fileName,
49 fileSize,
50 }),
51 signal: AbortSignal.timeout(30_000),
52 })
53
54 if (!response.ok) {
55 const responseBody = await response.text()
56 debug(`Init import failed - Status: ${response.status}, Body: ${responseBody}`)
57 const message = parseApiErrorMessage(responseBody, 'Failed to initialize import')
58 throw new ImportError(message, response.status)
59 }
60
61 return (await response.json()) as InitImportResponse
62}
63
64/**
65 * Uploads a file to the presigned S3 URL.

Callers 2

openDeepnoteFileInCloudFunction · 0.90

Calls 3

getApiEndpointFunction · 0.90
debugFunction · 0.90
parseApiErrorMessageFunction · 0.90

Tested by

no test coverage detected