fix(uploads): HEIC upload 500 — pass iterable Buffer to heic-convert (#135 never worked)#17
Merged
Merged
Conversation
The /api/uploads route forwarded `await file.arrayBuffer()` (a raw ArrayBuffer) to heic-convert. heic-decode's isHeic() spreads the input (`String.fromCharCode(...buf.slice(8,12))`), which requires an iterable — an ArrayBuffer is not iterable, so HEIC uploads threw "Found non-callable @@iterator" and 500'd. The HEIC support added in PR #16 never actually worked on a real iPhone photo. Root contributor: @types/heic-convert mistypes `buffer` as ArrayBufferLike, which lured the route into passing the wrong shape. - Add heicToJpeg() helper that normalizes any binary input to an iterable Buffer (casting past the incorrect d.ts). - Route uses the helper. - Regression coverage via node:test + a real ~1KB HEIC fixture: Buffer, ArrayBuffer, and Uint8Array inputs all yield a JPEG. Adds tsx + `npm test`. Reproduced against a real HEIC; fix verified end-to-end (HEIC -> JPEG).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
End-to-end testing of the staff-portal I-9 flow surfaced a launch-blocking bug: submitting an I-9 with a HEIC document photo fails with
/api/uploadsforwardedawait file.arrayBuffer()— a rawArrayBuffer— toheic-convert. Internallyheic-decode'sisHeic()does:Spread requires an iterable. A
Buffer/Uint8Arrayis iterable; a rawArrayBufferis not, so it throwsFound non-callable @@iterator(older V8) /Spread syntax requires ...iterable[Symbol.iterator] to be a function(newer V8) and the upload 500s.It only triggers on the HEIC/HEIF path, so non-HEIC docs (e.g. a JPEG license) worked — which is why the HEIC support added in #16 (#135) never actually worked on a real iPhone photo.
Contributing cause:
@types/heic-convertmistypesbufferasArrayBufferLike, which is what lured the route into passing a rawArrayBuffer(type-checks, crashes at runtime).Fix
src/lib/heic.ts→heicToJpeg(input)normalizesBuffer | Uint8Array | ArrayBufferto an iterable Buffer before callingheic-convert(and casts past the incorrect d.ts)./api/uploadscalls the helper.Tests
Adds
node:test(run viatsx,npm test) + a real ~1KB HEIC fixture made withsips. Covers Buffer, ArrayBuffer (the exact regression), and Uint8Array inputs — all must yield a JPEG.Verified:
tsc --noEmitclean (0 errors),next lintclean, reproduced the original failure and confirmed the fix end-to-end (real HEIC → valid JPEG).Deploy note
No staff-portal change needed — it correctly forwards the HEIC. After this deploys, re-run the I-9 submit to confirm.