oficina / slides Public

Readers: a conditional thumbnail of a parked slide is still 404

The 304 for If-None-Match came before the slide was known to be visible,
so a wildcard tag turned a parked slide into not modified on /s/ and /p/.
Those routes now check visibility first; /d/ and the API keep the quick
answer. The all-parked test also covers the projector, presenter notes,
remote, follow view and export.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev eea542094236fab03fff6b7bba30881c768221d0 parent fa04dda
2 files changed, +62 −3
  • internal/slides/thumbs.go +15 −2
  • internal/slidestest/talk_readers_test.go +47 −1
diff --git a/internal/slides/thumbs.go b/internal/slides/thumbs.go
index bfa6d71..682da0b 100644
--- a/internal/slides/thumbs.go
+++ b/internal/slides/thumbs.go
@@ -123,9 +123,18 @@ func (a *app) serveThumb(w http.ResponseWriter, r *http.Request, d Deck, base st
// a cache to treat the absence as the thing (editor.go says the
// same about the HTML twin).
etag := strconv.Quote(strconv.FormatInt(d.Seq, 10) + "-" + slideID + "-" + width)
- if matchesETag(r.Header.Get("If-None-Match"), etag) {
+ // A reader's route answers 304 only after the slide is known to be
+ // one it may see (a wildcard tag matches everything, parked slides
+ // included), so it pays a deck open; the editor and the API, which
+ // filter nothing, keep the quick answer.
+ reader := strings.HasPrefix(base, "/s/") || strings.HasPrefix(base, "/p/")
+ notModified := func() {
thumbHeaders(w, etag)
w.WriteHeader(http.StatusNotModified)
+ }
+ conditional := matchesETag(r.Header.Get("If-None-Match"), etag)
+ if conditional && !reader {
+ notModified()
return
}
@@ -138,7 +147,7 @@ func (a *app) serveThumb(w http.ResponseWriter, r *http.Request, d Deck, base st
// The editor's route (/d/…) and the API describe the whole deck; a
// share link and a presentation session are readers, and a parked
// slide is not there for them.
- if strings.HasPrefix(base, "/s/") || strings.HasPrefix(base, "/p/") {
+ if reader {
view = view.ForReaders()
}
@@ -153,6 +162,10 @@ func (a *app) serveThumb(w http.ResponseWriter, r *http.Request, d Deck, base st
missing()
return
}
+ if conditional {
+ notModified()
+ return
+ }
out, err := a.thumbnail(r, d, view, index, base)
if err != nil {
diff --git a/internal/slidestest/talk_readers_test.go b/internal/slidestest/talk_readers_test.go
index 9a4912b..7380ce4 100644
--- a/internal/slidestest/talk_readers_test.go
+++ b/internal/slidestest/talk_readers_test.go
@@ -2,6 +2,7 @@ package slidestest
import (
"net/http"
+ "net/http/httptest"
"net/url"
"strings"
"testing"
@@ -131,6 +132,38 @@ func TestAParkedSlideReachesNoReader(t *testing.T) {
})
}
+// TestAConditionalThumbnailOfAParkedSlideIsStill404: a wildcard or a
+// matching tag must not turn "no such slide" into "not modified".
+func TestAConditionalThumbnailOfAParkedSlideIsStill404(t *testing.T) {
+ a := newApp(t)
+ cookies := signedIn(t, a, allowedAddress)
+ path, _, _ := markedDeck(t, a, cookies, mixedTalk)
+ share := "/s/" + mintShareLink(t, a, path, cookies)
+ session, _ := startPresenting(t, a, path, cookies)
+ seq := ""
+ if row := a.db.G.Raw("SELECT seq FROM decks WHERE sqid = ?", strings.TrimPrefix(path, "/d/")).Row(); row != nil {
+ row.Scan(&seq)
+ }
+ for _, base := range []string{share, "/p/" + session} {
+ for _, tag := range []string{"*", `"` + seq + `-pone-` + `"`, `"` + seq + `-pone-480"`, `"` + seq + `-pone-1920"`} {
+ req := httptest.NewRequest(http.MethodGet, base+"/slides/pone.svg", nil)
+ req.Header.Set("If-None-Match", tag)
+ rec := httptest.NewRecorder()
+ a.ServeHTTP(rec, req)
+ if rec.Code != http.StatusNotFound {
+ t.Errorf("GET %s parked, If-None-Match %s: status %d, want 404", base, tag, rec.Code)
+ }
+ }
+ req := httptest.NewRequest(http.MethodGet, base+"/slides/stwo.svg", nil)
+ req.Header.Set("If-None-Match", "*")
+ rec := httptest.NewRecorder()
+ a.ServeHTTP(rec, req)
+ if rec.Code != http.StatusNotModified {
+ t.Errorf("GET %s shown slide, If-None-Match *: status %d, want 304", base, rec.Code)
+ }
+ }
+}
+
// TestAFullOnlySlideShowsToReaders: full only is a way of giving the
// talk, not a way of hiding a slide: readers get it.
func TestAFullOnlySlideShowsToReaders(t *testing.T) {
@@ -179,17 +212,30 @@ func TestEveryParkedDeckIsEmptyToReaders(t *testing.T) {
{"ptwo", "parked", "PARKEDTWO"},
})
share := "/s/" + mintShareLink(t, a, path, cookies)
+ session, remote := startPresenting(t, a, path, cookies)
- for _, target := range []string{share, path + "?slide=1", path + "/notes"} {
+ for _, target := range []string{share, path + "?slide=1", path + "/notes",
+ "/p/" + session, "/p/" + session + "/notes", "/p/" + session + "/remote?t=" + remote} {
rec := get(t, a, target, cookies...)
if target == share {
rec = get(t, a, target)
}
+ if strings.Contains(target, "/remote") {
+ rec = get(t, a, target)
+ }
body := rec.Body.String()
if rec.Code != http.StatusOK || strings.Contains(body, "PARKED") || strings.Contains(body, "<section slides-slide") {
t.Errorf("GET %s: status %d, want an empty page with no slide:\n%s", target, rec.Code, body)
}
}
+ if rec := get(t, a, share+"?follow=1"); rec.Code != http.StatusOK && rec.Code != http.StatusSeeOther || strings.Contains(rec.Body.String(), "PARKED") {
+ t.Errorf("the follow view of an all-parked deck: status %d, want the empty page or a redirect", rec.Code)
+ }
+ // Nothing is left to export, as for an empty deck: the job says so.
+ status := startExport(t, a, path, cookies, url.Values{})
+ if fragment := waitForExport(t, a, status, cookies); !strings.Contains(fragment, "rst-tone=\"negative\"") {
+ t.Errorf("exporting an all-parked deck did not fail:\n%s", fragment)
+ }
// An empty deck answers any slide with its empty page, and so does this.
if rec := get(t, a, share+"?slide=1"); rec.Code != http.StatusOK || strings.Contains(rec.Body.String(), "<section slides-slide") {
t.Errorf("slide 1 of an all-parked deck over a share link: status %d, want the empty page", rec.Code)