Skip to content

feat: add optional getAttachmentMeta to StackAdapter and SQLiteAdapter#14

Merged
cuibonobo merged 4 commits into
mainfrom
claude/nice-ptolemy-Iai17
May 26, 2026
Merged

feat: add optional getAttachmentMeta to StackAdapter and SQLiteAdapter#14
cuibonobo merged 4 commits into
mainfrom
claude/nice-ptolemy-Iai17

Conversation

@cuibonobo
Copy link
Copy Markdown
Member

Summary

  • Adds getAttachmentMeta?(fileId: FileId): Promise<{ mimeType: string } | null> as an optional method on the StackAdapter interface in packages/core/src/types.ts
  • Implements the method in SQLiteAdapter (packages/adapter-sqlite/src/index.ts) via a direct SELECT mime_type FROM attachments WHERE file_id = ? query

Why

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 the attachments table 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.getAttachmentMeta returns the correct MIME type for a file uploaded via putAttachment
  • Returns null for an unknown fileId
  • Server GET /attachments/:fileId returns the exact MIME type (including types like image/svg+xml) and sends 404 before reading binary when getAttachmentMeta returns null

Generated by Claude Code

cuibonobo added 4 commits May 25, 2026 14:43
…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
@cuibonobo cuibonobo merged commit 04f9b87 into main May 26, 2026
@cuibonobo cuibonobo deleted the claude/nice-ptolemy-Iai17 branch May 26, 2026 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant