fix: normalize JSON-serialized Buffer in getImage/getFile#444
Merged
Conversation
Server routes for GET /images/:id and GET /files/:id now support content negotiation. Clients sending Accept: application/octet-stream receive binary data with metadata in X-Metadata header, matching the existing vault/dmail pattern. JSON responses preserved as default for backward compatibility. - keymaster-api: add binary response path for images and files routes - keymaster-client: use responseType arraybuffer for getImage/getFile - herald: remove manual Buffer normalization workaround - client tests: update nock mocks for binary responses
e108f66 to
0ef2f5e
Compare
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.
Problem:
KeymasterClient.getImage()andgetFile()return file data as a plain object{ type: "Buffer", data: [137, 80, ...] }instead of a realBuffer. This happens because the keymaster server sends the response viares.json(), and Node'sBuffer.toJSON()serializes to that format. The client never reconstitutes it.This causes the CLI's
get-asset-imageandget-asset-filecommands to crash withERR_INVALID_ARG_TYPEwhen callingfs.writeFileSync().Fix: Add a
normalizeBufferData()helper that detects the JSON-serialized Buffer pattern and converts it back to a realBuffer. Applied in bothgetImage()andgetFile().Other binary methods (
getVaultItem,getDmailAttachment) are not affected — they already useresponseType: 'arraybuffer'withBuffer.from().