(
absolutePath: string,
options: OpenInCloudOptions = {}
)
| 24 | * @returns The launch URL and import ID |
| 25 | */ |
| 26 | export async function openDeepnoteFileInCloud( |
| 27 | absolutePath: string, |
| 28 | options: OpenInCloudOptions = {} |
| 29 | ): Promise<OpenInCloudResult> { |
| 30 | const domain = options.domain ?? DEFAULT_DOMAIN |
| 31 | const fileName = basename(absolutePath) |
| 32 | const c = getChalk() |
| 33 | |
| 34 | // Helper to output progress (suppressed in quiet mode) |
| 35 | const progress = (message: string) => { |
| 36 | if (!options.quiet) { |
| 37 | output(`${c.dim(message)}`) |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | // Validate file size |
| 42 | progress('Validating file...') |
| 43 | const fileSize = await validateFileSize(absolutePath) |
| 44 | debug(`File size: ${fileSize} bytes`) |
| 45 | |
| 46 | // Read file contents |
| 47 | progress('Reading file...') |
| 48 | const fileBuffer = await fs.readFile(absolutePath) |
| 49 | |
| 50 | // Initialize import and upload file |
| 51 | let initResponse: Awaited<ReturnType<typeof initImport>> |
| 52 | try { |
| 53 | progress('Preparing upload...') |
| 54 | initResponse = await initImport(fileName, fileSize, domain) |
| 55 | debug(`Import initialized: ${initResponse.importId}`) |
| 56 | |
| 57 | progress('Uploading file...') |
| 58 | await uploadFile(initResponse.uploadUrl, fileBuffer) |
| 59 | } catch (error) { |
| 60 | const originalMessage = error instanceof Error ? error.message : String(error) |
| 61 | const originalStack = error instanceof Error ? error.stack : undefined |
| 62 | const contextualError = new Error( |
| 63 | `Failed to upload file "${fileName}" (size: ${fileSize} bytes, domain: ${domain}): ${originalMessage}` |
| 64 | ) |
| 65 | if (originalStack) { |
| 66 | contextualError.stack = `${contextualError.message}\n${originalStack.split('\n').slice(1).join('\n')}` |
| 67 | } |
| 68 | throw contextualError |
| 69 | } |
| 70 | |
| 71 | // Build and open the launch URL |
| 72 | const launchUrl = buildLaunchUrl(initResponse.importId, domain) |
| 73 | debug(`Launch URL: ${launchUrl}`) |
| 74 | |
| 75 | progress('Opening in browser...') |
| 76 | await openInBrowser(launchUrl) |
| 77 | |
| 78 | return { |
| 79 | url: launchUrl, |
| 80 | importId: initResponse.importId, |
| 81 | } |
| 82 | } |
no test coverage detected