forge
Explore
Log in

Don't you dare go Hollow

🎧 play the finished episode from its job's own audio door

Browse files at this commit

1f37a9a4bbdd47e00c6c0f854c23ddd6504fc373Ahmet Kaan GümüşParent: a3421b2
  • fix
    • 🎧 play the finished episode from its job's own audio door
Show full message
fix: 🎧 play the finished episode from its job's own audio door

The panel's "ready" player pointed at /api/podcast/audio?path=…, a door the
backend no longer has: the request answers 404 with an empty body, so the
element dies on a format error and shows 0:00 / 0:00 with no sound. The live
contract streams an episode by job id — GET /podcast/jobs/{id}/audio — with
409 not_ready for a job that has not finished, 409 audio_missing for a row
whose blob is gone, and 404 for a job the caller does not own. The helper now
takes the job id, and the panel hands it result().job_id.

Sweeping every hand-built /api URL in src/ against the live OpenAPI paths
turned up a second dead shape: the roster's per-student file download
composed /homework/{id}/submissions/{user}/files/{fid}, which no route
answers (empty 404, where a matched-but-missing route answers a JSON 404).
A teacher reads any file under a homework they manage through
/homework/{id}/submission/files/{fid}, so the roster uses that one helper
and the second URL shape is gone with it. The two SSE stream URLs, the
question/answer image URLs, the note and course-note file URLs, the avatar
URL and both WebSocket rooms all still resolve.

Tests: the audio helper pin moves to the job door, the panel gains a pin
that the element's src is built from job_id (fails if handed audio_id), the
roster's URL pin goes with its helper, and the contract probe now asks the
live door for a job id that is not the caller's instead of the retired path
door.
src/api/__tests__/contract/ai.contract.test.tsmodified+7 -5
@@ -58,10 +58,12 @@ describe.skipIf(!isLive)(`ai contract @ ${contractBaseUrl}`, () => {
58 expect([400, 404, 503]).toContain(response.status);58 expect([400, 404, 503]).toContain(response.status);
59 });59 });
60 60
61- it("rejects an audio path that escapes the school's output directory", async () => {61+ it("answers nothing for an audio job id that is not the caller's", async () => {
62- const response = await api(`/podcast/audio?path=${encodeURIComponent("../../etc/passwd")}`);62+ // The stream is addressed by job id and resolved from the caller's own job
63- // 400, not 404: a caller probing the boundary is told the truth about the63+ // row, so a caller cannot name a file at all — an unknown id is a 404, and
64- // path rather than being left to guess whether the file exists.64+ // never bytes. (The old `?path=` door, which took a client-supplied path
65- expect([400, 503]).toContain(response.status);65+ // and answered 400 on escape, is gone.)
66+ const response = await api(`/podcast/jobs/${encodeURIComponent("00000000-0000-0000-0000-000000000000")}/audio`);
67+ expect([404, 503]).toContain(response.status);
66 });68 });
67 });69 });
src/api/__tests__/homework/homework.test.tsmodified+0 -5
@@ -7,7 +7,6 @@ import {
7 getHomework,7 getHomework,
8 getHomeworkById,8 getHomeworkById,
9 getHomeworkReport,9 getHomeworkReport,
10- getHomeworkRosterSubmissionFileUrl,
11 getHomeworkResult,10 getHomeworkResult,
12 getHomeworkSubmission,11 getHomeworkSubmission,
13 getHomeworkSubmissionFileBlob,12 getHomeworkSubmissionFileBlob,
@@ -145,10 +144,6 @@ describe("homework API", () => {
145 expect(getHomeworkSubmissionFileUrl("hw/1", "f?1")).toBe("/api/homework/hw%2F1/submission/files/f%3F1");144 expect(getHomeworkSubmissionFileUrl("hw/1", "f?1")).toBe("/api/homework/hw%2F1/submission/files/f%3F1");
146 });145 });
147 146
148- it("getHomeworkRosterSubmissionFileUrl returns encoded URL", () => {
149- expect(getHomeworkRosterSubmissionFileUrl("hw/1", "u?1", "f?1")).toBe("/api/homework/hw%2F1/submissions/u%3F1/files/f%3F1");
150- });
151-
152 it("deleteHomeworkSubmissionFile calls /homework/:id/submission/files/:fid", async () => {147 it("deleteHomeworkSubmissionFile calls /homework/:id/submission/files/:fid", async () => {
153 mockFetch204();148 mockFetch204();
154 149
src/api/__tests__/podcast/podcast.test.tsmodified+2 -4
@@ -84,9 +84,7 @@ describe("podcast API", () => {
84 expect(url).toBe("/api/podcast/jobs/a%20b");84 expect(url).toBe("/api/podcast/jobs/a%20b");
85 });85 });
86 86
87- it("podcastAudioUrl carries the artifact path as a query param, encoded", () => {87+ it("podcastAudioUrl addresses the job's own audio door, encoded", () => {
88- expect(podcastAudioUrl("ses/duz_okuma/j1/episode.mp3")).toBe(88+ expect(podcastAudioUrl("j 1")).toBe("/api/podcast/jobs/j%201/audio");
89- "/api/podcast/audio?path=ses%2Fduz_okuma%2Fj1%2Fepisode.mp3",
90- );
91 });89 });
92 });90 });
src/api/client/types.tsmodified+3 -2
@@ -1373,8 +1373,9 @@ export type PodcastJobStatus = {
1373 /** A finished job's artifacts, passed through verbatim. */1373 /** A finished job's artifacts, passed through verbatim. */
1374 export type PodcastJobArtifacts = {1374 export type PodcastJobArtifacts = {
1375 job_id: string;1375 job_id: string;
1376- /** The produced audio, relative to the school's output root — feed it to1376+ /** The produced audio's path inside the school's output root. Display-only:
1377- * `podcastAudioUrl`, never to a fetch of your own. */1377+ * the stream is addressed by `job_id` (see `podcastAudioUrl`), never by this
1378+ * path, so a caller cannot name a file outside its own school. */
1378 audio_id: string;1379 audio_id: string;
1379 /** One entry per produced chapter; usually `[audio_id]`. */1380 /** One entry per produced chapter; usually `[audio_id]`. */
1380 audio_ids: string[];1381 audio_ids: string[];
src/api/homework/getHomeworkRosterSubmissionFileUrl.tsdeleted+0 -3
@@ -1,3 +0,0 @@
1-export function getHomeworkRosterSubmissionFileUrl(id: string, userId: string, fileId: string): string {
2- return `/api/homework/${encodeURIComponent(id)}/submissions/${encodeURIComponent(userId)}/files/${encodeURIComponent(fileId)}`;
3-}
src/api/homework/index.tsmodified+0 -1
@@ -8,7 +8,6 @@ export * from "./deleteHomeworkSubmission";
8 export * from "./postHomeworkSubmissionFile";8 export * from "./postHomeworkSubmissionFile";
9 export * from "./getHomeworkSubmissionFileBlob";9 export * from "./getHomeworkSubmissionFileBlob";
10 export * from "./getHomeworkSubmissionFileUrl";10 export * from "./getHomeworkSubmissionFileUrl";
11-export * from "./getHomeworkRosterSubmissionFileUrl";
12 export * from "./deleteHomeworkSubmissionFile";11 export * from "./deleteHomeworkSubmissionFile";
13 export * from "./postHomeworkResult";12 export * from "./postHomeworkResult";
14 export * from "./deleteHomeworkResultByUserId";13 export * from "./deleteHomeworkResultByUserId";
src/api/podcast/podcastAudioUrl.tsmodified+7 -6
@@ -3,11 +3,12 @@
3 * `<audio src>`: /api is same-origin, so the session cookie rides along on its3 * `<audio src>`: /api is same-origin, so the session cookie rides along on its
4 * own, and the backend streams the file in chunks rather than buffering it.4 * own, and the backend streams the file in chunks rather than buffering it.
5 *5 *
6- * `audioId` is the `audio_id` from `getPodcastJobResultById`, resolved under6+ * `jobId` is the `job_id` from `getPodcastJobResultById` (or from the submit
7- * the caller's own school output directory. The backend treats the path as7+ * receipt): the backend resolves the episode from its own job row, scoped to
8- * hostile input and 400s anything that escapes that directory, so pass the8+ * the caller's school, and never from a path the client supplies. A job that
9- * artifact through untouched instead of composing a path here.9+ * is not `done` answers `409 not_ready`; a row whose blob is missing on this
10+ * host answers `409 audio_missing`; a job the caller does not own is a `404`.
10 */11 */
11-export function podcastAudioUrl(audioId: string): string {12+export function podcastAudioUrl(jobId: string): string {
12- return `/api/podcast/audio?path=${encodeURIComponent(audioId)}`;13+ return `/api/podcast/jobs/${encodeURIComponent(jobId)}/audio`;
13 }14 }
src/components/homework/homework-submissions-panel.tsxmodified+2 -2
@@ -2,7 +2,7 @@ import { For, Show, Suspense, createMemo, createSignal } from "solid-js";
2 import { createResource } from "@/lib/create-resource";2 import { createResource } from "@/lib/create-resource";
3 import type { ColumnDef } from "@tanstack/solid-table";3 import type { ColumnDef } from "@tanstack/solid-table";
4 import { getInstanceEnrollments } from "@/api/instances";4 import { getInstanceEnrollments } from "@/api/instances";
5-import { deleteHomeworkResultByUserId, getHomeworkRosterSubmissionFileUrl, getHomeworkSubmissions, postHomeworkResult } from "@/api/homework";5+import { deleteHomeworkResultByUserId, getHomeworkSubmissionFileUrl, getHomeworkSubmissions, postHomeworkResult } from "@/api/homework";
6 import { formatApiError } from "@/api/client";6 import { formatApiError } from "@/api/client";
7 import type { HomeworkRosterEntry } from "@/api/client";7 import type { HomeworkRosterEntry } from "@/api/client";
8 import { Alert } from "@/components/ui/alert";8 import { Alert } from "@/components/ui/alert";
@@ -207,7 +207,7 @@ export function HomeworkSubmissionsPanel(props: { homeworkId: string; instanceId
207 <p class="truncate font-medium">{file.name}</p>207 <p class="truncate font-medium">{file.name}</p>
208 <p class="text-xs text-text-subtle">{formatBytes(file.size)}</p>208 <p class="text-xs text-text-subtle">{formatBytes(file.size)}</p>
209 </div>209 </div>
210- <a href={getHomeworkRosterSubmissionFileUrl(props.homeworkId, viewTarget()!.user, file.id)} download={file.name}>210+ <a href={getHomeworkSubmissionFileUrl(props.homeworkId, file.id)} download={file.name}>
211 <Button type="button" size="icon" variant="ghost" class="h-7 w-7 rounded-lg" title={t("notes.downloadFile")}>211 <Button type="button" size="icon" variant="ghost" class="h-7 w-7 rounded-lg" title={t("notes.downloadFile")}>
212 <IconDownload class="h-3.5 w-3.5" />212 <IconDownload class="h-3.5 w-3.5" />
213 </Button>213 </Button>
src/components/notes/podcast-panel.test.tsxmodified+30 -1
@@ -8,7 +8,7 @@ const podcastApi = vi.hoisted(() => ({
8 getPodcastJobById: vi.fn(),8 getPodcastJobById: vi.fn(),
9 getPodcastJobResultById: vi.fn(),9 getPodcastJobResultById: vi.fn(),
10 postPodcastJobCancel: vi.fn(),10 postPodcastJobCancel: vi.fn(),
11- podcastAudioUrl: vi.fn((id: string) => `/api/podcast/audio?path=${encodeURIComponent(id)}`),11+ podcastAudioUrl: vi.fn((jobId: string) => `/api/podcast/jobs/${encodeURIComponent(jobId)}/audio`),
12 }));12 }));
13 13
14 vi.mock("@/api/podcast", () => podcastApi);14 vi.mock("@/api/podcast", () => podcastApi);
@@ -50,4 +50,33 @@ describe("PodcastPanel", () => {
50 expect(sessionStorage.getItem("hezarfen.podcast.note-7")).toBe("j1");50 expect(sessionStorage.getItem("hezarfen.podcast.note-7")).toBe("j1");
51 expect(screen.getByText("Waiting in queue")).toBeTruthy();51 expect(screen.getByText("Waiting in queue")).toBeTruthy();
52 });52 });
53+
54+ it("points the audio element at the job's audio door, not the artifact path", async () => {
55+ // A finished job restored from sessionStorage: the panel must address the
56+ // stream by `job_id`. Handing it `audio_id` (the output-root path) composes
57+ // a URL the backend has no route for, and the player dies silently.
58+ sessionStorage.setItem("hezarfen.podcast.note-7", "pj1");
59+ podcastApi.getPodcastJobById.mockResolvedValue({ job_id: "pj1", state: "done", stage: "done", progress: 1 });
60+ podcastApi.getPodcastJobResultById.mockResolvedValue({
61+ job_id: "pj1",
62+ audio_id: "ses/duz_okuma/pj1/episode.mp3",
63+ audio_ids: ["ses/duz_okuma/pj1/episode.mp3"],
64+ duration_secs: 42,
65+ script_id: "s1",
66+ script_ids: ["s1"],
67+ format: "duz_okuma",
68+ });
69+
70+ render(() => (
71+ <PreferencesProvider>
72+ <PodcastPanel noteId="note-7" />
73+ </PreferencesProvider>
74+ ));
75+
76+ await waitFor(() => {
77+ expect(screen.getByText("Your episode is ready.")).toBeTruthy();
78+ });
79+ expect(podcastApi.podcastAudioUrl).toHaveBeenCalledWith("pj1");
80+ expect(document.querySelector("audio")?.getAttribute("src")).toBe("/api/podcast/jobs/pj1/audio");
81+ });
53 });82 });
src/components/notes/podcast-panel.tsxmodified+1 -1
@@ -206,7 +206,7 @@ export function PodcastPanel(props: { noteId: string; active?: boolean }) {
206 {(result) => (206 {(result) => (
207 <div class="space-y-2 rounded-lg border border-success/25 bg-success/5 p-3">207 <div class="space-y-2 rounded-lg border border-success/25 bg-success/5 p-3">
208 <p class="text-sm font-medium">{t("podcast.ready")}</p>208 <p class="text-sm font-medium">{t("podcast.ready")}</p>
209- <audio class="w-full" controls preload="metadata" src={podcastAudioUrl(result().audio_id)}>209+ <audio class="w-full" controls preload="metadata" src={podcastAudioUrl(result().job_id)}>
210 {t("podcast.audioUnsupported")}210 {t("podcast.audioUnsupported")}
211 </audio>211 </audio>
212 </div>212 </div>