From 1f37a9a4bbdd47e00c6c0f854c23ddd6504fc373 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 18 Sep 2026 04:35:48 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=8E=A7=20play=20the=20finished=20e?= =?UTF-8?q?pisode=20from=20its=20job's=20own=20audio=20door?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- .../__tests__/contract/ai.contract.test.ts | 12 ++++--- src/api/__tests__/homework/homework.test.ts | 5 --- src/api/__tests__/podcast/podcast.test.ts | 6 ++-- src/api/client/types.ts | 5 +-- .../getHomeworkRosterSubmissionFileUrl.ts | 3 -- src/api/homework/index.ts | 1 - src/api/podcast/podcastAudioUrl.ts | 13 ++++---- .../homework/homework-submissions-panel.tsx | 4 +-- src/components/notes/podcast-panel.test.tsx | 31 ++++++++++++++++++- src/components/notes/podcast-panel.tsx | 2 +- 10 files changed, 52 insertions(+), 30 deletions(-) delete mode 100644 src/api/homework/getHomeworkRosterSubmissionFileUrl.ts diff --git a/src/api/__tests__/contract/ai.contract.test.ts b/src/api/__tests__/contract/ai.contract.test.ts index 59ad65f..d8649f3 100644 --- a/src/api/__tests__/contract/ai.contract.test.ts +++ b/src/api/__tests__/contract/ai.contract.test.ts @@ -58,10 +58,12 @@ describe.skipIf(!isLive)(`ai contract @ ${contractBaseUrl}`, () => { expect([400, 404, 503]).toContain(response.status); }); - it("rejects an audio path that escapes the school's output directory", async () => { - const response = await api(`/podcast/audio?path=${encodeURIComponent("../../etc/passwd")}`); - // 400, not 404: a caller probing the boundary is told the truth about the - // path rather than being left to guess whether the file exists. - expect([400, 503]).toContain(response.status); + it("answers nothing for an audio job id that is not the caller's", async () => { + // The stream is addressed by job id and resolved from the caller's own job + // row, so a caller cannot name a file at all — an unknown id is a 404, and + // never bytes. (The old `?path=` door, which took a client-supplied path + // and answered 400 on escape, is gone.) + const response = await api(`/podcast/jobs/${encodeURIComponent("00000000-0000-0000-0000-000000000000")}/audio`); + expect([404, 503]).toContain(response.status); }); }); diff --git a/src/api/__tests__/homework/homework.test.ts b/src/api/__tests__/homework/homework.test.ts index 88a5b07..7b6dfc4 100644 --- a/src/api/__tests__/homework/homework.test.ts +++ b/src/api/__tests__/homework/homework.test.ts @@ -7,7 +7,6 @@ import { getHomework, getHomeworkById, getHomeworkReport, - getHomeworkRosterSubmissionFileUrl, getHomeworkResult, getHomeworkSubmission, getHomeworkSubmissionFileBlob, @@ -145,10 +144,6 @@ describe("homework API", () => { expect(getHomeworkSubmissionFileUrl("hw/1", "f?1")).toBe("/api/homework/hw%2F1/submission/files/f%3F1"); }); - it("getHomeworkRosterSubmissionFileUrl returns encoded URL", () => { - expect(getHomeworkRosterSubmissionFileUrl("hw/1", "u?1", "f?1")).toBe("/api/homework/hw%2F1/submissions/u%3F1/files/f%3F1"); - }); - it("deleteHomeworkSubmissionFile calls /homework/:id/submission/files/:fid", async () => { mockFetch204(); diff --git a/src/api/__tests__/podcast/podcast.test.ts b/src/api/__tests__/podcast/podcast.test.ts index 0d1398a..683501e 100644 --- a/src/api/__tests__/podcast/podcast.test.ts +++ b/src/api/__tests__/podcast/podcast.test.ts @@ -84,9 +84,7 @@ describe("podcast API", () => { expect(url).toBe("/api/podcast/jobs/a%20b"); }); - it("podcastAudioUrl carries the artifact path as a query param, encoded", () => { - expect(podcastAudioUrl("ses/duz_okuma/j1/episode.mp3")).toBe( - "/api/podcast/audio?path=ses%2Fduz_okuma%2Fj1%2Fepisode.mp3", - ); + it("podcastAudioUrl addresses the job's own audio door, encoded", () => { + expect(podcastAudioUrl("j 1")).toBe("/api/podcast/jobs/j%201/audio"); }); }); diff --git a/src/api/client/types.ts b/src/api/client/types.ts index ebbe5de..03a371a 100644 --- a/src/api/client/types.ts +++ b/src/api/client/types.ts @@ -1373,8 +1373,9 @@ export type PodcastJobStatus = { /** A finished job's artifacts, passed through verbatim. */ export type PodcastJobArtifacts = { job_id: string; - /** The produced audio, relative to the school's output root — feed it to - * `podcastAudioUrl`, never to a fetch of your own. */ + /** The produced audio's path inside the school's output root. Display-only: + * the stream is addressed by `job_id` (see `podcastAudioUrl`), never by this + * path, so a caller cannot name a file outside its own school. */ audio_id: string; /** One entry per produced chapter; usually `[audio_id]`. */ audio_ids: string[]; diff --git a/src/api/homework/getHomeworkRosterSubmissionFileUrl.ts b/src/api/homework/getHomeworkRosterSubmissionFileUrl.ts deleted file mode 100644 index 7be07d5..0000000 --- a/src/api/homework/getHomeworkRosterSubmissionFileUrl.ts +++ /dev/null @@ -1,3 +0,0 @@ -export function getHomeworkRosterSubmissionFileUrl(id: string, userId: string, fileId: string): string { - return `/api/homework/${encodeURIComponent(id)}/submissions/${encodeURIComponent(userId)}/files/${encodeURIComponent(fileId)}`; -} diff --git a/src/api/homework/index.ts b/src/api/homework/index.ts index f0173dc..fe90506 100644 --- a/src/api/homework/index.ts +++ b/src/api/homework/index.ts @@ -8,7 +8,6 @@ export * from "./deleteHomeworkSubmission"; export * from "./postHomeworkSubmissionFile"; export * from "./getHomeworkSubmissionFileBlob"; export * from "./getHomeworkSubmissionFileUrl"; -export * from "./getHomeworkRosterSubmissionFileUrl"; export * from "./deleteHomeworkSubmissionFile"; export * from "./postHomeworkResult"; export * from "./deleteHomeworkResultByUserId"; diff --git a/src/api/podcast/podcastAudioUrl.ts b/src/api/podcast/podcastAudioUrl.ts index 6e2ee61..d443f9e 100644 --- a/src/api/podcast/podcastAudioUrl.ts +++ b/src/api/podcast/podcastAudioUrl.ts @@ -3,11 +3,12 @@ * `