feat: add optional getAttachmentMeta to StackAdapter and SQLiteAdapter#14
Merged
Conversation
…in APIAdapter APIAdapter returns null — it delegates attachment storage to the server, so it holds no metadata locally. Removing the optional marker gives callers a uniform contract and eliminates defensive if (adapter.getAttachmentMeta) guards.
… dedup - putAttachment now takes optional filename - getAttachmentMeta now returns size, createdAt, filename in addition to mimeType - SQLiteAdapter: file ID = SHA-256 hex of bytes; files stored without extension; dedup on putAttachment; deleteAttachment removes the file; schema migration drops old path-based attachments table on open/initialize - APIAdapter: passes filename via Content-Disposition header on upload; getAttachmentMeta returns null (metadata lives on the server)
…apter-api spec.md: - Attachments section: SHA-256 file IDs, dedup behaviour, filename param, getAttachmentMeta, AttachmentMeta type, Uint8Array (was Blob/Buffer) - Wire format Attachments: Content-Disposition upload/download, 413 size limit, MAX_ATTACHMENT_BYTES reference README.md: - Move @haverstack/adapter-api from Planned to main packages table - Remove "coming soon" from haverstack/server link
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.
Summary
getAttachmentMeta?(fileId: FileId): Promise<{ mimeType: string } | null>as an optional method on theStackAdapterinterface inpackages/core/src/types.tsSQLiteAdapter(packages/adapter-sqlite/src/index.ts) via a directSELECT mime_type FROM attachments WHERE file_id = ?queryWhy
When the server serves a stored attachment it needs to know its MIME type. The previous approach reconstructed the MIME type from the file extension (e.g.
image/svg+xml→ stored as.svg+xml→ round-trip fails). Querying theattachmentstable directly avoids this ambiguity because the MIME type is stored verbatim at upload time.The method is optional so adapters that don't persist attachment metadata locally (e.g.
APIAdapter, which delegates to the server) are not required to implement it.Test plan
SQLiteAdapter.getAttachmentMetareturns the correct MIME type for a file uploaded viaputAttachmentnullfor an unknownfileIdGET /attachments/:fileIdreturns the exact MIME type (including types likeimage/svg+xml) and sends 404 before reading binary whengetAttachmentMetareturns nullGenerated by Claude Code