oficina / slides Public

Slides: pictures stream through the app instead of being read whole; AGENTS says the bucket is served through the app

Claude Fable on #41 (approved 04beeaa), P2 and P3: serveAsset read up to
20 MiB per uncached view into memory; it now reads the 1 KiB head the
sniff needs, sends it, and streams the rest, with the content hash as a
strong ETag (304 on a match). ThroughApp's comment now says what the way
in really costs (rastrillo's S3.Put holds the body twice; registration
reads it again). AGENTS.md no longer says no store is bound and names
ThroughApp as what production runs.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev e56af28de64cd8156dc9832e6a5a10a8d7b766bd parent 04beeaa
2 files changed, +33 −10
  • AGENTS.md +10 −4
  • internal/slides/assets.go +23 −6

CI passed — run details

diff --git a/AGENTS.md b/AGENTS.md
index cd899a9..0344587 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -128,10 +128,16 @@ comments, and version history. Those are the triggers in spec ยง9.
`docs/api.md` is the reference for the API, written for a person and an
agent both.
-**The deployment has no object store bound today** (`carlos store create`
-is the fix, and nobody has run it). The upload endpoints answer
-`503` there and the editor's image field says so, server-rendered, rather
-than letting somebody pick a file and find out afterwards.
+**The deployment's object store is bound (2026-11-11, bucket
+`carlos-store-bds-slides`) and served through the app**, not presigned:
+`cmd/slides` wraps it in `slides.ThroughApp`, so the browser uploads to
+`PUT /d/{sqid}/uploads/{key}` and pictures and exports stream back from
+this app. The presigned path below is the design and still what a
+presigning store would take, but the page's CSP (`default-src 'self'`,
+`img-src 'self' data:`) refuses a browser PUT to the bucket and a picture
+from it, and the bucket has no CORS for this origin; going direct needs
+both changed. With no store bound at all the upload endpoints answer
+`503` and the editor's image field says so.
## Layout
diff --git a/internal/slides/assets.go b/internal/slides/assets.go
index 598c946..cde07d9 100644
--- a/internal/slides/assets.go
+++ b/internal/slides/assets.go
@@ -157,8 +157,11 @@ type presigner interface {
// the path had never run. Going direct again needs the bucket's origin
// in connect-src and img-src and a CORS rule on the bucket; until then
// this is the path that works. The cost is the bytes passing through
-// one instance: a 20 MiB picture once on the way in, and on every
-// uncached view on the way out (Cache-Control below keeps that rare).
+// one instance. On the way out a picture is streamed (serveAsset). On
+// the way in rastrillo's blobs.S3.Put holds the body in memory (twice,
+// as of v0.27), and registration reads it again to sniff and promote,
+// so one 20 MiB upload can take ~60 MiB for a moment โ€” fine for one
+// team, and a rastrillo streaming Put is the fix when it is not.
func ThroughApp(s blobs.Store) blobs.Store {
if s == nil {
return nil
@@ -817,12 +820,19 @@ func (a *app) serveAsset(w http.ResponseWriter, r *http.Request, d Deck) {
return
}
defer rc.Close()
- raw, err := io.ReadAll(io.LimitReader(rc, maxAssetBytes+1))
- if err != nil {
+ // Streamed, not read whole: the bucket is served through this app
+ // (ThroughApp), and a deck of large photos opened by a few readers
+ // at once would otherwise hold 20 MiB per picture per request. The
+ // sniff needs only the head (sniffImage reads 1 KiB), which is read
+ // first and sent ahead of the rest.
+ head := make([]byte, 1024)
+ n, err := io.ReadFull(rc, head)
+ if err != nil && !errors.Is(err, io.ErrUnexpectedEOF) && !errors.Is(err, io.EOF) {
a.fail(w, r, "read an asset", err)
return
}
- kind := sniffImage(raw)
+ head = head[:n]
+ kind := sniffImage(head)
if kind == "" {
a.notFound(w, r)
return
@@ -832,7 +842,14 @@ func (a *app) serveAsset(w http.ResponseWriter, r *http.Request, d Deck) {
// is honest. Private rather than public โ€” the address is the deck's
// capability, not the object's.
w.Header().Set("Cache-Control", "private, max-age=31536000, immutable")
- http.ServeContent(w, r, ref, time.Time{}, bytes.NewReader(raw))
+ // The ref is the content hash, so it is an honest strong validator.
+ w.Header().Set("ETag", `"`+ref+`"`)
+ if match := r.Header.Get("If-None-Match"); match != "" && strings.Contains(match, `"`+ref+`"`) {
+ w.WriteHeader(http.StatusNotModified)
+ return
+ }
+ w.Write(head)
+ io.Copy(w, io.LimitReader(rc, maxAssetBytes-int64(len(head))))
}
// assetHeaders is the header set every served asset carries.