Skip to content

Commit 066e594

Browse files
feat(api): return each slide's speaker notes in the deck detail (#20) (#698)
* feat(api): return each slide's speaker notes in the deck detail (#20) Signed-off-by: Ym <173550318+MaxonT@users.noreply.github.com> * fix(api): return slide notes to the deck owner only (#20) A viewer of a public deck could get notes that no download carries yet (deck not built, or notes edited since the last build). Default to owner-only. Signed-off-by: Ym <173550318+MaxonT@users.noreply.github.com> --------- Signed-off-by: Ym <173550318+MaxonT@users.noreply.github.com> Co-authored-by: ShotaroKataoka <shotaro.kata@gmail.com>
1 parent 5300935 commit 066e594

5 files changed

Lines changed: 79 additions & 1 deletion

File tree

‎CHANGELOG.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ Under an Upgrading section, the bullets after **Local installs (`sdpm update`).*
1515

1616
### Added
1717

18+
- **Speaker notes in the deck detail** (#20, first step). Each slide entry of `GET /decks/{id}`
19+
(AWS stack) and `GET /api/decks/{id}` (Local Web UI) of a PPTX deck carries the slide's `notes` text as
20+
written in `slides/<slug>.json`; the key is left out for a slide without notes. On the AWS
21+
stack only the owner of a deck gets the notes; a viewer never does, because notes are often the
22+
presenter's private script.
23+
The Presenter view that reads them is not part of this change.
1824
- **Inline colours are checked against the style's colour tokens** (part of #135, by
1925
@MaxonT). When a PPTX deck is built or previewed, `{{#RRGGBB:text}}` colours (also in
2026
`{{bold,#RRGGBB:text}}` and nested forms) that are not a `#RRGGBB` token in the `:root` of

‎api/index.py‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1198,16 +1198,25 @@ def get_deck(deck_id: str) -> Dict[str, Any]:
11981198
pass
11991199

12001200
preview_keys = _list_preview_keys(deck_id)
1201+
# Speaker notes stay with the owner: they are often the presenter's private script, and a
1202+
# deck that is not built yet, or edited since the last build, has them in no download.
1203+
share_notes = decision.role == "owner"
12011204
for i, slug in enumerate(slugs):
1205+
slide_json: Any = None
12021206
if legacy_slides is None:
12031207
# A slug whose slides/{slug}.json is missing or unreadable is not listed.
12041208
try:
12051209
slide_resp = s3_client.get_object(Bucket=BUCKET_NAME, Key=f"decks/{deck_id}/slides/{slug}.json")
1206-
json.loads(slide_resp["Body"].read())
1210+
slide_json = json.loads(slide_resp["Body"].read())
12071211
except Exception:
12081212
continue
1213+
else:
1214+
slide_json = legacy_slides[i]
12091215
slide_preview = _resolve_preview_url(deck_id, slug, preview_keys)
12101216
slide_entry: Dict[str, Any] = {"slug": slug, "previewUrl": slide_preview}
1217+
notes = slide_json.get("notes") if isinstance(slide_json, dict) else None
1218+
if share_notes and isinstance(notes, str) and notes.strip():
1219+
slide_entry["notes"] = notes
12111220
compose_key = latest_compose.get(slug) or latest_compose.get(f"slide_{i + 1}")
12121221
if compose_key:
12131222
slide_entry["composeUrl"] = preview_url(compose_key)

‎tests/test_api_public_decks.py‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,39 @@ def test_get_deck_for_the_owner_keeps_the_session(monkeypatch, index, extra, obj
108108
result = index.get_deck("d1")
109109

110110
assert result["role"] == "owner" and result["chatSessionId"] == SESSION
111+
112+
113+
# --- speaker notes in the slide list ------------------------------------------
114+
115+
_NOTES_OBJECTS = {
116+
**_PPTX_OBJECTS,
117+
"decks/d1/slides/cover.json": json.dumps({"notes": "Say hello {{bold:first}}"}).encode(),
118+
}
119+
120+
121+
def _notes(result: dict) -> list:
122+
return [slide.get("notes") for slide in result["slides"]]
123+
124+
125+
def test_get_deck_lists_the_slide_notes_for_the_owner(monkeypatch, index): # noqa: F811
126+
_serve(monkeypatch, index, _record(index, pptxS3Key="pptx/d1/out.pptx"), _NOTES_OBJECTS, OWNER)
127+
assert _notes(index.get_deck("d1")) == ["Say hello {{bold:first}}"]
128+
129+
130+
def test_get_deck_omits_notes_for_a_slide_without_any(monkeypatch, index): # noqa: F811
131+
_serve(monkeypatch, index, _record(index, pptxS3Key="pptx/d1/out.pptx"), _PPTX_OBJECTS, OWNER)
132+
slide = index.get_deck("d1")["slides"][0]
133+
assert "notes" not in slide
134+
135+
136+
def test_get_deck_viewer_gets_no_notes_even_when_the_pptx_carries_them(monkeypatch, index): # noqa: F811
137+
_serve(monkeypatch, index, _record(index, pptxS3Key="pptx/d1/out.pptx"), _NOTES_OBJECTS, VIEWER)
138+
assert _notes(index.get_deck("d1")) == [None]
139+
140+
141+
def test_get_deck_viewer_does_not_get_notes_kept_out_of_the_pptx(monkeypatch, index): # noqa: F811
142+
record = _record(index, pptxS3Key="pptx/d1/out.pptx", notesS3Key="pptx/d1/out.notes.md")
143+
_serve(monkeypatch, index, record, _NOTES_OBJECTS, VIEWER)
144+
assert _notes(index.get_deck("d1")) == [None]
145+
_serve(monkeypatch, index, record, _NOTES_OBJECTS, OWNER)
146+
assert _notes(index.get_deck("d1")) == ["Say hello {{bold:first}}"]

‎web-ui/src/app/api/decks/[id]/route.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ beforeAll(async () => {
4040
write("html/deck.json", JSON.stringify({ name: "H", outputFormat: "html", slideSize: { width: 1600, height: 900 } }))
4141
write("built/deck.json", JSON.stringify({ name: "B" }))
4242
write("built/output.pptx", "PK")
43+
write("withnotes/deck.json", JSON.stringify({ name: "N" }))
44+
write("withnotes/specs/outline.md", "- [intro] Intro\n- [empty] Empty\n- [broken] Broken\n")
45+
write("withnotes/slides/intro.json", JSON.stringify({ notes: "Say hello {{bold:first}}" }))
46+
write("withnotes/slides/empty.json", JSON.stringify({ notes: " " }))
47+
write("withnotes/slides/broken.json", "{not json")
4348
write("mdnotes/deck.json", JSON.stringify({ name: "M", speakerNotes: "markdown" }))
4449
write("mdnotes/output.pptx", "PK")
4550
write("mdnotes/output.notes.md", "# Speaker notes\n")
@@ -82,3 +87,13 @@ describe("GET /api/decks/[id] speakerNotes", () => {
8287
expect((await deck("html")).speakerNotes).toBeUndefined()
8388
})
8489
})
90+
91+
describe("GET /api/decks/[id] slide notes", () => {
92+
it("gives each slide its notes text and leaves the key out when there are none", async () => {
93+
const body = await deck("withnotes")
94+
expect(body.slides.map((s: { slug: string }) => s.slug)).toEqual(["intro", "empty", "broken"])
95+
expect(body.slides[0].notes).toBe("Say hello {{bold:first}}")
96+
expect("notes" in body.slides[1]).toBe(false)
97+
expect("notes" in body.slides[2]).toBe(false)
98+
})
99+
})

‎web-ui/src/app/api/decks/[id]/route.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ function versionedUrl(filePath: string, url: string): string | null {
3535
try { return `${url}?v=${Math.floor(fs.statSync(filePath).mtimeMs)}` } catch { return null }
3636
}
3737

38+
/** The `notes` text of `slides/<slug>.json` (speaker notes); null when absent, empty or unreadable. */
39+
function slideNotes(dp: string, slug: string): string | null {
40+
const text = safeRead(dp, "slides", `${slug}.json`)
41+
if (!text) return null
42+
try {
43+
const notes = (JSON.parse(text) as { notes?: unknown } | null)?.notes
44+
return typeof notes === "string" && notes.trim() ? notes : null
45+
} catch { return null }
46+
}
47+
3848
/** HTML deck slides: `slides/<slug>.html` in outline order, previews from `preview/<slug>.html`. */
3949
function htmlSlides(dp: string, deckId: string, outlineSlugs: string[]): Record<string, unknown>[] {
4050
// `dp` comes from resolveDeckDir (allow-list + realpath check); every slug passes HTML_SLUG_RE before it is joined.
@@ -113,8 +123,10 @@ export async function GET(_req: Request, { params }: { params: Promise<{ id: str
113123
pageNum++
114124
const composeFile = composeBySlug.get(slug)
115125
const previewFile = previewBySlug.get(slug) || previewByPage.get(pageNum)
126+
const notes = slideNotes(dp, slug)
116127
slides.push({
117128
slug,
129+
...(notes ? { notes } : {}),
118130
previewUrl: previewFile ? `/api/preview/${deckId}/preview/${previewFile}` : null,
119131
composeUrl: composeFile ? `/api/preview/${deckId}/compose/${composeFile}` : null,
120132
updatedAt: new Date().toISOString(),

0 commit comments

Comments
 (0)