-
-
Notifications
You must be signed in to change notification settings - Fork 11
feat(kit): async product sync with job queue, dry-run, and purge-local #127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
83d18fc
acaaa8e
3c9421f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -179,10 +179,30 @@ export const readFileAsBase64 = internalAction({ | |
| // accessCount: (file.accessCount || 0) + 1, | ||
| // }); | ||
|
|
||
| // Convert blob to base64 via Buffer (Convex actions run on Node/Bun | ||
| // — Buffer is available globally and avoids the per-byte loop). | ||
| // Convex `internalAction`s without `"use node"` run in the V8 | ||
| // isolate runtime where `Buffer` is NOT a global — using it | ||
| // throws `ReferenceError: Buffer is not defined` at request time | ||
| // (the prior `Buffer.from(...)` shipped here was the bug behind | ||
| // the dashboard's "download .p8" failing). Encode via `btoa` on | ||
| // chunked binary strings so the path stays portable to either | ||
| // runtime; chunking keeps the call-stack bound below the | ||
| // `String.fromCharCode` argument limit for files of any size, | ||
| // and accumulating the chunks in an array before `join("")` | ||
| // avoids the O(n²) string-concatenation behavior of `binary +=` | ||
| // on multi-megabyte uploads (Copilot review on PR #127). | ||
| const arrayBuffer = await blob.arrayBuffer(); | ||
| const base64 = Buffer.from(arrayBuffer).toString("base64"); | ||
| const bytes = new Uint8Array(arrayBuffer); | ||
| const CHUNK = 0x8000; | ||
| const chunks: string[] = []; | ||
| for (let i = 0; i < bytes.length; i += CHUNK) { | ||
| chunks.push( | ||
| String.fromCharCode.apply( | ||
| null, | ||
| bytes.subarray(i, i + CHUNK) as unknown as number[], | ||
| ), | ||
| ); | ||
| } | ||
|
Comment on lines
+199
to
+204
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While for (let i = 0; i < bytes.length; i += CHUNK) {
const subarray = bytes.subarray(i, i + CHUNK);
let chunk = "";
for (let j = 0; j < subarray.length; j++) {
chunk += String.fromCharCode(subarray[j]);
}
chunks.push(chunk);
} |
||
| const base64 = btoa(chunks.join("")); | ||
|
|
||
| return { | ||
| fileId: file._id, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.