#38 iteration 1: file attachments, 1 file per paste
- internal/store/blob.go: BlobStore interface + fs implementation with
traversal-safe keys (<paste-id>/<sha256>), put/get/stat/delete
- attachments table migration (id, paste_id, filename sanitized to 255,
mime sniffed server-side, size, sha256, created_at)
- POST /api/pastes now accepts multipart/form-data with a 'file' part;
1 file = 1 paste: file replaces text content when both are sent
- 25 MB per-file limit enforced server-side (413 file_too_large)
- GET /f/{attachment-id}/{filename}: stored sniffed mime, nosniff,
inline only for images/pdf, html/svg/xml forced to text/plain (#34 rule)
- paste view renders attachment chip + inline image preview
- /new: dropzone with file picker, drag-and-drop, Ctrl+V file paste,
file chip with name/size/remove, matches pill/radius design
- tests: blob roundtrip/traversal/sanitize; multipart create (mime
sniffing, client mime ignored, size limit, two-file reject, html/svg
forcing, 404s, password/expiry fields)
This commit is contained in:
+25
-1
@@ -78,7 +78,8 @@ type CanRow struct {
|
||||
}
|
||||
|
||||
type Store struct {
|
||||
db *sql.DB
|
||||
db *sql.DB
|
||||
blob BlobStore // #38: attachment byte storage (nil in some unit tests)
|
||||
}
|
||||
|
||||
func OpenStore(path string) (*Store, error) {
|
||||
@@ -95,6 +96,12 @@ func OpenStore(path string) (*Store, error) {
|
||||
if err := s.migrate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// #38: attachment blobs live beside the database under <db>.files
|
||||
blobs, err := NewFsBlobStore(path + ".files")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s.blob = blobs
|
||||
return s, nil
|
||||
}
|
||||
|
||||
@@ -142,9 +149,26 @@ deletion_token TEXT
|
||||
last_viewed INTEGER NOT NULL,
|
||||
PRIMARY KEY (paste_id, viewer_id)
|
||||
)`) // #49: per-viewer read dedupe window
|
||||
// #38: file attachments, one per paste in iteration 1. mime is sniffed
|
||||
// server-side before insert; bytes live in the BlobStore keyed
|
||||
// <paste_id>/<sha256>.
|
||||
s.db.Exec(`CREATE TABLE IF NOT EXISTS attachments (
|
||||
id TEXT PRIMARY KEY,
|
||||
paste_id TEXT NOT NULL,
|
||||
filename TEXT NOT NULL,
|
||||
mime TEXT NOT NULL,
|
||||
size INTEGER NOT NULL,
|
||||
sha256 TEXT NOT NULL,
|
||||
created_at INTEGER NOT NULL
|
||||
)`)
|
||||
s.db.Exec(`CREATE INDEX IF NOT EXISTS idx_attachments_paste ON attachments(paste_id)`)
|
||||
return err
|
||||
}
|
||||
|
||||
// Blobs returns the attachment blob store (nil when unavailable, e.g. some
|
||||
// unit-test stores).
|
||||
func (s *Store) Blobs() BlobStore { return s.blob }
|
||||
|
||||
// SlugAlphabet is the paste-id charset (no ambiguous chars).
|
||||
var SlugAlphabet = "23456789abcdefghjkmnpqrstuvwxyz"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user