forge
Explore
Log in

Don't you dare go Hollow

Dispatch every attachment as sources, not just the newest PDF

Browse files at this commit

979d53ff4e87fc1e436834bc111b8a654b1a84c2Ahmet Kaan GümüşParent: 987866d
  • feat
    • dispatch every attachment as sources, not just the newest PDF
Show full message
✨ feat(podcast): dispatch every attachment as sources, not just the newest PDF

The submit door now lists all of the note's attachments (id ASC), stats each
blob, and dispatches the present ones as `sources` — `source_key` rides on as
the first source's key, one-release compat. A blob that is gone is skipped with
a log line; `409 source_missing` now means zero attachments or zero present
blobs, and a note id with any single attachment is a valid job.

`podcast.report` gains additive `sources` (`{key, name, status}`, `ok` or
`skipped:<code>`), stored verbatim into the job row's new JSONB `sources`
column and replayed by `GET /podcast/jobs/{id}/result`. `newest_pdf` is
deleted with its service wrapper — clean cutover.
Local-Gate: fe26c0cd12b31b6a48cacff9a3a6119bd241d89e (1518 passed, 459s)
.sqlx/query-b3044b692a7cca8eb27c9060462465df513a477b6f67329ea555ed41c87919d0.json → .sqlx/query-1ac7a9d2e2b86e6b1a44f58c2c630cf16978179c96a0beac016b39a4cd74aa39.jsonrenamed+25 -13
@@ -1,6 +1,6 @@
1 {1 {
2 "db_name": "PostgreSQL",2 "db_name": "PostgreSQL",
3- "query": "UPDATE podcast_job SET audio_key = $2, audio_name = $3, audio_type = $4, audio_bytes = $5, duration_secs = $6, updated_at = $7 WHERE id = $1 RETURNING id AS \"id: PodcastJobId\", user_id AS \"user_id: UserId\", source_id, format, transcript, state AS \"state: PodcastJobState\", stage, progress, error_code, audio_key, audio_name, audio_type, audio_bytes, duration_secs, eta_secs, created_at AS \"created_at: Timestamp\", updated_at AS \"updated_at: Timestamp\"",3+ "query": "UPDATE podcast_job SET audio_key = $2, audio_name = $3, audio_type = $4, audio_bytes = $5, duration_secs = $6, updated_at = $7 WHERE id = $1 RETURNING id AS \"id: PodcastJobId\", user_id AS \"user_id: UserId\", source_id, format, transcript, sources AS \"sources: Json<Value>\", state AS \"state: PodcastJobState\", stage, progress, error_code, audio_key, audio_name, audio_type, audio_bytes, duration_secs, eta_secs, created_at AS \"created_at: Timestamp\", updated_at AS \"updated_at: Timestamp\"",
4 "describe": {4 "describe": {
5 "columns": [5 "columns": [
6 {6 {
@@ -60,6 +60,17 @@
60 },60 },
61 {61 {
62 "ordinal": 5,62 "ordinal": 5,
63+ "name": "sources: Json<Value>",
64+ "type_info": "Jsonb",
65+ "origin": {
66+ "Table": {
67+ "table": "podcast_job",
68+ "name": "sources"
69+ }
70+ }
71+ },
72+ {
73+ "ordinal": 6,
63 "name": "state: PodcastJobState",74 "name": "state: PodcastJobState",
64 "type_info": "Text",75 "type_info": "Text",
65 "origin": {76 "origin": {
@@ -70,7 +81,7 @@
70 }81 }
71 },82 },
72 {83 {
73- "ordinal": 6,84+ "ordinal": 7,
74 "name": "stage",85 "name": "stage",
75 "type_info": "Text",86 "type_info": "Text",
76 "origin": {87 "origin": {
@@ -81,7 +92,7 @@
81 }92 }
82 },93 },
83 {94 {
84- "ordinal": 7,95+ "ordinal": 8,
85 "name": "progress",96 "name": "progress",
86 "type_info": "Float8",97 "type_info": "Float8",
87 "origin": {98 "origin": {
@@ -92,7 +103,7 @@
92 }103 }
93 },104 },
94 {105 {
95- "ordinal": 8,106+ "ordinal": 9,
96 "name": "error_code",107 "name": "error_code",
97 "type_info": "Text",108 "type_info": "Text",
98 "origin": {109 "origin": {
@@ -103,7 +114,7 @@
103 }114 }
104 },115 },
105 {116 {
106- "ordinal": 9,117+ "ordinal": 10,
107 "name": "audio_key",118 "name": "audio_key",
108 "type_info": "Text",119 "type_info": "Text",
109 "origin": {120 "origin": {
@@ -114,7 +125,7 @@
114 }125 }
115 },126 },
116 {127 {
117- "ordinal": 10,128+ "ordinal": 11,
118 "name": "audio_name",129 "name": "audio_name",
119 "type_info": "Text",130 "type_info": "Text",
120 "origin": {131 "origin": {
@@ -125,7 +136,7 @@
125 }136 }
126 },137 },
127 {138 {
128- "ordinal": 11,139+ "ordinal": 12,
129 "name": "audio_type",140 "name": "audio_type",
130 "type_info": "Text",141 "type_info": "Text",
131 "origin": {142 "origin": {
@@ -136,7 +147,7 @@
136 }147 }
137 },148 },
138 {149 {
139- "ordinal": 12,150+ "ordinal": 13,
140 "name": "audio_bytes",151 "name": "audio_bytes",
141 "type_info": "Int8",152 "type_info": "Int8",
142 "origin": {153 "origin": {
@@ -147,7 +158,7 @@
147 }158 }
148 },159 },
149 {160 {
150- "ordinal": 13,161+ "ordinal": 14,
151 "name": "duration_secs",162 "name": "duration_secs",
152 "type_info": "Float8",163 "type_info": "Float8",
153 "origin": {164 "origin": {
@@ -158,7 +169,7 @@
158 }169 }
159 },170 },
160 {171 {
161- "ordinal": 14,172+ "ordinal": 15,
162 "name": "eta_secs",173 "name": "eta_secs",
163 "type_info": "Int8",174 "type_info": "Int8",
164 "origin": {175 "origin": {
@@ -169,7 +180,7 @@
169 }180 }
170 },181 },
171 {182 {
172- "ordinal": 15,183+ "ordinal": 16,
173 "name": "created_at: Timestamp",184 "name": "created_at: Timestamp",
174 "type_info": "Int8",185 "type_info": "Int8",
175 "origin": {186 "origin": {
@@ -180,7 +191,7 @@
180 }191 }
181 },192 },
182 {193 {
183- "ordinal": 16,194+ "ordinal": 17,
184 "name": "updated_at: Timestamp",195 "name": "updated_at: Timestamp",
185 "type_info": "Int8",196 "type_info": "Int8",
186 "origin": {197 "origin": {
@@ -208,6 +219,7 @@
208 false,219 false,
209 true,220 true,
210 true,221 true,
222+ true,
211 false,223 false,
212 false,224 false,
213 false,225 false,
@@ -222,5 +234,5 @@
222 false234 false
223 ]235 ]
224 },236 },
225- "hash": "b3044b692a7cca8eb27c9060462465df513a477b6f67329ea555ed41c87919d0"237+ "hash": "1ac7a9d2e2b86e6b1a44f58c2c630cf16978179c96a0beac016b39a4cd74aa39"
226 }238 }
.sqlx/query-37c8e360c3557ede7f79c9f210984598576292ee347427e1a54441bceb88ed12.json → .sqlx/query-1b8d4d66fc69afb04cc66fc0e0e34b5ae9030899c067026f218ce02d6a7528cb.jsonrenamed+25 -13
@@ -1,6 +1,6 @@
1 {1 {
2 "db_name": "PostgreSQL",2 "db_name": "PostgreSQL",
3- "query": "UPDATE podcast_job SET eta_secs = $2 WHERE id = $1 RETURNING id AS \"id: PodcastJobId\", user_id AS \"user_id: UserId\", source_id, format, transcript, state AS \"state: PodcastJobState\", stage, progress, error_code, audio_key, audio_name, audio_type, audio_bytes, duration_secs, eta_secs, created_at AS \"created_at: Timestamp\", updated_at AS \"updated_at: Timestamp\"",3+ "query": "UPDATE podcast_job SET eta_secs = $2 WHERE id = $1 RETURNING id AS \"id: PodcastJobId\", user_id AS \"user_id: UserId\", source_id, format, transcript, sources AS \"sources: Json<Value>\", state AS \"state: PodcastJobState\", stage, progress, error_code, audio_key, audio_name, audio_type, audio_bytes, duration_secs, eta_secs, created_at AS \"created_at: Timestamp\", updated_at AS \"updated_at: Timestamp\"",
4 "describe": {4 "describe": {
5 "columns": [5 "columns": [
6 {6 {
@@ -60,6 +60,17 @@
60 },60 },
61 {61 {
62 "ordinal": 5,62 "ordinal": 5,
63+ "name": "sources: Json<Value>",
64+ "type_info": "Jsonb",
65+ "origin": {
66+ "Table": {
67+ "table": "podcast_job",
68+ "name": "sources"
69+ }
70+ }
71+ },
72+ {
73+ "ordinal": 6,
63 "name": "state: PodcastJobState",74 "name": "state: PodcastJobState",
64 "type_info": "Text",75 "type_info": "Text",
65 "origin": {76 "origin": {
@@ -70,7 +81,7 @@
70 }81 }
71 },82 },
72 {83 {
73- "ordinal": 6,84+ "ordinal": 7,
74 "name": "stage",85 "name": "stage",
75 "type_info": "Text",86 "type_info": "Text",
76 "origin": {87 "origin": {
@@ -81,7 +92,7 @@
81 }92 }
82 },93 },
83 {94 {
84- "ordinal": 7,95+ "ordinal": 8,
85 "name": "progress",96 "name": "progress",
86 "type_info": "Float8",97 "type_info": "Float8",
87 "origin": {98 "origin": {
@@ -92,7 +103,7 @@
92 }103 }
93 },104 },
94 {105 {
95- "ordinal": 8,106+ "ordinal": 9,
96 "name": "error_code",107 "name": "error_code",
97 "type_info": "Text",108 "type_info": "Text",
98 "origin": {109 "origin": {
@@ -103,7 +114,7 @@
103 }114 }
104 },115 },
105 {116 {
106- "ordinal": 9,117+ "ordinal": 10,
107 "name": "audio_key",118 "name": "audio_key",
108 "type_info": "Text",119 "type_info": "Text",
109 "origin": {120 "origin": {
@@ -114,7 +125,7 @@
114 }125 }
115 },126 },
116 {127 {
117- "ordinal": 10,128+ "ordinal": 11,
118 "name": "audio_name",129 "name": "audio_name",
119 "type_info": "Text",130 "type_info": "Text",
120 "origin": {131 "origin": {
@@ -125,7 +136,7 @@
125 }136 }
126 },137 },
127 {138 {
128- "ordinal": 11,139+ "ordinal": 12,
129 "name": "audio_type",140 "name": "audio_type",
130 "type_info": "Text",141 "type_info": "Text",
131 "origin": {142 "origin": {
@@ -136,7 +147,7 @@
136 }147 }
137 },148 },
138 {149 {
139- "ordinal": 12,150+ "ordinal": 13,
140 "name": "audio_bytes",151 "name": "audio_bytes",
141 "type_info": "Int8",152 "type_info": "Int8",
142 "origin": {153 "origin": {
@@ -147,7 +158,7 @@
147 }158 }
148 },159 },
149 {160 {
150- "ordinal": 13,161+ "ordinal": 14,
151 "name": "duration_secs",162 "name": "duration_secs",
152 "type_info": "Float8",163 "type_info": "Float8",
153 "origin": {164 "origin": {
@@ -158,7 +169,7 @@
158 }169 }
159 },170 },
160 {171 {
161- "ordinal": 14,172+ "ordinal": 15,
162 "name": "eta_secs",173 "name": "eta_secs",
163 "type_info": "Int8",174 "type_info": "Int8",
164 "origin": {175 "origin": {
@@ -169,7 +180,7 @@
169 }180 }
170 },181 },
171 {182 {
172- "ordinal": 15,183+ "ordinal": 16,
173 "name": "created_at: Timestamp",184 "name": "created_at: Timestamp",
174 "type_info": "Int8",185 "type_info": "Int8",
175 "origin": {186 "origin": {
@@ -180,7 +191,7 @@
180 }191 }
181 },192 },
182 {193 {
183- "ordinal": 16,194+ "ordinal": 17,
184 "name": "updated_at: Timestamp",195 "name": "updated_at: Timestamp",
185 "type_info": "Int8",196 "type_info": "Int8",
186 "origin": {197 "origin": {
@@ -203,6 +214,7 @@
203 false,214 false,
204 true,215 true,
205 true,216 true,
217+ true,
206 false,218 false,
207 false,219 false,
208 false,220 false,
@@ -217,5 +229,5 @@
217 false229 false
218 ]230 ]
219 },231 },
220- "hash": "37c8e360c3557ede7f79c9f210984598576292ee347427e1a54441bceb88ed12"232+ "hash": "1b8d4d66fc69afb04cc66fc0e0e34b5ae9030899c067026f218ce02d6a7528cb"
221 }233 }
.sqlx/query-4b05eec4ece0295d6be7ce2b92238e49fabe71d62b021c1d1425e51d9f1adbe3.json → .sqlx/query-26c326f8fce441ccc6dcb8cf8c4aec191a369da3e0e29966b6d0f0830b5ddb6e.jsonrenamed+25 -13
@@ -1,6 +1,6 @@
1 {1 {
2 "db_name": "PostgreSQL",2 "db_name": "PostgreSQL",
3- "query": "UPDATE podcast_job SET state = 'cancelled', stage = '', updated_at = $2 WHERE id = $1 AND state IN ('queued', 'running') RETURNING id AS \"id: PodcastJobId\", user_id AS \"user_id: UserId\", source_id, format, transcript, state AS \"state: PodcastJobState\", stage, progress, error_code, audio_key, audio_name, audio_type, audio_bytes, duration_secs, eta_secs, created_at AS \"created_at: Timestamp\", updated_at AS \"updated_at: Timestamp\"",3+ "query": "UPDATE podcast_job SET state = 'cancelled', stage = '', updated_at = $2 WHERE id = $1 AND state IN ('queued', 'running') RETURNING id AS \"id: PodcastJobId\", user_id AS \"user_id: UserId\", source_id, format, transcript, sources AS \"sources: Json<Value>\", state AS \"state: PodcastJobState\", stage, progress, error_code, audio_key, audio_name, audio_type, audio_bytes, duration_secs, eta_secs, created_at AS \"created_at: Timestamp\", updated_at AS \"updated_at: Timestamp\"",
4 "describe": {4 "describe": {
5 "columns": [5 "columns": [
6 {6 {
@@ -60,6 +60,17 @@
60 },60 },
61 {61 {
62 "ordinal": 5,62 "ordinal": 5,
63+ "name": "sources: Json<Value>",
64+ "type_info": "Jsonb",
65+ "origin": {
66+ "Table": {
67+ "table": "podcast_job",
68+ "name": "sources"
69+ }
70+ }
71+ },
72+ {
73+ "ordinal": 6,
63 "name": "state: PodcastJobState",74 "name": "state: PodcastJobState",
64 "type_info": "Text",75 "type_info": "Text",
65 "origin": {76 "origin": {
@@ -70,7 +81,7 @@
70 }81 }
71 },82 },
72 {83 {
73- "ordinal": 6,84+ "ordinal": 7,
74 "name": "stage",85 "name": "stage",
75 "type_info": "Text",86 "type_info": "Text",
76 "origin": {87 "origin": {
@@ -81,7 +92,7 @@
81 }92 }
82 },93 },
83 {94 {
84- "ordinal": 7,95+ "ordinal": 8,
85 "name": "progress",96 "name": "progress",
86 "type_info": "Float8",97 "type_info": "Float8",
87 "origin": {98 "origin": {
@@ -92,7 +103,7 @@
92 }103 }
93 },104 },
94 {105 {
95- "ordinal": 8,106+ "ordinal": 9,
96 "name": "error_code",107 "name": "error_code",
97 "type_info": "Text",108 "type_info": "Text",
98 "origin": {109 "origin": {
@@ -103,7 +114,7 @@
103 }114 }
104 },115 },
105 {116 {
106- "ordinal": 9,117+ "ordinal": 10,
107 "name": "audio_key",118 "name": "audio_key",
108 "type_info": "Text",119 "type_info": "Text",
109 "origin": {120 "origin": {
@@ -114,7 +125,7 @@
114 }125 }
115 },126 },
116 {127 {
117- "ordinal": 10,128+ "ordinal": 11,
118 "name": "audio_name",129 "name": "audio_name",
119 "type_info": "Text",130 "type_info": "Text",
120 "origin": {131 "origin": {
@@ -125,7 +136,7 @@
125 }136 }
126 },137 },
127 {138 {
128- "ordinal": 11,139+ "ordinal": 12,
129 "name": "audio_type",140 "name": "audio_type",
130 "type_info": "Text",141 "type_info": "Text",
131 "origin": {142 "origin": {
@@ -136,7 +147,7 @@
136 }147 }
137 },148 },
138 {149 {
139- "ordinal": 12,150+ "ordinal": 13,
140 "name": "audio_bytes",151 "name": "audio_bytes",
141 "type_info": "Int8",152 "type_info": "Int8",
142 "origin": {153 "origin": {
@@ -147,7 +158,7 @@
147 }158 }
148 },159 },
149 {160 {
150- "ordinal": 13,161+ "ordinal": 14,
151 "name": "duration_secs",162 "name": "duration_secs",
152 "type_info": "Float8",163 "type_info": "Float8",
153 "origin": {164 "origin": {
@@ -158,7 +169,7 @@
158 }169 }
159 },170 },
160 {171 {
161- "ordinal": 14,172+ "ordinal": 15,
162 "name": "eta_secs",173 "name": "eta_secs",
163 "type_info": "Int8",174 "type_info": "Int8",
164 "origin": {175 "origin": {
@@ -169,7 +180,7 @@
169 }180 }
170 },181 },
171 {182 {
172- "ordinal": 15,183+ "ordinal": 16,
173 "name": "created_at: Timestamp",184 "name": "created_at: Timestamp",
174 "type_info": "Int8",185 "type_info": "Int8",
175 "origin": {186 "origin": {
@@ -180,7 +191,7 @@
180 }191 }
181 },192 },
182 {193 {
183- "ordinal": 16,194+ "ordinal": 17,
184 "name": "updated_at: Timestamp",195 "name": "updated_at: Timestamp",
185 "type_info": "Int8",196 "type_info": "Int8",
186 "origin": {197 "origin": {
@@ -203,6 +214,7 @@
203 false,214 false,
204 true,215 true,
205 true,216 true,
217+ true,
206 false,218 false,
207 false,219 false,
208 false,220 false,
@@ -217,5 +229,5 @@
217 false229 false
218 ]230 ]
219 },231 },
220- "hash": "4b05eec4ece0295d6be7ce2b92238e49fabe71d62b021c1d1425e51d9f1adbe3"232+ "hash": "26c326f8fce441ccc6dcb8cf8c4aec191a369da3e0e29966b6d0f0830b5ddb6e"
221 }233 }
.sqlx/query-45ade92df6adc604f90c5e2111fc4bd23b8c6e901d81ca64a96bef3116ab906f.json → .sqlx/query-3e66c333be0794213c6c6f077e184780cba13e76123e7d9f4f9d64c17ca5105b.jsonrenamed+25 -13
@@ -1,6 +1,6 @@
1 {1 {
2 "db_name": "PostgreSQL",2 "db_name": "PostgreSQL",
3- "query": "SELECT id AS \"id: PodcastJobId\", user_id AS \"user_id: UserId\", source_id, format, transcript, state AS \"state: PodcastJobState\", stage, progress, error_code, audio_key, audio_name, audio_type, audio_bytes, duration_secs, eta_secs, created_at AS \"created_at: Timestamp\", updated_at AS \"updated_at: Timestamp\" FROM podcast_job WHERE id = $1 AND user_id = $2",3+ "query": "SELECT id AS \"id: PodcastJobId\", user_id AS \"user_id: UserId\", source_id, format, transcript, sources AS \"sources: Json<Value>\", state AS \"state: PodcastJobState\", stage, progress, error_code, audio_key, audio_name, audio_type, audio_bytes, duration_secs, eta_secs, created_at AS \"created_at: Timestamp\", updated_at AS \"updated_at: Timestamp\" FROM podcast_job WHERE id = $1 AND user_id = $2",
4 "describe": {4 "describe": {
5 "columns": [5 "columns": [
6 {6 {
@@ -60,6 +60,17 @@
60 },60 },
61 {61 {
62 "ordinal": 5,62 "ordinal": 5,
63+ "name": "sources: Json<Value>",
64+ "type_info": "Jsonb",
65+ "origin": {
66+ "Table": {
67+ "table": "podcast_job",
68+ "name": "sources"
69+ }
70+ }
71+ },
72+ {
73+ "ordinal": 6,
63 "name": "state: PodcastJobState",74 "name": "state: PodcastJobState",
64 "type_info": "Text",75 "type_info": "Text",
65 "origin": {76 "origin": {
@@ -70,7 +81,7 @@
70 }81 }
71 },82 },
72 {83 {
73- "ordinal": 6,84+ "ordinal": 7,
74 "name": "stage",85 "name": "stage",
75 "type_info": "Text",86 "type_info": "Text",
76 "origin": {87 "origin": {
@@ -81,7 +92,7 @@
81 }92 }
82 },93 },
83 {94 {
84- "ordinal": 7,95+ "ordinal": 8,
85 "name": "progress",96 "name": "progress",
86 "type_info": "Float8",97 "type_info": "Float8",
87 "origin": {98 "origin": {
@@ -92,7 +103,7 @@
92 }103 }
93 },104 },
94 {105 {
95- "ordinal": 8,106+ "ordinal": 9,
96 "name": "error_code",107 "name": "error_code",
97 "type_info": "Text",108 "type_info": "Text",
98 "origin": {109 "origin": {
@@ -103,7 +114,7 @@
103 }114 }
104 },115 },
105 {116 {
106- "ordinal": 9,117+ "ordinal": 10,
107 "name": "audio_key",118 "name": "audio_key",
108 "type_info": "Text",119 "type_info": "Text",
109 "origin": {120 "origin": {
@@ -114,7 +125,7 @@
114 }125 }
115 },126 },
116 {127 {
117- "ordinal": 10,128+ "ordinal": 11,
118 "name": "audio_name",129 "name": "audio_name",
119 "type_info": "Text",130 "type_info": "Text",
120 "origin": {131 "origin": {
@@ -125,7 +136,7 @@
125 }136 }
126 },137 },
127 {138 {
128- "ordinal": 11,139+ "ordinal": 12,
129 "name": "audio_type",140 "name": "audio_type",
130 "type_info": "Text",141 "type_info": "Text",
131 "origin": {142 "origin": {
@@ -136,7 +147,7 @@
136 }147 }
137 },148 },
138 {149 {
139- "ordinal": 12,150+ "ordinal": 13,
140 "name": "audio_bytes",151 "name": "audio_bytes",
141 "type_info": "Int8",152 "type_info": "Int8",
142 "origin": {153 "origin": {
@@ -147,7 +158,7 @@
147 }158 }
148 },159 },
149 {160 {
150- "ordinal": 13,161+ "ordinal": 14,
151 "name": "duration_secs",162 "name": "duration_secs",
152 "type_info": "Float8",163 "type_info": "Float8",
153 "origin": {164 "origin": {
@@ -158,7 +169,7 @@
158 }169 }
159 },170 },
160 {171 {
161- "ordinal": 14,172+ "ordinal": 15,
162 "name": "eta_secs",173 "name": "eta_secs",
163 "type_info": "Int8",174 "type_info": "Int8",
164 "origin": {175 "origin": {
@@ -169,7 +180,7 @@
169 }180 }
170 },181 },
171 {182 {
172- "ordinal": 15,183+ "ordinal": 16,
173 "name": "created_at: Timestamp",184 "name": "created_at: Timestamp",
174 "type_info": "Int8",185 "type_info": "Int8",
175 "origin": {186 "origin": {
@@ -180,7 +191,7 @@
180 }191 }
181 },192 },
182 {193 {
183- "ordinal": 16,194+ "ordinal": 17,
184 "name": "updated_at: Timestamp",195 "name": "updated_at: Timestamp",
185 "type_info": "Int8",196 "type_info": "Int8",
186 "origin": {197 "origin": {
@@ -203,6 +214,7 @@
203 false,214 false,
204 true,215 true,
205 true,216 true,
217+ true,
206 false,218 false,
207 false,219 false,
208 false,220 false,
@@ -217,5 +229,5 @@
217 false229 false
218 ]230 ]
219 },231 },
220- "hash": "45ade92df6adc604f90c5e2111fc4bd23b8c6e901d81ca64a96bef3116ab906f"232+ "hash": "3e66c333be0794213c6c6f077e184780cba13e76123e7d9f4f9d64c17ca5105b"
221 }233 }
.sqlx/query-814486dbb11e8eeaf410bced5a0aae724aa3f0198ce4204cd94016b827ab55b7.json → .sqlx/query-63f0dc707ee7f6fe9976a0e903b8bfd31de8ca2fe54ddf8cd19e0653de7711cf.jsonrenamed+25 -13
@@ -1,6 +1,6 @@
1 {1 {
2 "db_name": "PostgreSQL",2 "db_name": "PostgreSQL",
3- "query": "UPDATE podcast_job SET state = 'failed', error_code = $2, stage = '', updated_at = $3 WHERE id = $1 AND state IN ('queued', 'running') RETURNING id AS \"id: PodcastJobId\", user_id AS \"user_id: UserId\", source_id, format, transcript, state AS \"state: PodcastJobState\", stage, progress, error_code, audio_key, audio_name, audio_type, audio_bytes, duration_secs, eta_secs, created_at AS \"created_at: Timestamp\", updated_at AS \"updated_at: Timestamp\"",3+ "query": "UPDATE podcast_job SET state = 'failed', error_code = $2, stage = '', updated_at = $3 WHERE id = $1 AND state IN ('queued', 'running') RETURNING id AS \"id: PodcastJobId\", user_id AS \"user_id: UserId\", source_id, format, transcript, sources AS \"sources: Json<Value>\", state AS \"state: PodcastJobState\", stage, progress, error_code, audio_key, audio_name, audio_type, audio_bytes, duration_secs, eta_secs, created_at AS \"created_at: Timestamp\", updated_at AS \"updated_at: Timestamp\"",
4 "describe": {4 "describe": {
5 "columns": [5 "columns": [
6 {6 {
@@ -60,6 +60,17 @@
60 },60 },
61 {61 {
62 "ordinal": 5,62 "ordinal": 5,
63+ "name": "sources: Json<Value>",
64+ "type_info": "Jsonb",
65+ "origin": {
66+ "Table": {
67+ "table": "podcast_job",
68+ "name": "sources"
69+ }
70+ }
71+ },
72+ {
73+ "ordinal": 6,
63 "name": "state: PodcastJobState",74 "name": "state: PodcastJobState",
64 "type_info": "Text",75 "type_info": "Text",
65 "origin": {76 "origin": {
@@ -70,7 +81,7 @@
70 }81 }
71 },82 },
72 {83 {
73- "ordinal": 6,84+ "ordinal": 7,
74 "name": "stage",85 "name": "stage",
75 "type_info": "Text",86 "type_info": "Text",
76 "origin": {87 "origin": {
@@ -81,7 +92,7 @@
81 }92 }
82 },93 },
83 {94 {
84- "ordinal": 7,95+ "ordinal": 8,
85 "name": "progress",96 "name": "progress",
86 "type_info": "Float8",97 "type_info": "Float8",
87 "origin": {98 "origin": {
@@ -92,7 +103,7 @@
92 }103 }
93 },104 },
94 {105 {
95- "ordinal": 8,106+ "ordinal": 9,
96 "name": "error_code",107 "name": "error_code",
97 "type_info": "Text",108 "type_info": "Text",
98 "origin": {109 "origin": {
@@ -103,7 +114,7 @@
103 }114 }
104 },115 },
105 {116 {
106- "ordinal": 9,117+ "ordinal": 10,
107 "name": "audio_key",118 "name": "audio_key",
108 "type_info": "Text",119 "type_info": "Text",
109 "origin": {120 "origin": {
@@ -114,7 +125,7 @@
114 }125 }
115 },126 },
116 {127 {
117- "ordinal": 10,128+ "ordinal": 11,
118 "name": "audio_name",129 "name": "audio_name",
119 "type_info": "Text",130 "type_info": "Text",
120 "origin": {131 "origin": {
@@ -125,7 +136,7 @@
125 }136 }
126 },137 },
127 {138 {
128- "ordinal": 11,139+ "ordinal": 12,
129 "name": "audio_type",140 "name": "audio_type",
130 "type_info": "Text",141 "type_info": "Text",
131 "origin": {142 "origin": {
@@ -136,7 +147,7 @@
136 }147 }
137 },148 },
138 {149 {
139- "ordinal": 12,150+ "ordinal": 13,
140 "name": "audio_bytes",151 "name": "audio_bytes",
141 "type_info": "Int8",152 "type_info": "Int8",
142 "origin": {153 "origin": {
@@ -147,7 +158,7 @@
147 }158 }
148 },159 },
149 {160 {
150- "ordinal": 13,161+ "ordinal": 14,
151 "name": "duration_secs",162 "name": "duration_secs",
152 "type_info": "Float8",163 "type_info": "Float8",
153 "origin": {164 "origin": {
@@ -158,7 +169,7 @@
158 }169 }
159 },170 },
160 {171 {
161- "ordinal": 14,172+ "ordinal": 15,
162 "name": "eta_secs",173 "name": "eta_secs",
163 "type_info": "Int8",174 "type_info": "Int8",
164 "origin": {175 "origin": {
@@ -169,7 +180,7 @@
169 }180 }
170 },181 },
171 {182 {
172- "ordinal": 15,183+ "ordinal": 16,
173 "name": "created_at: Timestamp",184 "name": "created_at: Timestamp",
174 "type_info": "Int8",185 "type_info": "Int8",
175 "origin": {186 "origin": {
@@ -180,7 +191,7 @@
180 }191 }
181 },192 },
182 {193 {
183- "ordinal": 16,194+ "ordinal": 17,
184 "name": "updated_at: Timestamp",195 "name": "updated_at: Timestamp",
185 "type_info": "Int8",196 "type_info": "Int8",
186 "origin": {197 "origin": {
@@ -204,6 +215,7 @@
204 false,215 false,
205 true,216 true,
206 true,217 true,
218+ true,
207 false,219 false,
208 false,220 false,
209 false,221 false,
@@ -218,5 +230,5 @@
218 false230 false
219 ]231 ]
220 },232 },
221- "hash": "814486dbb11e8eeaf410bced5a0aae724aa3f0198ce4204cd94016b827ab55b7"233+ "hash": "63f0dc707ee7f6fe9976a0e903b8bfd31de8ca2fe54ddf8cd19e0653de7711cf"
222 }234 }
.sqlx/query-f40008ce74997412bd8099f21cc58579d2c6efc73d04072849fe650a737e7a4c.json → .sqlx/query-6b6ca993e9600caf8a4066432a7583be29811979fcfa869677c8dbbe5d19e2a8.jsonrenamed+26 -13
@@ -1,6 +1,6 @@
1 {1 {
2 "db_name": "PostgreSQL",2 "db_name": "PostgreSQL",
3- "query": "UPDATE podcast_job SET state = $3, stage = $4, progress = $5, error_code = $6, format = COALESCE(format, $7::text), transcript = COALESCE(transcript, $8::text), updated_at = $9 WHERE id = $1 AND state = $2 RETURNING id AS \"id: PodcastJobId\", user_id AS \"user_id: UserId\", source_id, format, transcript, state AS \"state: PodcastJobState\", stage, progress, error_code, audio_key, audio_name, audio_type, audio_bytes, duration_secs, eta_secs, created_at AS \"created_at: Timestamp\", updated_at AS \"updated_at: Timestamp\"",3+ "query": "UPDATE podcast_job SET state = $3, stage = $4, progress = $5, error_code = $6, format = COALESCE(format, $7::text), transcript = COALESCE(transcript, $8::text), sources = COALESCE(sources, $9::jsonb), updated_at = $10 WHERE id = $1 AND state = $2 RETURNING id AS \"id: PodcastJobId\", user_id AS \"user_id: UserId\", source_id, format, transcript, sources AS \"sources: Json<Value>\", state AS \"state: PodcastJobState\", stage, progress, error_code, audio_key, audio_name, audio_type, audio_bytes, duration_secs, eta_secs, created_at AS \"created_at: Timestamp\", updated_at AS \"updated_at: Timestamp\"",
4 "describe": {4 "describe": {
5 "columns": [5 "columns": [
6 {6 {
@@ -60,6 +60,17 @@
60 },60 },
61 {61 {
62 "ordinal": 5,62 "ordinal": 5,
63+ "name": "sources: Json<Value>",
64+ "type_info": "Jsonb",
65+ "origin": {
66+ "Table": {
67+ "table": "podcast_job",
68+ "name": "sources"
69+ }
70+ }
71+ },
72+ {
73+ "ordinal": 6,
63 "name": "state: PodcastJobState",74 "name": "state: PodcastJobState",
64 "type_info": "Text",75 "type_info": "Text",
65 "origin": {76 "origin": {
@@ -70,7 +81,7 @@
70 }81 }
71 },82 },
72 {83 {
73- "ordinal": 6,84+ "ordinal": 7,
74 "name": "stage",85 "name": "stage",
75 "type_info": "Text",86 "type_info": "Text",
76 "origin": {87 "origin": {
@@ -81,7 +92,7 @@
81 }92 }
82 },93 },
83 {94 {
84- "ordinal": 7,95+ "ordinal": 8,
85 "name": "progress",96 "name": "progress",
86 "type_info": "Float8",97 "type_info": "Float8",
87 "origin": {98 "origin": {
@@ -92,7 +103,7 @@
92 }103 }
93 },104 },
94 {105 {
95- "ordinal": 8,106+ "ordinal": 9,
96 "name": "error_code",107 "name": "error_code",
97 "type_info": "Text",108 "type_info": "Text",
98 "origin": {109 "origin": {
@@ -103,7 +114,7 @@
103 }114 }
104 },115 },
105 {116 {
106- "ordinal": 9,117+ "ordinal": 10,
107 "name": "audio_key",118 "name": "audio_key",
108 "type_info": "Text",119 "type_info": "Text",
109 "origin": {120 "origin": {
@@ -114,7 +125,7 @@
114 }125 }
115 },126 },
116 {127 {
117- "ordinal": 10,128+ "ordinal": 11,
118 "name": "audio_name",129 "name": "audio_name",
119 "type_info": "Text",130 "type_info": "Text",
120 "origin": {131 "origin": {
@@ -125,7 +136,7 @@
125 }136 }
126 },137 },
127 {138 {
128- "ordinal": 11,139+ "ordinal": 12,
129 "name": "audio_type",140 "name": "audio_type",
130 "type_info": "Text",141 "type_info": "Text",
131 "origin": {142 "origin": {
@@ -136,7 +147,7 @@
136 }147 }
137 },148 },
138 {149 {
139- "ordinal": 12,150+ "ordinal": 13,
140 "name": "audio_bytes",151 "name": "audio_bytes",
141 "type_info": "Int8",152 "type_info": "Int8",
142 "origin": {153 "origin": {
@@ -147,7 +158,7 @@
147 }158 }
148 },159 },
149 {160 {
150- "ordinal": 13,161+ "ordinal": 14,
151 "name": "duration_secs",162 "name": "duration_secs",
152 "type_info": "Float8",163 "type_info": "Float8",
153 "origin": {164 "origin": {
@@ -158,7 +169,7 @@
158 }169 }
159 },170 },
160 {171 {
161- "ordinal": 14,172+ "ordinal": 15,
162 "name": "eta_secs",173 "name": "eta_secs",
163 "type_info": "Int8",174 "type_info": "Int8",
164 "origin": {175 "origin": {
@@ -169,7 +180,7 @@
169 }180 }
170 },181 },
171 {182 {
172- "ordinal": 15,183+ "ordinal": 16,
173 "name": "created_at: Timestamp",184 "name": "created_at: Timestamp",
174 "type_info": "Int8",185 "type_info": "Int8",
175 "origin": {186 "origin": {
@@ -180,7 +191,7 @@
180 }191 }
181 },192 },
182 {193 {
183- "ordinal": 16,194+ "ordinal": 17,
184 "name": "updated_at: Timestamp",195 "name": "updated_at: Timestamp",
185 "type_info": "Int8",196 "type_info": "Int8",
186 "origin": {197 "origin": {
@@ -201,6 +212,7 @@
201 "Text",212 "Text",
202 "Text",213 "Text",
203 "Text",214 "Text",
215+ "Jsonb",
204 "Int8"216 "Int8"
205 ]217 ]
206 },218 },
@@ -210,6 +222,7 @@
210 false,222 false,
211 true,223 true,
212 true,224 true,
225+ true,
213 false,226 false,
214 false,227 false,
215 false,228 false,
@@ -224,5 +237,5 @@
224 false237 false
225 ]238 ]
226 },239 },
227- "hash": "f40008ce74997412bd8099f21cc58579d2c6efc73d04072849fe650a737e7a4c"240+ "hash": "6b6ca993e9600caf8a4066432a7583be29811979fcfa869677c8dbbe5d19e2a8"
228 }241 }
.sqlx/query-cabbdce4f24ffcd7792dc8b9b9f72d02d920bf9fabc10c61584b0bd64c7712ff.json → .sqlx/query-beb6594d280ac53dbb187850d195ac43234ee56ca59e70693e2d920c5a227a86.jsonrenamed+27 -14
@@ -1,6 +1,6 @@
1 {1 {
2 "db_name": "PostgreSQL",2 "db_name": "PostgreSQL",
3- "query": "INSERT INTO podcast_job (id, user_id, source_id, format, state, stage, progress, error_code, audio_key, audio_name, audio_type, audio_bytes, duration_secs, eta_secs, created_at, updated_at) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $15) RETURNING id AS \"id: PodcastJobId\", user_id AS \"user_id: UserId\", source_id, format, transcript, state AS \"state: PodcastJobState\", stage, progress, error_code, audio_key, audio_name, audio_type, audio_bytes, duration_secs, eta_secs, created_at AS \"created_at: Timestamp\", updated_at AS \"updated_at: Timestamp\"",3+ "query": "INSERT INTO podcast_job (id, user_id, source_id, format, state, stage, progress, error_code, audio_key, audio_name, audio_type, audio_bytes, duration_secs, eta_secs, created_at, updated_at, sources) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $15, $16) RETURNING id AS \"id: PodcastJobId\", user_id AS \"user_id: UserId\", source_id, format, transcript, sources AS \"sources: Json<Value>\", state AS \"state: PodcastJobState\", stage, progress, error_code, audio_key, audio_name, audio_type, audio_bytes, duration_secs, eta_secs, created_at AS \"created_at: Timestamp\", updated_at AS \"updated_at: Timestamp\"",
4 "describe": {4 "describe": {
5 "columns": [5 "columns": [
6 {6 {
@@ -60,6 +60,17 @@
60 },60 },
61 {61 {
62 "ordinal": 5,62 "ordinal": 5,
63+ "name": "sources: Json<Value>",
64+ "type_info": "Jsonb",
65+ "origin": {
66+ "Table": {
67+ "table": "podcast_job",
68+ "name": "sources"
69+ }
70+ }
71+ },
72+ {
73+ "ordinal": 6,
63 "name": "state: PodcastJobState",74 "name": "state: PodcastJobState",
64 "type_info": "Text",75 "type_info": "Text",
65 "origin": {76 "origin": {
@@ -70,7 +81,7 @@
70 }81 }
71 },82 },
72 {83 {
73- "ordinal": 6,84+ "ordinal": 7,
74 "name": "stage",85 "name": "stage",
75 "type_info": "Text",86 "type_info": "Text",
76 "origin": {87 "origin": {
@@ -81,7 +92,7 @@
81 }92 }
82 },93 },
83 {94 {
84- "ordinal": 7,95+ "ordinal": 8,
85 "name": "progress",96 "name": "progress",
86 "type_info": "Float8",97 "type_info": "Float8",
87 "origin": {98 "origin": {
@@ -92,7 +103,7 @@
92 }103 }
93 },104 },
94 {105 {
95- "ordinal": 8,106+ "ordinal": 9,
96 "name": "error_code",107 "name": "error_code",
97 "type_info": "Text",108 "type_info": "Text",
98 "origin": {109 "origin": {
@@ -103,7 +114,7 @@
103 }114 }
104 },115 },
105 {116 {
106- "ordinal": 9,117+ "ordinal": 10,
107 "name": "audio_key",118 "name": "audio_key",
108 "type_info": "Text",119 "type_info": "Text",
109 "origin": {120 "origin": {
@@ -114,7 +125,7 @@
114 }125 }
115 },126 },
116 {127 {
117- "ordinal": 10,128+ "ordinal": 11,
118 "name": "audio_name",129 "name": "audio_name",
119 "type_info": "Text",130 "type_info": "Text",
120 "origin": {131 "origin": {
@@ -125,7 +136,7 @@
125 }136 }
126 },137 },
127 {138 {
128- "ordinal": 11,139+ "ordinal": 12,
129 "name": "audio_type",140 "name": "audio_type",
130 "type_info": "Text",141 "type_info": "Text",
131 "origin": {142 "origin": {
@@ -136,7 +147,7 @@
136 }147 }
137 },148 },
138 {149 {
139- "ordinal": 12,150+ "ordinal": 13,
140 "name": "audio_bytes",151 "name": "audio_bytes",
141 "type_info": "Int8",152 "type_info": "Int8",
142 "origin": {153 "origin": {
@@ -147,7 +158,7 @@
147 }158 }
148 },159 },
149 {160 {
150- "ordinal": 13,161+ "ordinal": 14,
151 "name": "duration_secs",162 "name": "duration_secs",
152 "type_info": "Float8",163 "type_info": "Float8",
153 "origin": {164 "origin": {
@@ -158,7 +169,7 @@
158 }169 }
159 },170 },
160 {171 {
161- "ordinal": 14,172+ "ordinal": 15,
162 "name": "eta_secs",173 "name": "eta_secs",
163 "type_info": "Int8",174 "type_info": "Int8",
164 "origin": {175 "origin": {
@@ -169,7 +180,7 @@
169 }180 }
170 },181 },
171 {182 {
172- "ordinal": 15,183+ "ordinal": 16,
173 "name": "created_at: Timestamp",184 "name": "created_at: Timestamp",
174 "type_info": "Int8",185 "type_info": "Int8",
175 "origin": {186 "origin": {
@@ -180,7 +191,7 @@
180 }191 }
181 },192 },
182 {193 {
183- "ordinal": 16,194+ "ordinal": 17,
184 "name": "updated_at: Timestamp",195 "name": "updated_at: Timestamp",
185 "type_info": "Int8",196 "type_info": "Int8",
186 "origin": {197 "origin": {
@@ -207,7 +218,8 @@
207 "Int8",218 "Int8",
208 "Float8",219 "Float8",
209 "Int8",220 "Int8",
210- "Int8"221+ "Int8",
222+ "Jsonb"
211 ]223 ]
212 },224 },
213 "nullable": [225 "nullable": [
@@ -216,6 +228,7 @@
216 false,228 false,
217 true,229 true,
218 true,230 true,
231+ true,
219 false,232 false,
220 false,233 false,
221 false,234 false,
@@ -230,5 +243,5 @@
230 false243 false
231 ]244 ]
232 },245 },
233- "hash": "cabbdce4f24ffcd7792dc8b9b9f72d02d920bf9fabc10c61584b0bd64c7712ff"246+ "hash": "beb6594d280ac53dbb187850d195ac43234ee56ca59e70693e2d920c5a227a86"
234 }247 }
.sqlx/query-d1b16c756ea05fe53f875c57b4d46dfdc152943eb31d5df4c531af6da3e6ec7b.json → .sqlx/query-cb286f2c1e63c638be8a58c0b9b0fb4add9e70c39cc9095ddafd3693e27f7bfd.jsonrenamed+25 -13
@@ -1,6 +1,6 @@
1 {1 {
2 "db_name": "PostgreSQL",2 "db_name": "PostgreSQL",
3- "query": "SELECT id AS \"id: PodcastJobId\", user_id AS \"user_id: UserId\", source_id, format, transcript, state AS \"state: PodcastJobState\", stage, progress, error_code, audio_key, audio_name, audio_type, audio_bytes, duration_secs, eta_secs, created_at AS \"created_at: Timestamp\", updated_at AS \"updated_at: Timestamp\" FROM podcast_job WHERE id = $1",3+ "query": "SELECT id AS \"id: PodcastJobId\", user_id AS \"user_id: UserId\", source_id, format, transcript, sources AS \"sources: Json<Value>\", state AS \"state: PodcastJobState\", stage, progress, error_code, audio_key, audio_name, audio_type, audio_bytes, duration_secs, eta_secs, created_at AS \"created_at: Timestamp\", updated_at AS \"updated_at: Timestamp\" FROM podcast_job WHERE id = $1",
4 "describe": {4 "describe": {
5 "columns": [5 "columns": [
6 {6 {
@@ -60,6 +60,17 @@
60 },60 },
61 {61 {
62 "ordinal": 5,62 "ordinal": 5,
63+ "name": "sources: Json<Value>",
64+ "type_info": "Jsonb",
65+ "origin": {
66+ "Table": {
67+ "table": "podcast_job",
68+ "name": "sources"
69+ }
70+ }
71+ },
72+ {
73+ "ordinal": 6,
63 "name": "state: PodcastJobState",74 "name": "state: PodcastJobState",
64 "type_info": "Text",75 "type_info": "Text",
65 "origin": {76 "origin": {
@@ -70,7 +81,7 @@
70 }81 }
71 },82 },
72 {83 {
73- "ordinal": 6,84+ "ordinal": 7,
74 "name": "stage",85 "name": "stage",
75 "type_info": "Text",86 "type_info": "Text",
76 "origin": {87 "origin": {
@@ -81,7 +92,7 @@
81 }92 }
82 },93 },
83 {94 {
84- "ordinal": 7,95+ "ordinal": 8,
85 "name": "progress",96 "name": "progress",
86 "type_info": "Float8",97 "type_info": "Float8",
87 "origin": {98 "origin": {
@@ -92,7 +103,7 @@
92 }103 }
93 },104 },
94 {105 {
95- "ordinal": 8,106+ "ordinal": 9,
96 "name": "error_code",107 "name": "error_code",
97 "type_info": "Text",108 "type_info": "Text",
98 "origin": {109 "origin": {
@@ -103,7 +114,7 @@
103 }114 }
104 },115 },
105 {116 {
106- "ordinal": 9,117+ "ordinal": 10,
107 "name": "audio_key",118 "name": "audio_key",
108 "type_info": "Text",119 "type_info": "Text",
109 "origin": {120 "origin": {
@@ -114,7 +125,7 @@
114 }125 }
115 },126 },
116 {127 {
117- "ordinal": 10,128+ "ordinal": 11,
118 "name": "audio_name",129 "name": "audio_name",
119 "type_info": "Text",130 "type_info": "Text",
120 "origin": {131 "origin": {
@@ -125,7 +136,7 @@
125 }136 }
126 },137 },
127 {138 {
128- "ordinal": 11,139+ "ordinal": 12,
129 "name": "audio_type",140 "name": "audio_type",
130 "type_info": "Text",141 "type_info": "Text",
131 "origin": {142 "origin": {
@@ -136,7 +147,7 @@
136 }147 }
137 },148 },
138 {149 {
139- "ordinal": 12,150+ "ordinal": 13,
140 "name": "audio_bytes",151 "name": "audio_bytes",
141 "type_info": "Int8",152 "type_info": "Int8",
142 "origin": {153 "origin": {
@@ -147,7 +158,7 @@
147 }158 }
148 },159 },
149 {160 {
150- "ordinal": 13,161+ "ordinal": 14,
151 "name": "duration_secs",162 "name": "duration_secs",
152 "type_info": "Float8",163 "type_info": "Float8",
153 "origin": {164 "origin": {
@@ -158,7 +169,7 @@
158 }169 }
159 },170 },
160 {171 {
161- "ordinal": 14,172+ "ordinal": 15,
162 "name": "eta_secs",173 "name": "eta_secs",
163 "type_info": "Int8",174 "type_info": "Int8",
164 "origin": {175 "origin": {
@@ -169,7 +180,7 @@
169 }180 }
170 },181 },
171 {182 {
172- "ordinal": 15,183+ "ordinal": 16,
173 "name": "created_at: Timestamp",184 "name": "created_at: Timestamp",
174 "type_info": "Int8",185 "type_info": "Int8",
175 "origin": {186 "origin": {
@@ -180,7 +191,7 @@
180 }191 }
181 },192 },
182 {193 {
183- "ordinal": 16,194+ "ordinal": 17,
184 "name": "updated_at: Timestamp",195 "name": "updated_at: Timestamp",
185 "type_info": "Int8",196 "type_info": "Int8",
186 "origin": {197 "origin": {
@@ -202,6 +213,7 @@
202 false,213 false,
203 true,214 true,
204 true,215 true,
216+ true,
205 false,217 false,
206 false,218 false,
207 false,219 false,
@@ -216,5 +228,5 @@
216 false228 false
217 ]229 ]
218 },230 },
219- "hash": "d1b16c756ea05fe53f875c57b4d46dfdc152943eb31d5df4c531af6da3e6ec7b"231+ "hash": "cb286f2c1e63c638be8a58c0b9b0fb4add9e70c39cc9095ddafd3693e27f7bfd"
220 }232 }
.sqlx/query-e1bd89bafa14d3594316fc1768683dd9869275117ab83a255dac8de33b35725c.jsondeleted+0 -76
@@ -1,76 +0,0 @@
1-{
2- "db_name": "PostgreSQL",
3- "query": "SELECT id AS \"id: CourseNoteFileId\",\n course_note AS \"course_note: CourseNoteId\", name AS \"name: FileName\",\n content_type AS \"content_type: FileContentType\", size FROM course_note_file\n WHERE course_note = $1 AND content_type = 'application/pdf'\n ORDER BY id DESC\n LIMIT 1",
4- "describe": {
5- "columns": [
6- {
7- "ordinal": 0,
8- "name": "id: CourseNoteFileId",
9- "type_info": "Uuid",
10- "origin": {
11- "Table": {
12- "table": "course_note_file",
13- "name": "id"
14- }
15- }
16- },
17- {
18- "ordinal": 1,
19- "name": "course_note: CourseNoteId",
20- "type_info": "Uuid",
21- "origin": {
22- "Table": {
23- "table": "course_note_file",
24- "name": "course_note"
25- }
26- }
27- },
28- {
29- "ordinal": 2,
30- "name": "name: FileName",
31- "type_info": "Text",
32- "origin": {
33- "Table": {
34- "table": "course_note_file",
35- "name": "name"
36- }
37- }
38- },
39- {
40- "ordinal": 3,
41- "name": "content_type: FileContentType",
42- "type_info": "Text",
43- "origin": {
44- "Table": {
45- "table": "course_note_file",
46- "name": "content_type"
47- }
48- }
49- },
50- {
51- "ordinal": 4,
52- "name": "size",
53- "type_info": "Int8",
54- "origin": {
55- "Table": {
56- "table": "course_note_file",
57- "name": "size"
58- }
59- }
60- }
61- ],
62- "parameters": {
63- "Left": [
64- "Uuid"
65- ]
66- },
67- "nullable": [
68- false,
69- false,
70- false,
71- false,
72- false
73- ]
74- },
75- "hash": "e1bd89bafa14d3594316fc1768683dd9869275117ab83a255dac8de33b35725c"
76-}
migrations/school/20260923000002_podcast_sources.sqladded+11 -0
@@ -0,0 +1,11 @@
1+-- The per-source outcomes the service reports on `podcast.report` for a
2+-- multi-document episode: one JSONB array of `{key, name, status}`, stored
3+-- verbatim and replayed by `GET /podcast/jobs/{id}/result`.
4+--
5+-- WHERE THIS FILE BELONGS: `migrations/school/` in the backend repo. APPEND-ONLY
6+-- relative to the existing school migrations: one new nullable column, no
7+-- backfill. A job finished before this column existed stays NULL, and a report
8+-- that omits the field (a service that has not learned it yet) leaves it NULL.
9+-- The report statement fills it once (`COALESCE`), the same way `transcript`
10+-- is filled, and never rewrites a value that already landed.
11+ALTER TABLE podcast_job ADD COLUMN sources JSONB NULL;
src/ai/podcast.rsmodified+46 -13
@@ -1,8 +1,8 @@
1 //! Payload contract for the `podcast.*` capabilities and the audio ingest —1 //! Payload contract for the `podcast.*` capabilities and the audio ingest —
2 //! both directions of the podcast seam.2 //! both directions of the podcast seam.
3 //!3 //!
4-//! The podcast service turns one stored source — a course note's PDF — into an4+//! The podcast service turns a course note's stored attachments — PDF,
5-//! audio episode. Since 2026-09-17 the **backend owns that job's record**: the5+//! document, text — into one audio episode, narrating them in order. Since 2026-09-17 the **backend owns that job's record**: the
6 //! submit door mints the job id, writes the row, and then dispatches6 //! submit door mints the job id, writes the row, and then dispatches
7 //! `podcast.submit` with that id; the service reports every transition back7 //! `podcast.submit` with that id; the service reports every transition back
8 //! through the client-initiated `podcast.report` capability, and uploads the8 //! through the client-initiated `podcast.report` capability, and uploads the
@@ -17,9 +17,10 @@
17 //! * [`submit`] — `podcast.submit`, whose payload carries the backend-minted17 //! * [`submit`] — `podcast.submit`, whose payload carries the backend-minted
18 //! `job_id`, the submitting `user_id` (the service stores both; its own18 //! `job_id`, the submitting `user_id` (the service stores both; its own
19 //! record is keyed by the id the backend will keep asking about), and the19 //! record is keyed by the id the backend will keep asking about), and the
20-//! `source_key` of the note's PDF: the backend resolves which file that is20+//! note's `sources` — every attachment whose blob is on this host, in
21-//! before the job exists, so the service is never asked to open a name it21+//! upload order: the backend resolves which files those are before the job
22-//! cannot turn into bytes.22+//! exists, so the service is never asked to open a name it cannot turn
23+//! into bytes.
23 //! * [`cancel`] — `podcast.cancel`, unchanged: a write on the service's queue,24 //! * [`cancel`] — `podcast.cancel`, unchanged: a write on the service's queue,
24 //! and the capability is what decides whether a deployment offers the door.25 //! and the capability is what decides whether a deployment offers the door.
25 //!26 //!
@@ -45,6 +46,17 @@ pub use crate::constant::{
45 AI_PODCAST_CANCEL_CAPABILITY, AI_PODCAST_REPORT_CAPABILITY, AI_PODCAST_SUBMIT_CAPABILITY,46 AI_PODCAST_CANCEL_CAPABILITY, AI_PODCAST_REPORT_CAPABILITY, AI_PODCAST_SUBMIT_CAPABILITY,
46 };47 };
47 48
49+/// One attachment the job narrates, as the submit door resolved it: the blob
50+/// key the service reads at `<PODCAST_MEDIA_ROOT>/<school>/<key>`, the file
51+/// name the upload declared, and the declared content type — which the
52+/// service treats as a hint only, extracting by magic bytes instead.
53+#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
54+pub struct PodcastSource {
55+ pub key: String,
56+ pub name: String,
57+ pub content_type: String,
58+}
59+
48 /// What the backend asks a podcast service to start. The `job_id` is the60 /// What the backend asks a podcast service to start. The `job_id` is the
49 /// backend's own minted id — the service keys its record by it and echoes it61 /// backend's own minted id — the service keys its record by it and echoes it
50 /// in every report, so the two stores can never disagree about which job a62 /// in every report, so the two stores can never disagree about which job a
@@ -52,13 +64,17 @@ pub use crate::constant::{
52 #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]64 #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
53 pub struct PodcastSubmitPayload {65 pub struct PodcastSubmitPayload {
54 pub job_id: String,66 pub job_id: String,
55- /// The course note the job narrates, for the record. `source_key` is the67+ /// The course note the job narrates, for the record.
56- /// handle the service actually opens.
57 pub source_id: String,68 pub source_id: String,
58- /// The blob key of the note's PDF attachment — the file the service reads69+ /// The note's attachments, in upload order (id ASC): every attachment
59- /// at `<PODCAST_MEDIA_ROOT>/<school>/<source_key>`. The backend resolves70+ /// whose blob is on this host. The backend resolves them before the job
60- /// it (the note's newest `application/pdf` attachment) before the job71+ /// exists; `source_id` alone names nothing the service could open. The
61- /// exists; `source_id` alone names nothing the service could open.72+ /// service narrates all of them, one document each.
73+ pub sources: Vec<PodcastSource>,
74+ /// One-release compat alias for `sources[0].key`: the pre-multi-source
75+ /// field, kept so a service that has not learned `sources` yet still
76+ /// narrates the first document. A service reads `sources` when present
77+ /// and falls back to this.
62 pub source_key: String,78 pub source_key: String,
63 /// `None` means the service applies its own default (`duz_okuma` today).79 /// `None` means the service applies its own default (`duz_okuma` today).
64 #[serde(default, skip_serializing_if = "Option::is_none")]80 #[serde(default, skip_serializing_if = "Option::is_none")]
@@ -120,6 +136,22 @@ pub struct PodcastReportPayload {
120 /// keeps that older payload valid.136 /// keeps that older payload valid.
121 #[serde(default)]137 #[serde(default)]
122 pub transcript: Option<String>,138 pub transcript: Option<String>,
139+ /// The per-source outcomes of the episode: `ok`, or `skipped:<code>` for
140+ /// a source that failed extraction and was left out. Absent on a service
141+ /// that has not learned the field yet — `#[serde(default)]` keeps that
142+ /// older payload valid, exactly as it does for `transcript`.
143+ #[serde(default)]
144+ pub sources: Option<Vec<PodcastSourceStatus>>,
145+}
146+
147+/// One source's outcome as the service reported it. The backend stores the
148+/// array verbatim on the job row; the result door replays it.
149+#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
150+pub struct PodcastSourceStatus {
151+ pub key: String,
152+ pub name: String,
153+ /// `ok`, or `skipped:<code>`.
154+ pub status: String,
123 }155 }
124 156
125 /// The answer to one report. `stored` is always `true` on an `Ok` — an157 /// The answer to one report. `stored` is always `true` on an `Ok` — an
@@ -154,8 +186,8 @@ pub async fn cancel(
154 ///186 ///
155 /// The decode is deliberately strict: a payload that does not fit187 /// The decode is deliberately strict: a payload that does not fit
156 /// [`PodcastReportPayload`] is `invalid_payload`, never coerced into a188 /// [`PodcastReportPayload`] is `invalid_payload`, never coerced into a
157-/// half-filled report. `transcript` is the one defaulted field, so a service189+/// half-filled report. `transcript` and `sources` are the defaulted fields,
158-/// that omits it still reports.190+/// so a service that omits them still reports.
159 pub async fn report(db: &Database, payload: Value) -> Result<Value, (&'static str, String)> {191 pub async fn report(db: &Database, payload: Value) -> Result<Value, (&'static str, String)> {
160 let report: PodcastReportPayload = serde_json::from_value(payload).map_err(|err| {192 let report: PodcastReportPayload = serde_json::from_value(payload).map_err(|err| {
161 (193 (
@@ -173,6 +205,7 @@ pub async fn report(db: &Database, payload: Value) -> Result<Value, (&'static st
173 progress: report.progress,205 progress: report.progress,
174 error_code: report.error_code.as_deref(),206 error_code: report.error_code.as_deref(),
175 transcript: report.transcript.as_deref(),207 transcript: report.transcript.as_deref(),
208+ sources: report.sources.as_deref(),
176 };209 };
177 match crate::service::podcast_job::report(db, &input).await {210 match crate::service::podcast_job::report(db, &input).await {
178 Ok(job) => Ok(serde_json::to_value(PodcastReportReply {211 Ok(job) => Ok(serde_json::to_value(PodcastReportReply {
src/db/course_note_file.rsmodified+0 -25
@@ -101,31 +101,6 @@ pub async fn read_for(
101 Ok(file)101 Ok(file)
102 }102 }
103 103
104-/// The note's newest `application/pdf` attachment — the file the podcast
105-/// submit door narrates. `None` covers both a note that never had a PDF and a
106-/// note id that names no row at all: either way there is nothing to narrate.
107-///
108-/// The content type is matched exactly as it was declared on upload, because
109-/// that is the only type the service's extractor reads.
110-pub async fn newest_pdf(
111- db: &Database,
112- note: &CourseNoteId,
113-) -> Result<Option<CourseNoteFile>, AppError> {
114- let file = sqlx::query_as!(
115- CourseNoteFile,
116- r#"SELECT id AS "id: CourseNoteFileId",
117- course_note AS "course_note: CourseNoteId", name AS "name: FileName",
118- content_type AS "content_type: FileContentType", size FROM course_note_file
119- WHERE course_note = $1 AND content_type = 'application/pdf'
120- ORDER BY id DESC
121- LIMIT 1"#,
122- note.uuid()
123- )
124- .fetch_optional(db)
125- .await?;
126- Ok(file)
127-}
128-
129 /// All of `note`'s attachment rows, newest first.104 /// All of `note`'s attachment rows, newest first.
130 pub async fn list_for(105 pub async fn list_for(
131 db: &Database,106 db: &Database,
src/db/podcast_job.rsmodified+28 -17
@@ -23,6 +23,8 @@ use crate::domain::podcast_job::{PodcastJob, PodcastJobId, PodcastJobState};
23 use crate::domain::timestamp::Timestamp;23 use crate::domain::timestamp::Timestamp;
24 use crate::domain::user::UserId;24 use crate::domain::user::UserId;
25 use crate::error::AppError;25 use crate::error::AppError;
26+use serde_json::Value;
27+use sqlx::types::Json;
26 use sqlx::{query, query_as};28 use sqlx::{query, query_as};
27 29
28 /// Write one freshly minted job. The id and timestamps are the caller's — the30 /// Write one freshly minted job. The id and timestamps are the caller's — the
@@ -33,10 +35,10 @@ pub async fn insert(db: &Database, job: &PodcastJob) -> Result<PodcastJob, AppEr
33 PodcastJob,35 PodcastJob,
34 "INSERT INTO podcast_job (id, user_id, source_id, format, state, stage, progress, \36 "INSERT INTO podcast_job (id, user_id, source_id, format, state, stage, progress, \
35 error_code, audio_key, audio_name, audio_type, audio_bytes, duration_secs, \37 error_code, audio_key, audio_name, audio_type, audio_bytes, duration_secs, \
36- eta_secs, created_at, updated_at) \38+ eta_secs, created_at, updated_at, sources) \
37- VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $15) \39+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $15, $16) \
38 RETURNING id AS \"id: PodcastJobId\", user_id AS \"user_id: UserId\", \40 RETURNING id AS \"id: PodcastJobId\", user_id AS \"user_id: UserId\", \
39- source_id, format, transcript, state AS \"state: PodcastJobState\", stage, progress, error_code, \41+ source_id, format, transcript, sources AS \"sources: Json<Value>\", state AS \"state: PodcastJobState\", stage, progress, error_code, \
40 audio_key, audio_name, audio_type, audio_bytes, duration_secs, eta_secs, \42 audio_key, audio_name, audio_type, audio_bytes, duration_secs, eta_secs, \
41 created_at AS \"created_at: Timestamp\", updated_at AS \"updated_at: Timestamp\"",43 created_at AS \"created_at: Timestamp\", updated_at AS \"updated_at: Timestamp\"",
42 job.get_id().uuid(),44 job.get_id().uuid(),
@@ -54,6 +56,7 @@ pub async fn insert(db: &Database, job: &PodcastJob) -> Result<PodcastJob, AppEr
54 job.get_duration_secs(),56 job.get_duration_secs(),
55 job.get_eta_secs(),57 job.get_eta_secs(),
56 job.get_created_at().as_millis(),58 job.get_created_at().as_millis(),
59+ job.get_sources(),
57 )60 )
58 .fetch_one(db)61 .fetch_one(db)
59 .await?)62 .await?)
@@ -65,7 +68,7 @@ pub async fn read(db: &Database, id: &PodcastJobId) -> Result<Option<PodcastJob>
65 Ok(query_as!(68 Ok(query_as!(
66 PodcastJob,69 PodcastJob,
67 "SELECT id AS \"id: PodcastJobId\", user_id AS \"user_id: UserId\", \70 "SELECT id AS \"id: PodcastJobId\", user_id AS \"user_id: UserId\", \
68- source_id, format, transcript, state AS \"state: PodcastJobState\", stage, progress, error_code, \71+ source_id, format, transcript, sources AS \"sources: Json<Value>\", state AS \"state: PodcastJobState\", stage, progress, error_code, \
69 audio_key, audio_name, audio_type, audio_bytes, duration_secs, eta_secs, \72 audio_key, audio_name, audio_type, audio_bytes, duration_secs, eta_secs, \
70 created_at AS \"created_at: Timestamp\", updated_at AS \"updated_at: Timestamp\" \73 created_at AS \"created_at: Timestamp\", updated_at AS \"updated_at: Timestamp\" \
71 FROM podcast_job WHERE id = $1",74 FROM podcast_job WHERE id = $1",
@@ -87,7 +90,7 @@ pub async fn read_for(
87 Ok(query_as!(90 Ok(query_as!(
88 PodcastJob,91 PodcastJob,
89 "SELECT id AS \"id: PodcastJobId\", user_id AS \"user_id: UserId\", \92 "SELECT id AS \"id: PodcastJobId\", user_id AS \"user_id: UserId\", \
90- source_id, format, transcript, state AS \"state: PodcastJobState\", stage, progress, error_code, \93+ source_id, format, transcript, sources AS \"sources: Json<Value>\", state AS \"state: PodcastJobState\", stage, progress, error_code, \
91 audio_key, audio_name, audio_type, audio_bytes, duration_secs, eta_secs, \94 audio_key, audio_name, audio_type, audio_bytes, duration_secs, eta_secs, \
92 created_at AS \"created_at: Timestamp\", updated_at AS \"updated_at: Timestamp\" \95 created_at AS \"created_at: Timestamp\", updated_at AS \"updated_at: Timestamp\" \
93 FROM podcast_job WHERE id = $1 AND user_id = $2",96 FROM podcast_job WHERE id = $1 AND user_id = $2",
@@ -177,11 +180,11 @@ async fn with_source_titles(
177 /// concurrent write (a cancel, another report) moved it first — the caller180 /// concurrent write (a cancel, another report) moved it first — the caller
178 /// re-reads and answers the truth.181 /// re-reads and answers the truth.
179 ///182 ///
180-/// `format` and `transcript` fill their columns once and never rewrite them:183+/// `format`, `transcript` and `sources` fill their columns once and never
181-/// the service's default resolution arrives on the first report, and a later184+/// rewrite them: the service's default resolution arrives on the first
182-/// report disagreeing with the format is refused by the service layer, not185+/// report, and a later report disagreeing with the format is refused by the
183-/// silently stored. A later transcript is ignored the same way — the first186+/// service layer, not silently stored. A later transcript is ignored the same
184-/// non-null value stands.187+/// way — the first non-null value stands.
185 #[allow(clippy::too_many_arguments)]188 #[allow(clippy::too_many_arguments)]
186 pub async fn report(189 pub async fn report(
187 db: &Database,190 db: &Database,
@@ -193,16 +196,17 @@ pub async fn report(
193 error_code: Option<&str>,196 error_code: Option<&str>,
194 format: Option<&str>,197 format: Option<&str>,
195 transcript: Option<&str>,198 transcript: Option<&str>,
199+ sources: Option<&Value>,
196 ) -> Result<Option<PodcastJob>, AppError> {200 ) -> Result<Option<PodcastJob>, AppError> {
197 let now = Timestamp::now().as_millis();201 let now = Timestamp::now().as_millis();
198 Ok(query_as!(202 Ok(query_as!(
199 PodcastJob,203 PodcastJob,
200 "UPDATE podcast_job SET state = $3, stage = $4, progress = $5, error_code = $6, \204 "UPDATE podcast_job SET state = $3, stage = $4, progress = $5, error_code = $6, \
201 format = COALESCE(format, $7::text), transcript = COALESCE(transcript, $8::text), \205 format = COALESCE(format, $7::text), transcript = COALESCE(transcript, $8::text), \
202- updated_at = $9 \206+ sources = COALESCE(sources, $9::jsonb), updated_at = $10 \
203- WHERE id = $1 AND state = $2 \207+ WHERE id = $1 AND state = $2 \
204 RETURNING id AS \"id: PodcastJobId\", user_id AS \"user_id: UserId\", \208 RETURNING id AS \"id: PodcastJobId\", user_id AS \"user_id: UserId\", \
205- source_id, format, transcript, state AS \"state: PodcastJobState\", stage, progress, error_code, \209+ source_id, format, transcript, sources AS \"sources: Json<Value>\", state AS \"state: PodcastJobState\", stage, progress, error_code, \
206 audio_key, audio_name, audio_type, audio_bytes, duration_secs, eta_secs, \210 audio_key, audio_name, audio_type, audio_bytes, duration_secs, eta_secs, \
207 created_at AS \"created_at: Timestamp\", updated_at AS \"updated_at: Timestamp\"",211 created_at AS \"created_at: Timestamp\", updated_at AS \"updated_at: Timestamp\"",
208 id.uuid(),212 id.uuid(),
@@ -213,6 +217,7 @@ pub async fn report(
213 error_code,217 error_code,
214 format,218 format,
215 transcript,219 transcript,
220+ sources,
216 now,221 now,
217 )222 )
218 .fetch_optional(db)223 .fetch_optional(db)
@@ -233,7 +238,7 @@ pub async fn set_cancelled(
233 "UPDATE podcast_job SET state = 'cancelled', stage = '', updated_at = $2 \238 "UPDATE podcast_job SET state = 'cancelled', stage = '', updated_at = $2 \
234 WHERE id = $1 AND state IN ('queued', 'running') \239 WHERE id = $1 AND state IN ('queued', 'running') \
235 RETURNING id AS \"id: PodcastJobId\", user_id AS \"user_id: UserId\", \240 RETURNING id AS \"id: PodcastJobId\", user_id AS \"user_id: UserId\", \
236- source_id, format, transcript, state AS \"state: PodcastJobState\", stage, progress, error_code, \241+ source_id, format, transcript, sources AS \"sources: Json<Value>\", state AS \"state: PodcastJobState\", stage, progress, error_code, \
237 audio_key, audio_name, audio_type, audio_bytes, duration_secs, eta_secs, \242 audio_key, audio_name, audio_type, audio_bytes, duration_secs, eta_secs, \
238 created_at AS \"created_at: Timestamp\", updated_at AS \"updated_at: Timestamp\"",243 created_at AS \"created_at: Timestamp\", updated_at AS \"updated_at: Timestamp\"",
239 id.uuid(),244 id.uuid(),
@@ -258,7 +263,7 @@ pub async fn set_failed(
258 "UPDATE podcast_job SET state = 'failed', error_code = $2, stage = '', updated_at = $3 \263 "UPDATE podcast_job SET state = 'failed', error_code = $2, stage = '', updated_at = $3 \
259 WHERE id = $1 AND state IN ('queued', 'running') \264 WHERE id = $1 AND state IN ('queued', 'running') \
260 RETURNING id AS \"id: PodcastJobId\", user_id AS \"user_id: UserId\", \265 RETURNING id AS \"id: PodcastJobId\", user_id AS \"user_id: UserId\", \
261- source_id, format, transcript, state AS \"state: PodcastJobState\", stage, progress, error_code, \266+ source_id, format, transcript, sources AS \"sources: Json<Value>\", state AS \"state: PodcastJobState\", stage, progress, error_code, \
262 audio_key, audio_name, audio_type, audio_bytes, duration_secs, eta_secs, \267 audio_key, audio_name, audio_type, audio_bytes, duration_secs, eta_secs, \
263 created_at AS \"created_at: Timestamp\", updated_at AS \"updated_at: Timestamp\"",268 created_at AS \"created_at: Timestamp\", updated_at AS \"updated_at: Timestamp\"",
264 id.uuid(),269 id.uuid(),
@@ -289,7 +294,7 @@ pub async fn set_audio(
289 audio_bytes = $5, duration_secs = $6, updated_at = $7 \294 audio_bytes = $5, duration_secs = $6, updated_at = $7 \
290 WHERE id = $1 \295 WHERE id = $1 \
291 RETURNING id AS \"id: PodcastJobId\", user_id AS \"user_id: UserId\", \296 RETURNING id AS \"id: PodcastJobId\", user_id AS \"user_id: UserId\", \
292- source_id, format, transcript, state AS \"state: PodcastJobState\", stage, progress, error_code, \297+ source_id, format, transcript, sources AS \"sources: Json<Value>\", state AS \"state: PodcastJobState\", stage, progress, error_code, \
293 audio_key, audio_name, audio_type, audio_bytes, duration_secs, eta_secs, \298 audio_key, audio_name, audio_type, audio_bytes, duration_secs, eta_secs, \
294 created_at AS \"created_at: Timestamp\", updated_at AS \"updated_at: Timestamp\"",299 created_at AS \"created_at: Timestamp\", updated_at AS \"updated_at: Timestamp\"",
295 id.uuid(),300 id.uuid(),
@@ -316,7 +321,7 @@ pub async fn set_eta(
316 PodcastJob,321 PodcastJob,
317 "UPDATE podcast_job SET eta_secs = $2 WHERE id = $1 \322 "UPDATE podcast_job SET eta_secs = $2 WHERE id = $1 \
318 RETURNING id AS \"id: PodcastJobId\", user_id AS \"user_id: UserId\", \323 RETURNING id AS \"id: PodcastJobId\", user_id AS \"user_id: UserId\", \
319- source_id, format, transcript, state AS \"state: PodcastJobState\", stage, progress, error_code, \324+ source_id, format, transcript, sources AS \"sources: Json<Value>\", state AS \"state: PodcastJobState\", stage, progress, error_code, \
320 audio_key, audio_name, audio_type, audio_bytes, duration_secs, eta_secs, \325 audio_key, audio_name, audio_type, audio_bytes, duration_secs, eta_secs, \
321 created_at AS \"created_at: Timestamp\", updated_at AS \"updated_at: Timestamp\"",326 created_at AS \"created_at: Timestamp\", updated_at AS \"updated_at: Timestamp\"",
322 id.uuid(),327 id.uuid(),
@@ -361,6 +366,7 @@ mod tests {
361 source_id: "src".to_string(),366 source_id: "src".to_string(),
362 format: None,367 format: None,
363 transcript: None,368 transcript: None,
369+ sources: None,
364 state: PodcastJobState::Queued,370 state: PodcastJobState::Queued,
365 stage: String::new(),371 stage: String::new(),
366 progress: 0.0,372 progress: 0.0,
@@ -398,6 +404,7 @@ mod tests {
398 None,404 None,
399 Some("duz_okuma"),405 Some("duz_okuma"),
400 Some("bolum bir\n\nbolum iki"),406 Some("bolum bir\n\nbolum iki"),
407+ None,
401 )408 )
402 .await409 .await
403 .expect("report")410 .expect("report")
@@ -417,6 +424,7 @@ mod tests {
417 None,424 None,
418 None,425 None,
419 Some("should not land"),426 Some("should not land"),
427+ None,
420 )428 )
421 .await429 .await
422 .expect("report");430 .expect("report");
@@ -434,6 +442,7 @@ mod tests {
434 None,442 None,
435 None,443 None,
436 Some("also not"),444 Some("also not"),
445+ None,
437 )446 )
438 .await447 .await
439 .expect("report");448 .expect("report");
@@ -495,6 +504,7 @@ mod tests {
495 None,504 None,
496 None,505 None,
497 None,506 None,
507+ None,
498 )508 )
499 .await;509 .await;
500 assert!(refused.is_err(), "the CHECK backstops the service layer");510 assert!(refused.is_err(), "the CHECK backstops the service layer");
@@ -520,6 +530,7 @@ mod tests {
520 None,530 None,
521 None,531 None,
522 Some("metin"),532 Some("metin"),
533+ None,
523 )534 )
524 .await535 .await
525 .expect("report")536 .expect("report")
src/domain/podcast_job.rsmodified+12 -0
@@ -27,6 +27,8 @@ use crate::constant::{
27 use crate::domain::monotonic_id::next_uuid;27 use crate::domain::monotonic_id::next_uuid;
28 use crate::domain::timestamp::Timestamp;28 use crate::domain::timestamp::Timestamp;
29 use crate::domain::user::UserId;29 use crate::domain::user::UserId;
30+use serde_json::Value;
31+use sqlx::types::Json;
30 32
31 #[derive(Debug, Clone, PartialEq, Eq, sqlx::Type)]33 #[derive(Debug, Clone, PartialEq, Eq, sqlx::Type)]
32 #[sqlx(transparent)]34 #[sqlx(transparent)]
@@ -139,6 +141,10 @@ pub struct PodcastJob {
139 /// The episode transcript, chapters joined with blank lines. `None` until141 /// The episode transcript, chapters joined with blank lines. `None` until
140 /// a report carries one, and forever for a job whose service never did.142 /// a report carries one, and forever for a job whose service never did.
141 pub(crate) transcript: Option<String>,143 pub(crate) transcript: Option<String>,
144+ /// The per-source outcomes the service reported on `podcast.report` — a
145+ /// JSON array of `{key, name, status}`, stored verbatim. `None` until a
146+ /// report carries one, and forever for a job whose service never did.
147+ pub(crate) sources: Option<Json<Value>>,
142 pub(crate) state: PodcastJobState,148 pub(crate) state: PodcastJobState,
143 pub(crate) stage: String,149 pub(crate) stage: String,
144 pub(crate) progress: f64,150 pub(crate) progress: f64,
@@ -174,6 +180,11 @@ impl PodcastJob {
174 self.transcript.as_deref()180 self.transcript.as_deref()
175 }181 }
176 182
183+ /// The verbatim per-source report, if the service ever sent one.
184+ pub fn get_sources(&self) -> Option<&Value> {
185+ self.sources.as_ref().map(|sources| &sources.0)
186+ }
187+
177 pub fn get_state(&self) -> PodcastJobState {188 pub fn get_state(&self) -> PodcastJobState {
178 self.state189 self.state
179 }190 }
@@ -334,6 +345,7 @@ mod tests {
334 source_id: "src".to_string(),345 source_id: "src".to_string(),
335 format: None,346 format: None,
336 transcript: None,347 transcript: None,
348+ sources: None,
337 state,349 state,
338 stage: String::new(),350 stage: String::new(),
339 progress: 0.0,351 progress: 0.0,
src/lib.rsmodified+1 -1
@@ -59,7 +59,7 @@ use crate::web::module_gate::gate;
59 (name = "chatbot", description = "The AI chatbot, relayed through the QUIC bridge to an out-of-process AI service. Every authenticated role may chat (parents included) and every thread is private to its owner — nobody, not even an admin, reads someone else's. A user keeps up to the school's `max_chatbot_threads` threads (409 at the cap, delete one first) and sends at most `RATE_LIMIT_CHATBOT_PER_MINUTE` messages a minute (default 20, `0` disables the tier; 429 with `Retry-After`). A thread can be renamed — or its name cleared — with `PATCH /chatbot/threads/{id}` (`{title}`, `null` to clear); nothing names a thread automatically. Sending is asynchronous: `POST /chatbot/threads/{id}/messages` writes the turn plus an empty `pending` assistant row and answers `202 {message_id, status}` immediately, because an inference outlives a normal request. The pending row is what a reload comes back to, not a queued job: the bridge round trip runs in an in-process task the `202` leaves behind, so a restart mid-inference strands that turn — it settles `failed`/`interrupted` (a reader projects a `pending` row older than 300 seconds as failed, and the boot sweep stamps that verdict durably) rather than being answered by anyone. Accepted, because the backend is a single process with stop-the-world deploys: there is no peer that could have taken the turn over. Sending is also serialized against the thread's own deletion — both rows ride a transaction that writes the thread row, so a turn accepted while `DELETE /chatbot/threads/{id}` is committing is refused with a `404` instead of surviving as a message under a thread that is gone. The answer is then read either by polling `GET .../messages/{mid}` or over the Server-Sent-Events stream at `.../messages/{mid}/stream` (`delta` chunks, then one `done` or `error`) — both read the same row, so they never disagree, and a stream opened after the answer landed still replays it. An answer the service made longer than `max_chatbot_message_len` is clipped rather than discarded, and the stored turn is flagged `truncated: true` — the polling read and the SSE `done` payload always agree on it. A turn always settles: `complete` with the text, or `failed` with a short code (`unavailable`, `busy`, `timed_out`, `transport`, `protocol`, `bad_reply`, `empty_reply`, `interrupted`, or the service's own). With no `chat.reply` service connected anywhere in the deployment, sending answers `503` and writes nothing"),59 (name = "chatbot", description = "The AI chatbot, relayed through the QUIC bridge to an out-of-process AI service. Every authenticated role may chat (parents included) and every thread is private to its owner — nobody, not even an admin, reads someone else's. A user keeps up to the school's `max_chatbot_threads` threads (409 at the cap, delete one first) and sends at most `RATE_LIMIT_CHATBOT_PER_MINUTE` messages a minute (default 20, `0` disables the tier; 429 with `Retry-After`). A thread can be renamed — or its name cleared — with `PATCH /chatbot/threads/{id}` (`{title}`, `null` to clear); nothing names a thread automatically. Sending is asynchronous: `POST /chatbot/threads/{id}/messages` writes the turn plus an empty `pending` assistant row and answers `202 {message_id, status}` immediately, because an inference outlives a normal request. The pending row is what a reload comes back to, not a queued job: the bridge round trip runs in an in-process task the `202` leaves behind, so a restart mid-inference strands that turn — it settles `failed`/`interrupted` (a reader projects a `pending` row older than 300 seconds as failed, and the boot sweep stamps that verdict durably) rather than being answered by anyone. Accepted, because the backend is a single process with stop-the-world deploys: there is no peer that could have taken the turn over. Sending is also serialized against the thread's own deletion — both rows ride a transaction that writes the thread row, so a turn accepted while `DELETE /chatbot/threads/{id}` is committing is refused with a `404` instead of surviving as a message under a thread that is gone. The answer is then read either by polling `GET .../messages/{mid}` or over the Server-Sent-Events stream at `.../messages/{mid}/stream` (`delta` chunks, then one `done` or `error`) — both read the same row, so they never disagree, and a stream opened after the answer landed still replays it. An answer the service made longer than `max_chatbot_message_len` is clipped rather than discarded, and the stored turn is flagged `truncated: true` — the polling read and the SSE `done` payload always agree on it. A turn always settles: `complete` with the text, or `failed` with a short code (`unavailable`, `busy`, `timed_out`, `transport`, `protocol`, `bad_reply`, `empty_reply`, `interrupted`, or the service's own). With no `chat.reply` service connected anywhere in the deployment, sending answers `503` and writes nothing"),
60 (name = "rag", description = "The course-note RAG: its own nest, threads and tables, relayed through the same QUIC bridge as the chatbot — RAG is not folded into the chatbot's storage. Every authenticated role may ask (parents included) and every thread is private to its owner. Every question is scoped server-side to `(sınıf, ders)` pairs derived by the server — a manager or an admin gets every class-course pair in the school, everyone else their own memberships (a linked parent's children, and the school-wide club/etüt memberships they hold, which scope the subject across grades, `sinif: null`) — never from the body, so a caller cannot widen their own retrieval; a scope past `MAX_RAG_SCOPE_PAIRS` pairs is refused (400) rather than narrowed. A RAG thread draws on the school's existing AI thread seats (`max_chatbot_threads`, the same seat count the chatbot nest uses, one pool per user), its prompts and answers are bounded by `max_chatbot_message_len`, and its per-minute tier is its own: `RATE_LIMIT_RAG_PER_MINUTE` (default 6, `0` disables the tier; 429 with `Retry-After`). Sending is asynchronous exactly as the chatbot's is: `POST /rag/threads/{id}/messages` writes the turn plus a `pending` assistant row and answers `202`, then poll `GET /rag/threads/{id}/messages/{mid}` or open its `/stream` (SSE `delta`s then `done`/`error`). `503` when no AI service offers `rag.chat`, with nothing written. An answer may abstain — `abstained: true` with a `reason` (`guard_*`, `insufficient_data`, `model_abstained`) is a complete, successful turn, not an error — and carries its `citations`, up to `MAX_RAG_CITATIONS` per answer and at most `MAX_RAG_CITATION_PAGES` pages each (a service reply past either cap fails the turn whole). Each citation's corpus `doc_id` is resolved to the course-note file that owns it (`file`, `null` when no file the asker may view claims that document) beside the pages and retrieval span ids behind it. Two **study** doors are one-shot and synchronous rather than threaded: `POST /rag/summarize` returns a summary of one page/span range and `POST /rag/questions` returns a set of practice questions (plus their range-bounded answers) over one — the artifact is the answer, so nothing is stored and there is no thread or poll. Their body names only a *target within* the asker's own derived pairs (the body's `sinif` plus `ders`): a pair the caller does not hold is `403`, and omitting `sinif` for a ders taught at more than one grade is `400` — the backend never picks a corpus for the caller. Both answer `503` when no AI service offers `rag.summarize`/`rag.questions`, and an `abstained: true` reply with a `reason` is a complete `200`, exactly as on a chat turn. Each waits on its dispatch under a 25 s deadline, deliberately inside the middleware's own 30 s envelope — a dropped handler would answer with prose written for a request that may have written something."),60 (name = "rag", description = "The course-note RAG: its own nest, threads and tables, relayed through the same QUIC bridge as the chatbot — RAG is not folded into the chatbot's storage. Every authenticated role may ask (parents included) and every thread is private to its owner. Every question is scoped server-side to `(sınıf, ders)` pairs derived by the server — a manager or an admin gets every class-course pair in the school, everyone else their own memberships (a linked parent's children, and the school-wide club/etüt memberships they hold, which scope the subject across grades, `sinif: null`) — never from the body, so a caller cannot widen their own retrieval; a scope past `MAX_RAG_SCOPE_PAIRS` pairs is refused (400) rather than narrowed. A RAG thread draws on the school's existing AI thread seats (`max_chatbot_threads`, the same seat count the chatbot nest uses, one pool per user), its prompts and answers are bounded by `max_chatbot_message_len`, and its per-minute tier is its own: `RATE_LIMIT_RAG_PER_MINUTE` (default 6, `0` disables the tier; 429 with `Retry-After`). Sending is asynchronous exactly as the chatbot's is: `POST /rag/threads/{id}/messages` writes the turn plus a `pending` assistant row and answers `202`, then poll `GET /rag/threads/{id}/messages/{mid}` or open its `/stream` (SSE `delta`s then `done`/`error`). `503` when no AI service offers `rag.chat`, with nothing written. An answer may abstain — `abstained: true` with a `reason` (`guard_*`, `insufficient_data`, `model_abstained`) is a complete, successful turn, not an error — and carries its `citations`, up to `MAX_RAG_CITATIONS` per answer and at most `MAX_RAG_CITATION_PAGES` pages each (a service reply past either cap fails the turn whole). Each citation's corpus `doc_id` is resolved to the course-note file that owns it (`file`, `null` when no file the asker may view claims that document) beside the pages and retrieval span ids behind it. Two **study** doors are one-shot and synchronous rather than threaded: `POST /rag/summarize` returns a summary of one page/span range and `POST /rag/questions` returns a set of practice questions (plus their range-bounded answers) over one — the artifact is the answer, so nothing is stored and there is no thread or poll. Their body names only a *target within* the asker's own derived pairs (the body's `sinif` plus `ders`): a pair the caller does not hold is `403`, and omitting `sinif` for a ders taught at more than one grade is `400` — the backend never picks a corpus for the caller. Both answer `503` when no AI service offers `rag.summarize`/`rag.questions`, and an `abstained: true` reply with a `reason` is a complete `200`, exactly as on a chat turn. Each waits on its dispatch under a 25 s deadline, deliberately inside the middleware's own 30 s envelope — a dropped handler would answer with prose written for a request that may have written something."),
61 (name = "insights", description = "ZEKA's computed student insights. The `hezarfen_zeka` AI service dials in over the same QUIC bridge as the chatbot, but it does **not** touch a school database: the backend owns every statement against the `zeka_*` tables, and the service calls the backend by name (`insight.*` capabilities on a client-initiated stream — see `src/ai/insight.rs`) to have its computed rows written and read back. So this nest reads what the service computed and asks it to compute on demand, and its write doors are the same operations the bridge serves: `POST /insights/summaries`, `/recommendations`, `/segments`, `/profiles` and `/runs` store one batch each (manager+, one call one transaction, rows about students school-wide), `GET /insights/pending` is the students the freshest run left pending, and `POST /insights/sweep` / `POST /insights/purge` are retention and graduation housekeeping — all scoped to the caller's own school by the nest's extractors, and none of them takes a school, a database or a query in its body. `GET /insights/schools` is the exception and is not this nest's usual principal: the active-school directory names every customer, so it is mounted on the **builder** principal outside the school gate (a school session answers `401`), exactly like the vendor surface's `GET /schools`. `GET /insights/me` is the caller's own view: a student's summary, their own recommendation cards and their segment profile — and **never** the attention list about themselves, which is a teacher's tool and is not returned to a student or to a linked parent. `GET /insights/students/{id}` is the observer's view of one student — teacher+ narrowed to the students they actually reach through a shared class×course instance, or a parent holding a live link — adding the attention list and the caller's own cards about that student; anyone else reads `404`, never `403`. `POST /insights/students/{id}` and `POST /insights/refresh` (manager+) queue a recompute through the bridge and answer `202` — the compute lands in the service's own rows, so a client polls the read routes; `GET /insights/runs` (manager+) is the run ledger, newest first. Both dispatch doors answer `503` when no service offers the capability, and nothing is queued. Expired and dismissed cards are filtered out of every card read, segment rows below 30 answers (`confidence: none`) are filtered out of every profile read, and a card's `about` is never returned to a student caller."),61 (name = "insights", description = "ZEKA's computed student insights. The `hezarfen_zeka` AI service dials in over the same QUIC bridge as the chatbot, but it does **not** touch a school database: the backend owns every statement against the `zeka_*` tables, and the service calls the backend by name (`insight.*` capabilities on a client-initiated stream — see `src/ai/insight.rs`) to have its computed rows written and read back. So this nest reads what the service computed and asks it to compute on demand, and its write doors are the same operations the bridge serves: `POST /insights/summaries`, `/recommendations`, `/segments`, `/profiles` and `/runs` store one batch each (manager+, one call one transaction, rows about students school-wide), `GET /insights/pending` is the students the freshest run left pending, and `POST /insights/sweep` / `POST /insights/purge` are retention and graduation housekeeping — all scoped to the caller's own school by the nest's extractors, and none of them takes a school, a database or a query in its body. `GET /insights/schools` is the exception and is not this nest's usual principal: the active-school directory names every customer, so it is mounted on the **builder** principal outside the school gate (a school session answers `401`), exactly like the vendor surface's `GET /schools`. `GET /insights/me` is the caller's own view: a student's summary, their own recommendation cards and their segment profile — and **never** the attention list about themselves, which is a teacher's tool and is not returned to a student or to a linked parent. `GET /insights/students/{id}` is the observer's view of one student — teacher+ narrowed to the students they actually reach through a shared class×course instance, or a parent holding a live link — adding the attention list and the caller's own cards about that student; anyone else reads `404`, never `403`. `POST /insights/students/{id}` and `POST /insights/refresh` (manager+) queue a recompute through the bridge and answer `202` — the compute lands in the service's own rows, so a client polls the read routes; `GET /insights/runs` (manager+) is the run ledger, newest first. Both dispatch doors answer `503` when no service offers the capability, and nothing is queued. Expired and dismissed cards are filtered out of every card read, segment rows below 30 answers (`confidence: none`) are filtered out of every profile read, and a card's `about` is never returned to a student caller."),
62- (name = "podcast", description = "Podcast generation, relayed through the same QUIC bridge as the chatbot and the RAG nest — and the **backend owns the job**, not just the HTTP surface. `POST /podcast/jobs` (`{source_id, format?}`) resolves the note's newest `application/pdf` attachment — the blob key the dispatch hands the service as `source_key`, so the service opens `<media root>/<school>/<source_key>` — refusing `409 source_missing` when the note has no PDF or its bytes are missing from this host, then mints the job id, writes the row, dispatches `podcast.submit` to the service and answers `202` with `{job_id, state, eta_secs}`; `GET /podcast/jobs/{id}` polls the backend's own row `{state, stage, progress, error_code}` with no service round trip, `GET /podcast/jobs/{id}/result` collects a finished job's `{audio_id, duration_secs, format, transcript}` (`409` while it is still running), `GET /podcast/jobs/{id}/audio` streams the episode the service uploaded into this school's own blob directory, and `POST /podcast/jobs/{id}/cancel` asks the service to stop it (`cancelled` is \"this call stopped work\", so a finished job answers `false`; a terminal job answers without the service); `GET /podcast/jobs` is the caller's own history, newest first (`?limit=&offset=`), each row carrying the title of the note it narrated. The service reports every transition back through the `podcast.report` capability and uploads the finished mp3 — so status, result and audio keep answering while the service is down or restarted, and a job nobody is updating reads as failed/interrupted after an ETA-scaled window. Submit and cancel refuse `503` when no worker is connected; none of the four read doors needs one (404 for an unknown or foreign job, 410 past the retention window, 409 before the job is done or when its blob is missing from this host)."),62+ (name = "podcast", description = "Podcast generation, relayed through the same QUIC bridge as the chatbot and the RAG nest — and the **backend owns the job**, not just the HTTP surface. `POST /podcast/jobs` (`{source_id, format?}`) resolves the note's attachments — every one whose blob is on this host, dispatched as `sources` in upload order, the blob keys the service opens as `<media root>/<school>/<key>` (`source_key` rides on as the first source's key, one-release compat) — refusing `409 source_missing` when the note has no attachments or none of their blobs are present on this host, then mints the job id, writes the row, dispatches `podcast.submit` to the service and answers `202` with `{job_id, state, eta_secs}`; `GET /podcast/jobs/{id}` polls the backend's own row `{state, stage, progress, error_code}` with no service round trip, `GET /podcast/jobs/{id}/result` collects a finished job's `{audio_id, duration_secs, format, transcript, sources?}` (`409` while it is still running), `GET /podcast/jobs/{id}/audio` streams the episode the service uploaded into this school's own blob directory, and `POST /podcast/jobs/{id}/cancel` asks the service to stop it (`cancelled` is \"this call stopped work\", so a finished job answers `false`; a terminal job answers without the service); `GET /podcast/jobs` is the caller's own history, newest first (`?limit=&offset=`), each row carrying the title of the note it narrated. The service reports every transition back through the `podcast.report` capability and uploads the finished mp3 — so status, result and audio keep answering while the service is down or restarted, and a job nobody is updating reads as failed/interrupted after an ETA-scaled window. Submit and cancel refuse `503` when no worker is connected; none of the four read doors needs one (404 for an unknown or foreign job, 410 past the retention window, 409 before the job is done or when its blob is missing from this host)."),
63 (name = "users", description = "User info: self-service profile and UI preferences (theme `light`/`dark`, language `tr`/`en`, accent color `palette_color` as `#rrggbb` — returned on every user response, `null` until chosen), name search for the pickers (any authenticated user, optionally role-filtered; a student or parent sees only the staff they may message), plus account creation (admin only: `POST /users` mints a school account outright, born with the role the caller names — `student` by default), listing, lookup, and role/profile/preferences administration (admin only). An admin never changes their own role, and the school's **last** admin cannot be demoted at all (`409`) — role management can no longer lock everyone out, not even when two admins…, accent color `palette_color` as `#rrggbb` — returned on every user response, `null` until chosen), name search for the pickers (any authenticated user, optionally role-filtered; a student or parent sees only the staff they may message), plus account creation (admin only: `POST /users` mints a school account outright, born with the role the caller names — `student` by default), listing, lookup, and role/profile/preferences administration (admin only). An admin never changes their own role, and the school's **last** admin cannot be demoted at all (`409`) — role management can no longer lock everyone out, not even when two admins demote each other at the same instant. Also the parent↔student ties: admins link students to a `parent` account under `/users/{id}/students` (link, list, unlink — a role change on either side drops its ties in the *same transaction* as the role write, so a failure mid-way leaves the old role with all its ties intact rather than a half-applied change), and a parent lists their own students at `/users/me/students`; every one of those lists is filtered to accounts that hold the `student` role **right now**, so a tie whose student was promoted out names nobody, exactly as it grants nothing; the tie grants the parent read access to those students' mark, attendance, pomodoro, and homework reports and nothing else. Every account also has a **public profile** (`GET /users/me/profile`, `GET /users/{id}/profile`): username, `display_name` (the self-chosen one, else the `name surname` join, else `null` — the very same three steps every embedded person ref resolves, so a chosen name shows school-wide; it never replaces `name`/`surname`, which stay the school-office record, and it deliberately stays out of the user search fold), role, `bio`, avatar metadata, a narrowed class/course block (id/name/grade and id/title/kind only — never a class's creator or homeroom teacher — capped at `max_profile_classes` / `max_profile_courses`, since `/classes/me` and `/courses/me` are the full paged lists), a sixteen-key `stats` block, and the badges those stats have earned. Four stats are computed at read (finished pomodoro stints and their focused milliseconds, plus the full course and class counts) and twelve are stored lifetime tallies maintained at write time, so a tally can outlive the rows behind it — a deleted exam does not un-sit it; all sixteen read `0`, never `null`. Five are the student's own work (`homework_submitted_total`, `homework_on_time_total`, `exam_sat_total` — **exams sat**, not sittings: a retake of an exam already counted moves nothing, since an `open` exam with unlimited attempts is a start/finish loop a student runs with no teacher in it —, `pomodoro_finished_total`, `pomodoro_focus_ms_total` — the last two count only stints that **counted**: at least `pomodoro.min_counted_ms` long and within that UTC day's `pomodoro.max_counted_per_day`, since a start/finish pair is two requests with nobody else in it, so `pomodoro_sessions` may legitimately run ahead of them), and seven more cover both sides of the school: `marks_given_total` (grades a teacher recorded, exam sittings and homework alike, once per pair — a regrade moves nothing, but deleting the grade gives it back, since the grader who deletes is the grader who was credited and grade → un-grade → regrade would otherwise count the same work twice), `lessons_held_total` (a session teacher's lessons, credited by the **first roll call taken at or after the lesson's own `starts_at`**, so neither a lesson scheduled and cancelled nor two hundred marked before they begin count for anything), `pool_approved_total` and `pool_published_total` (the approver's and the asker's halves of one pending→approved transition — a teacher approving their own question publishes it but earns neither, since a counter moves only when one person's work was judged by somebody else), `lessons_attended_total` (a **student** marked `present` or `late` at lesson roll call, moved back down by a correction to any other status and untouched by daily/event attendance), `high_mark_total` (the student's exam marks at or above `badges.high_mark_min`, once per sitting, given back when the mark is deleted on the same terms as the grader's — but unlike the grader's, a **regrade does move it** whenever the correction crosses the cut in either direction, since it counts marks *stored* above the line rather than first gradings, which is the only way the credit and the refund read the same value; homework marks are optional and often status-only, so they never count), and `study_streak_total` — the **longest** run of consecutive days the student finished a pomodoro stint that counted, not a sum, spelled `_total` like every other key so a client joins it to the catalog's `stat` name mechanically. Days there end at **midnight UTC**, like every other day calculation here, and the run is read as a high-water mark, so breaking it never takes a badge back. **Badges are auto-earned only** — no route awards or revokes one; a badge appears when a stored counter crosses a hardcoded threshold and is **permanent**, surviving that counter falling back (withdrawing a submission decrements the counter, never the badge), with `earned_at` pinned at the first crossing and the list ordered oldest first. Each entry is `{id, earned_at}`: labels and icons belong to the client, keyed by id, exactly as for `roles` and course `kinds`. The catalog behind the ids is `badges.catalog[]` at `GET /limits` (`{id, stat, threshold}`, 34 badges over twelve counters, `stat` being the API's name for the counter rather than the column it is stored in) alongside `badges.high_mark_min`, the exam mark the `high_mark` ladder counts from (the id alone does not say it), both compiled in, so a threshold moves only with a deploy. Contact details (`email`, `phone`, `birth_date`) are **not** part of it and keep exactly the gate they have today. Any authenticated account reads any profile — except a `parent`, who reads their own and their linked students' only, with the link *and* the target's live role re-read per call, so an unlinked or promoted-out student stops being readable at once. The courses block follows the owner's **live** role: teacher+ lists what they teach, everyone else what they are enrolled in, so a demoted ex-teacher lists enrollments and not what they created — and it is then cut to the courses the *reader* may already read at `GET /courses/{id}` (a title a reader is `403` on there must not arrive here instead), so a stranger sees an empty block while the owner and manager+ see it whole; the truncation runs after that filter. The class block is cut the same way, against the bar `GET /classes/user/{id}` holds: teacher+, a parent linked to that student, or the owner reading their own profile — every other reader (a fellow student included) gets an empty `classes` array rather than a `403`, since a class name and grade are exactly what the `/classes` routes withhold below teacher+. **Every** number in `stats` stays the owner's true total either way, not just those two — `pomodoro_focus_ms`/`pomodoro_focus_ms_total` are the same figure `GET /pomodoro/{id}` serves behind its observer gate, and `lessons_attended_total`, `homework_submitted_total`, `homework_on_time_total`, `exam_sat_total` and `high_mark_total` are magnitudes of the mark and attendance data behind that same gate (for a reader who is exactly a `teacher`, wider than the `can_manage_course`-narrowed `/marks/user/{id}` and `/attendance/user/{id}` reports). That is deliberate: they are motivational counters, a magnitude names no course, class, lesson or exam, and a per-reader figure would make one profile read differently to different people. `display_name` (≤ 50) and `bio` (≤ 500) ride the same `PATCH /users/me` / `PATCH /users/{id}/profile` pair as the rest of the personal info, `\"\"` clearing either. One avatar per account: `POST /users/me/avatar` (multipart, raster types only — no SVG, whose script can run when the bytes render inline school-wide — at most the school's `max_file_bytes` rather than a knob of its own; replacing one drops the previous picture), the bytes at `GET /users/{id}/avatar` — or `GET /users/me/avatar` for the caller's own, so a client never needs to know its own id — (same reach as the profile, served `nosniff` and `private, no-store`), removed by the owner at `DELETE /users/me/avatar` or, as moderation, by an admin at `DELETE /users/{id}/avatar`"),63 (name = "users", description = "User info: self-service profile and UI preferences (theme `light`/`dark`, language `tr`/`en`, accent color `palette_color` as `#rrggbb` — returned on every user response, `null` until chosen), name search for the pickers (any authenticated user, optionally role-filtered; a student or parent sees only the staff they may message), plus account creation (admin only: `POST /users` mints a school account outright, born with the role the caller names — `student` by default), listing, lookup, and role/profile/preferences administration (admin only). An admin never changes their own role, and the school's **last** admin cannot be demoted at all (`409`) — role management can no longer lock everyone out, not even when two admins…, accent color `palette_color` as `#rrggbb` — returned on every user response, `null` until chosen), name search for the pickers (any authenticated user, optionally role-filtered; a student or parent sees only the staff they may message), plus account creation (admin only: `POST /users` mints a school account outright, born with the role the caller names — `student` by default), listing, lookup, and role/profile/preferences administration (admin only). An admin never changes their own role, and the school's **last** admin cannot be demoted at all (`409`) — role management can no longer lock everyone out, not even when two admins demote each other at the same instant. Also the parent↔student ties: admins link students to a `parent` account under `/users/{id}/students` (link, list, unlink — a role change on either side drops its ties in the *same transaction* as the role write, so a failure mid-way leaves the old role with all its ties intact rather than a half-applied change), and a parent lists their own students at `/users/me/students`; every one of those lists is filtered to accounts that hold the `student` role **right now**, so a tie whose student was promoted out names nobody, exactly as it grants nothing; the tie grants the parent read access to those students' mark, attendance, pomodoro, and homework reports and nothing else. Every account also has a **public profile** (`GET /users/me/profile`, `GET /users/{id}/profile`): username, `display_name` (the self-chosen one, else the `name surname` join, else `null` — the very same three steps every embedded person ref resolves, so a chosen name shows school-wide; it never replaces `name`/`surname`, which stay the school-office record, and it deliberately stays out of the user search fold), role, `bio`, avatar metadata, a narrowed class/course block (id/name/grade and id/title/kind only — never a class's creator or homeroom teacher — capped at `max_profile_classes` / `max_profile_courses`, since `/classes/me` and `/courses/me` are the full paged lists), a sixteen-key `stats` block, and the badges those stats have earned. Four stats are computed at read (finished pomodoro stints and their focused milliseconds, plus the full course and class counts) and twelve are stored lifetime tallies maintained at write time, so a tally can outlive the rows behind it — a deleted exam does not un-sit it; all sixteen read `0`, never `null`. Five are the student's own work (`homework_submitted_total`, `homework_on_time_total`, `exam_sat_total` — **exams sat**, not sittings: a retake of an exam already counted moves nothing, since an `open` exam with unlimited attempts is a start/finish loop a student runs with no teacher in it —, `pomodoro_finished_total`, `pomodoro_focus_ms_total` — the last two count only stints that **counted**: at least `pomodoro.min_counted_ms` long and within that UTC day's `pomodoro.max_counted_per_day`, since a start/finish pair is two requests with nobody else in it, so `pomodoro_sessions` may legitimately run ahead of them), and seven more cover both sides of the school: `marks_given_total` (grades a teacher recorded, exam sittings and homework alike, once per pair — a regrade moves nothing, but deleting the grade gives it back, since the grader who deletes is the grader who was credited and grade → un-grade → regrade would otherwise count the same work twice), `lessons_held_total` (a session teacher's lessons, credited by the **first roll call taken at or after the lesson's own `starts_at`**, so neither a lesson scheduled and cancelled nor two hundred marked before they begin count for anything), `pool_approved_total` and `pool_published_total` (the approver's and the asker's halves of one pending→approved transition — a teacher approving their own question publishes it but earns neither, since a counter moves only when one person's work was judged by somebody else), `lessons_attended_total` (a **student** marked `present` or `late` at lesson roll call, moved back down by a correction to any other status and untouched by daily/event attendance), `high_mark_total` (the student's exam marks at or above `badges.high_mark_min`, once per sitting, given back when the mark is deleted on the same terms as the grader's — but unlike the grader's, a **regrade does move it** whenever the correction crosses the cut in either direction, since it counts marks *stored* above the line rather than first gradings, which is the only way the credit and the refund read the same value; homework marks are optional and often status-only, so they never count), and `study_streak_total` — the **longest** run of consecutive days the student finished a pomodoro stint that counted, not a sum, spelled `_total` like every other key so a client joins it to the catalog's `stat` name mechanically. Days there end at **midnight UTC**, like every other day calculation here, and the run is read as a high-water mark, so breaking it never takes a badge back. **Badges are auto-earned only** — no route awards or revokes one; a badge appears when a stored counter crosses a hardcoded threshold and is **permanent**, surviving that counter falling back (withdrawing a submission decrements the counter, never the badge), with `earned_at` pinned at the first crossing and the list ordered oldest first. Each entry is `{id, earned_at}`: labels and icons belong to the client, keyed by id, exactly as for `roles` and course `kinds`. The catalog behind the ids is `badges.catalog[]` at `GET /limits` (`{id, stat, threshold}`, 34 badges over twelve counters, `stat` being the API's name for the counter rather than the column it is stored in) alongside `badges.high_mark_min`, the exam mark the `high_mark` ladder counts from (the id alone does not say it), both compiled in, so a threshold moves only with a deploy. Contact details (`email`, `phone`, `birth_date`) are **not** part of it and keep exactly the gate they have today. Any authenticated account reads any profile — except a `parent`, who reads their own and their linked students' only, with the link *and* the target's live role re-read per call, so an unlinked or promoted-out student stops being readable at once. The courses block follows the owner's **live** role: teacher+ lists what they teach, everyone else what they are enrolled in, so a demoted ex-teacher lists enrollments and not what they created — and it is then cut to the courses the *reader* may already read at `GET /courses/{id}` (a title a reader is `403` on there must not arrive here instead), so a stranger sees an empty block while the owner and manager+ see it whole; the truncation runs after that filter. The class block is cut the same way, against the bar `GET /classes/user/{id}` holds: teacher+, a parent linked to that student, or the owner reading their own profile — every other reader (a fellow student included) gets an empty `classes` array rather than a `403`, since a class name and grade are exactly what the `/classes` routes withhold below teacher+. **Every** number in `stats` stays the owner's true total either way, not just those two — `pomodoro_focus_ms`/`pomodoro_focus_ms_total` are the same figure `GET /pomodoro/{id}` serves behind its observer gate, and `lessons_attended_total`, `homework_submitted_total`, `homework_on_time_total`, `exam_sat_total` and `high_mark_total` are magnitudes of the mark and attendance data behind that same gate (for a reader who is exactly a `teacher`, wider than the `can_manage_course`-narrowed `/marks/user/{id}` and `/attendance/user/{id}` reports). That is deliberate: they are motivational counters, a magnitude names no course, class, lesson or exam, and a per-reader figure would make one profile read differently to different people. `display_name` (≤ 50) and `bio` (≤ 500) ride the same `PATCH /users/me` / `PATCH /users/{id}/profile` pair as the rest of the personal info, `\"\"` clearing either. One avatar per account: `POST /users/me/avatar` (multipart, raster types only — no SVG, whose script can run when the bytes render inline school-wide — at most the school's `max_file_bytes` rather than a knob of its own; replacing one drops the previous picture), the bytes at `GET /users/{id}/avatar` — or `GET /users/me/avatar` for the caller's own, so a client never needs to know its own id — (same reach as the profile, served `nosniff` and `private, no-store`), removed by the owner at `DELETE /users/me/avatar` or, as moderation, by an admin at `DELETE /users/{id}/avatar`"),
64 (name = "notes", description = "Per-user notes CRUD, plus file attachments per note (multipart upload, download, delete — at most 10 per note, each at most the school's settings-configured `max_file_bytes`). Every authenticated role keeps notes, `parent` included: a note is private own-scoped data with no other reader, and the routes carry **no role bar at all** — ownership is the whole authorization, so nobody but the owner ever reaches a note or its files (a stranger's id is a `404`, never a `403`). That is deliberate and it is the fix for a real defect: while these routes required `student`, a demotion to `parent` locked the owner out of their own notes for good, and since nothing else in the crate reads a note and no route cascades one, the rows and their on-disk blobs became unreachable and undeletable by everybody. Own-scoped personal data is not confiscated by a role change"),64 (name = "notes", description = "Per-user notes CRUD, plus file attachments per note (multipart upload, download, delete — at most 10 per note, each at most the school's settings-configured `max_file_bytes`). Every authenticated role keeps notes, `parent` included: a note is private own-scoped data with no other reader, and the routes carry **no role bar at all** — ownership is the whole authorization, so nobody but the owner ever reaches a note or its files (a stranger's id is a `404`, never a `403`). That is deliberate and it is the fix for a real defect: while these routes required `student`, a demotion to `parent` locked the owner out of their own notes for good, and since nothing else in the crate reads a note and no route cascades one, the rows and their on-disk blobs became unreachable and undeletable by everybody. Own-scoped personal data is not confiscated by a role change"),
65 (name = "messages", description = "One-to-one mail-style messages, upward only below staff: a student or parent writes to a teacher, manager or admin (parents included — messaging is the one place a parent writes) and never to another student or parent (`403`), while staff write to anyone, each optionally tagged with a free-text `label` badge. Each party owns their copy independently: the recipient's moves through `inbox`/`archive`/`trash` with a read flag (visible to the sender as a read receipt), the sender's through `sent`/`archive`/`trash`. Filing a copy away records the folder it left as its `previous_folder`, so restoring it puts it back where it came from (a trashed archive copy returns to the archive, not the inbox). `GET /messages?folder=` lists one folder (`&read=false` narrows to unread — with `limit=1`, `total` is the unread badge); permanent deletion (`DELETE`) works only from the trash and removes the row once both sides have deleted"),65 (name = "messages", description = "One-to-one mail-style messages, upward only below staff: a student or parent writes to a teacher, manager or admin (parents included — messaging is the one place a parent writes) and never to another student or parent (`403`), while staff write to anyone, each optionally tagged with a free-text `label` badge. Each party owns their copy independently: the recipient's moves through `inbox`/`archive`/`trash` with a read flag (visible to the sender as a read receipt), the sender's through `sent`/`archive`/`trash`. Filing a copy away records the folder it left as its `previous_folder`, so restoring it puts it back where it came from (a trashed archive copy returns to the archive, not the inbox). `GET /messages?folder=` lists one folder (`&read=false` narrows to unread — with `limit=1`, `total` is the unread badge); permanent deletion (`DELETE`) works only from the trash and removes the row once both sides have deleted"),
src/service/course_note_file.rsmodified+0 -9
@@ -32,15 +32,6 @@ pub async fn read_for(
32 course_note_file::read_for(db, id, note).await32 course_note_file::read_for(db, id, note).await
33 }33 }
34 34
35-/// The note's newest `application/pdf` attachment — what the podcast submit
36-/// door narrates, resolved before any job row is written.
37-pub async fn newest_pdf(
38- db: &Database,
39- note: &CourseNoteId,
40-) -> Result<Option<CourseNoteFile>, AppError> {
41- course_note_file::newest_pdf(db, note).await
42-}
43-
44 pub async fn list_for(35 pub async fn list_for(
45 db: &Database,36 db: &Database,
46 note: &CourseNoteId,37 note: &CourseNoteId,
src/service/podcast_job.rsmodified+24 -0
@@ -9,6 +9,8 @@
9 //! enum), the retention window, and the "done means audio" rule — in that9 //! enum), the retention window, and the "done means audio" rule — in that
10 //! order — before a single statement runs.10 //! order — before a single statement runs.
11 11
12+use crate::ai::podcast::PodcastSourceStatus;
13+use crate::constant::MAX_COURSE_NOTE_FILES;
12 use crate::database::Database;14 use crate::database::Database;
13 use crate::db::podcast_job;15 use crate::db::podcast_job;
14 use crate::domain::course_note::CourseNoteId;16 use crate::domain::course_note::CourseNoteId;
@@ -101,6 +103,9 @@ pub struct ReportInput<'a> {
101 pub progress: f64,103 pub progress: f64,
102 pub error_code: Option<&'a str>,104 pub error_code: Option<&'a str>,
103 pub transcript: Option<&'a str>,105 pub transcript: Option<&'a str>,
106+ /// The per-source outcomes, as the report carried them. `None` from a
107+ /// service that has not learned the field yet.
108+ pub sources: Option<&'a [PodcastSourceStatus]>,
104 }109 }
105 110
106 /// Mint and store one freshly submitted job. The id is the backend's (the111 /// Mint and store one freshly submitted job. The id is the backend's (the
@@ -120,6 +125,7 @@ pub async fn create(
120 source_id: source_id.to_string(),125 source_id: source_id.to_string(),
121 format: format.map(str::to_string),126 format: format.map(str::to_string),
122 transcript: None,127 transcript: None,
128+ sources: None,
123 state: PodcastJobState::Queued,129 state: PodcastJobState::Queued,
124 stage: String::new(),130 stage: String::new(),
125 progress: 0.0,131 progress: 0.0,
@@ -215,6 +221,15 @@ pub async fn report(
215 "transcript is longer than {MAX_TRANSCRIPT_LEN} characters"221 "transcript is longer than {MAX_TRANSCRIPT_LEN} characters"
216 )));222 )));
217 }223 }
224+ // A note cannot hold more than [`MAX_COURSE_NOTE_FILES`] attachments, so
225+ // a longer source list is not a report this backend could have asked for.
226+ if let Some(sources) = input.sources
227+ && sources.len() > MAX_COURSE_NOTE_FILES
228+ {
229+ return Err(PodcastRefusal::InvalidPayload(format!(
230+ "sources carries more than the {MAX_COURSE_NOTE_FILES} attachments a note can hold"
231+ )));
232+ }
218 233
219 let Some(row) = podcast_job::read(db, &id).await? else {234 let Some(row) = podcast_job::read(db, &id).await? else {
220 return Err(PodcastRefusal::UnknownJob);235 return Err(PodcastRefusal::UnknownJob);
@@ -253,6 +268,11 @@ pub async fn report(
253 // that empty string and then ignore the done report's text, so a blank268 // that empty string and then ignore the done report's text, so a blank
254 // or all-whitespace transcript is absent, not a value.269 // or all-whitespace transcript is absent, not a value.
255 let transcript = input.transcript.filter(|text| !text.trim().is_empty());270 let transcript = input.transcript.filter(|text| !text.trim().is_empty());
271+ // Stored verbatim, like the transcript: a service-owned shape this side
272+ // neither interprets nor rewrites.
273+ let sources = input
274+ .sources
275+ .map(|sources| serde_json::to_value(sources).expect("a source list is always encodable"));
256 276
257 match podcast_job::report(277 match podcast_job::report(
258 db,278 db,
@@ -264,6 +284,7 @@ pub async fn report(
264 input.error_code,284 input.error_code,
265 input.format,285 input.format,
266 transcript,286 transcript,
287+ sources.as_ref(),
267 )288 )
268 .await?289 .await?
269 {290 {
@@ -387,6 +408,7 @@ mod tests {
387 progress: 0.0,408 progress: 0.0,
388 error_code: None,409 error_code: None,
389 transcript: Some(&huge),410 transcript: Some(&huge),
411+ sources: None,
390 };412 };
391 let err = report(&db, &input).await.expect_err("over the cap");413 let err = report(&db, &input).await.expect_err("over the cap");
392 assert_eq!(err.code(), "invalid_payload");414 assert_eq!(err.code(), "invalid_payload");
@@ -423,6 +445,7 @@ mod tests {
423 progress: 0.2,445 progress: 0.2,
424 error_code: None,446 error_code: None,
425 transcript: Some(""),447 transcript: Some(""),
448+ sources: None,
426 };449 };
427 let running = report(&db, &progress).await.expect("progress report");450 let running = report(&db, &progress).await.expect("progress report");
428 assert_eq!(running.get_state(), PodcastJobState::Running);451 assert_eq!(running.get_state(), PodcastJobState::Running);
@@ -450,6 +473,7 @@ mod tests {
450 progress: 1.0,473 progress: 1.0,
451 error_code: None,474 error_code: None,
452 transcript: Some("bolum bir\n\nbolum iki"),475 transcript: Some("bolum bir\n\nbolum iki"),
476+ sources: None,
453 };477 };
454 let finished = report(&db, &done).await.expect("done report");478 let finished = report(&db, &done).await.expect("done report");
455 assert_eq!(finished.get_transcript(), Some("bolum bir\n\nbolum iki"));479 assert_eq!(finished.get_transcript(), Some("bolum bir\n\nbolum iki"));
src/web/podcast.rsmodified+84 -33
@@ -36,13 +36,13 @@
36 //! window (see [`PodcastJob::projected`]): the projection writes nothing, and36 //! window (see [`PodcastJob::projected`]): the projection writes nothing, and
37 //! the service's next report overwrites it.37 //! the service's next report overwrites it.
38 //!38 //!
39-//! The **source** is resolved here, not by the service: `source_id` names a39+//! The **sources** are resolved here, not by the service: `source_id` names a
40 //! course note in the caller's own school, and the submit door hands the40 //! course note in the caller's own school, and the submit door hands the
41-//! service the blob key of that note's newest `application/pdf` attachment41+//! service that note's attachments — every one whose blob is on this host, in
42-//! (`source_key`) — the file it reads under its shared media root. A note with42+//! upload order — as `sources` (`source_key` rides on as the first source's
43-//! no such attachment, or one whose blob is missing from this host, is refused43+//! key, one-release compat). A note with no attachments, or one whose blobs
44-//! `409 source_missing` before the row is written, so a job that could only44+//! are all missing from this host, is refused `409 source_missing` before the
45-//! fail is never queued.45+//! row is written, so a job that could only fail is never queued.
46 46
47 use axum::Json;47 use axum::Json;
48 use axum::body::Body;48 use axum::body::Body;
@@ -58,7 +58,7 @@ use utoipa_axum::router::OpenApiRouter;
58 use utoipa_axum::routes;58 use utoipa_axum::routes;
59 59
60 use crate::ai::AiBridge;60 use crate::ai::AiBridge;
61-use crate::ai::podcast::{self, PodcastCancelPayload, PodcastSubmitPayload};61+use crate::ai::podcast::{self, PodcastCancelPayload, PodcastSource, PodcastSubmitPayload};
62 use crate::constant::{62 use crate::constant::{
63 AI_PODCAST_CANCEL_CAPABILITY, AI_PODCAST_SUBMIT_CAPABILITY, PODCAST_INTERRUPTED_CODE,63 AI_PODCAST_CANCEL_CAPABILITY, AI_PODCAST_SUBMIT_CAPABILITY, PODCAST_INTERRUPTED_CODE,
64 };64 };
@@ -124,6 +124,20 @@ struct JobStatus {
124 error_code: Option<String>,124 error_code: Option<String>,
125 }125 }
126 126
127+/// One attachment's outcome in the finished episode, as the service reported
128+/// it.
129+#[derive(Serialize, Deserialize, ToSchema)]
130+struct JobSourceStatus {
131+ /// The attachment's blob key — the id `GET /course-notes/{id}/files`
132+ /// lists.
133+ key: String,
134+ /// The file name the upload declared.
135+ name: String,
136+ /// `ok`, or `skipped:<code>` when the source failed extraction and was
137+ /// left out of the episode.
138+ status: String,
139+}
140+
127 /// A finished job's artifacts.141 /// A finished job's artifacts.
128 #[derive(Serialize, ToSchema)]142 #[derive(Serialize, ToSchema)]
129 struct JobArtifacts {143 struct JobArtifacts {
@@ -140,6 +154,10 @@ struct JobArtifacts {
140 /// finished before the column existed, and any later job whose done report154 /// finished before the column existed, and any later job whose done report
141 /// omitted the field.155 /// omitted the field.
142 transcript: Option<String>,156 transcript: Option<String>,
157+ /// Per-source outcomes for a multi-document episode, exactly as the
158+ /// service reported them. `null` for episodes finished before the field
159+ /// existed, or by a service that has not learned it.
160+ sources: Option<Vec<JobSourceStatus>>,
143 }161 }
144 162
145 /// The verdict on a cancel.163 /// The verdict on a cancel.
@@ -162,11 +180,12 @@ struct CancelVerdict {
162 /// far as a row either (see below).180 /// far as a row either (see below).
163 ///181 ///
164 /// `source_id` names a course note in this school, and the door resolves it182 /// `source_id` names a course note in this school, and the door resolves it
165-/// first: what the service narrates is that note's **newest183+/// first: what the service narrates is that note's **attachments** — every
166-/// `application/pdf` attachment**, whose blob key rides the dispatch as184+/// one whose blob is on this host, dispatched as `sources` in upload order
167-/// `source_key`. A note with no PDF — or one whose blob is missing from this185+/// (a missing blob is skipped with a log line, not a refusal). A note with
168-/// host — is a `409 source_missing` before anything is written, so a job that186+/// no attachments — or none whose blob is on this host — is a `409
169-/// is guaranteed to fail is never queued for the service to discover later.187+/// source_missing` before anything is written, so a job that is guaranteed
188+/// to fail is never queued for the service to discover later.
170 #[utoipa::path(189 #[utoipa::path(
171 post,190 post,
172 path = "/jobs",191 path = "/jobs",
@@ -177,7 +196,7 @@ struct CancelVerdict {
177 (status = 202, description = "The job is queued; `job_id` names it from here on", body = JobReceipt),196 (status = 202, description = "The job is queued; `job_id` names it from here on", body = JobReceipt),
178 (status = 400, description = "Empty `source_id`, or a `format` the service does not serve", body = ErrorResponse),197 (status = 400, description = "Empty `source_id`, or a `format` the service does not serve", body = ErrorResponse),
179 (status = 401, description = "Not authenticated", body = ErrorResponse),198 (status = 401, description = "Not authenticated", body = ErrorResponse),
180- (status = 409, description = "The note has no `application/pdf` attachment, or that attachment's blob is missing from this host (`source_missing`)", body = ErrorResponse),199+ (status = 409, description = "The note has no attachments at all, or none of its attachment blobs are present on this host (`source_missing`)", body = ErrorResponse),
181 (status = 422, description = "The body does not fit this request: a field has the wrong type, or a required field is missing", body = ErrorResponse),200 (status = 422, description = "The body does not fit this request: a field has the wrong type, or a required field is missing", body = ErrorResponse),
182 (status = 503, description = "No AI service offers `podcast.submit` (or the service is at capacity)", body = ErrorResponse),201 (status = 503, description = "No AI service offers `podcast.submit` (or the service is at capacity)", body = ErrorResponse),
183 ),202 ),
@@ -203,24 +222,51 @@ async fn submit(
203 }));222 }));
204 }223 }
205 224
206- // The source is resolved here, before anything is written: what the225+ // The sources are resolved here, before anything is written: what the
207- // service narrates is the note's own newest PDF, and the key of those226+ // service narrates is the note's own attachments — every one whose blob
208- // bytes is what rides the dispatch. Both shapes of "no source" are refused227+ // is on this host, in upload order (id ASC) — and those keys are what
209- // now — queueing the job would only buy a failure in the service's own228+ // ride the dispatch. A blob that is gone is skipped with a log line, not
210- // `kaynak` stage, with the caller already holding a job id.229+ // a refusal: the episode just narrates fewer documents. Both shapes of
211- let file = note_files::newest_pdf(&st.db, &CourseNoteId::from_key(source_id))230+ // "no source at all" are refused now — queueing the job would only buy a
212- .await?231+ // failure in the service's own `kaynak` stage, with the caller already
213- .ok_or_else(|| source_missing("this course note has no PDF attachment to narrate"))?;232+ // holding a job id.
214- let source_key = file.get_id().key();233+ let (mut files, _) =
215- match tokio::fs::try_exists(crate::web::blob_path(&st.files_path, &source_key)).await {234+ note_files::list_for(&st.db, &CourseNoteId::from_key(source_id), None, 0).await?;
216- Ok(true) => {}235+ let attachments = files.len();
217- Ok(false) => return Err(source_missing("this note's PDF is missing on this host")),236+ // `list_for` is newest first; the payload carries upload order (id ASC),
218- Err(err) => {237+ // the order the service narrates in.
219- return Err(AppError::Internal(format!(238+ files.sort_by_key(|file| file.get_id().uuid());
220- "could not stat the note's PDF blob: {err}"239+ let mut sources = Vec::with_capacity(files.len());
221- )));240+ for file in files {
241+ let key = file.get_id().key();
242+ match tokio::fs::try_exists(crate::web::blob_path(&st.files_path, &key)).await {
243+ Ok(true) => sources.push(PodcastSource {
244+ key,
245+ name: file.get_name().as_str().to_string(),
246+ content_type: file.get_content_type().as_str().to_string(),
247+ }),
248+ // The row is intact, the bytes are not: leave this one document
249+ // out rather than refusing a note whose other attachments are
250+ // fine.
251+ Ok(false) => tracing::warn!(
252+ key = %key,
253+ "podcast source's blob is missing from this host; skipping it"
254+ ),
255+ Err(err) => {
256+ return Err(AppError::Internal(format!(
257+ "could not stat a note attachment blob: {err}"
258+ )));
259+ }
222 }260 }
223 }261 }
262+ if sources.is_empty() {
263+ return Err(source_missing(if attachments == 0 {
264+ "this course note has no attachments to narrate"
265+ } else {
266+ "none of this note's attachments are on this host"
267+ }));
268+ }
269+ let source_key = sources[0].key.clone();
224 270
225 let job = jobs::create(&st.db, user.get_id(), source_id, req.format.as_deref()).await?;271 let job = jobs::create(&st.db, user.get_id(), source_id, req.format.as_deref()).await?;
226 let job_id = job.get_id().key();272 let job_id = job.get_id().key();
@@ -228,6 +274,7 @@ async fn submit(
228 job_id: job_id.clone(),274 job_id: job_id.clone(),
229 source_id: source_id.to_string(),275 source_id: source_id.to_string(),
230 source_key,276 source_key,
277+ sources,
231 format: req.format.clone(),278 format: req.format.clone(),
232 user_id: user.get_id().key(),279 user_id: user.get_id().key(),
233 };280 };
@@ -472,6 +519,10 @@ async fn result(
472 duration_secs: job.get_duration_secs(),519 duration_secs: job.get_duration_secs(),
473 format: job.get_format().map(str::to_string),520 format: job.get_format().map(str::to_string),
474 transcript: job.get_transcript().map(str::to_string),521 transcript: job.get_transcript().map(str::to_string),
522+ sources: job.get_sources().map(|sources| {
523+ serde_json::from_value(sources.clone())
524+ .expect("the report decode guarantees the stored sources shape")
525+ }),
475 })526 })
476 .into_response())527 .into_response())
477 }528 }
@@ -665,10 +716,10 @@ fn worker_for(st: &AppState, capability: &str) -> Result<AiBridge, NoWorker> {
665 }716 }
666 717
667 /// The submit door's own refusal: the note behind `source_id` cannot be718 /// The submit door's own refusal: the note behind `source_id` cannot be
668-/// narrated — it has no PDF attachment, or the bytes the row names are gone719+/// narrated — it has no attachments, or the bytes every one of them names are
669-/// from this host. One code (`source_missing`) for both, a message that says720+/// gone from this host. One code (`source_missing`) for both, a message that
670-/// which side is missing, and a `409` either way, so a client branches on the721+/// says which side is missing, and a `409` either way, so a client branches on
671-/// code instead of parsing the sentence.722+/// the code instead of parsing the sentence.
672 fn source_missing(message: &str) -> AppError {723 fn source_missing(message: &str) -> AppError {
673 AppError::ConflictCoded {724 AppError::ConflictCoded {
674 code: "source_missing",725 code: "source_missing",
tests/podcast.rsmodified+127 -30
@@ -294,7 +294,7 @@ async fn submit(app: &Router, cookie: &str, body: Value) -> common::Res {
294 294
295 /// Submit one job for `source` with the standard format (asserting the `202`)295 /// Submit one job for `source` with the standard format (asserting the `202`)
296 /// and hand back the backend-minted id every other door names. `source` is the296 /// and hand back the backend-minted id every other door names. `source` is the
297-/// note id: the door resolves the note's own newest PDF before it writes297+/// note id: the door resolves the note's attachments before it writes
298 /// anything, so every submitting test needs a real note behind its source.298 /// anything, so every submitting test needs a real note behind its source.
299 async fn submit_job(app: &Router, cookie: &str, source: &str) -> String {299 async fn submit_job(app: &Router, cookie: &str, source: &str) -> String {
300 let res = submit(300 let res = submit(
@@ -843,6 +843,57 @@ async fn a_finished_job_serves_the_uploaded_bytes() {
843 );843 );
844 }844 }
845 845
846+/// The per-source outcomes ride the done report and come back on the result
847+/// door, verbatim — the frontend can show which documents made it into the
848+/// episode without a second contract. A job whose service never reported them
849+/// keeps the field absent.
850+#[tokio::test]
851+async fn the_result_door_exposes_the_reported_sources() {
852+ let (service, app, cookie, db) = podcast_app().await;
853+ let user = common::me_id(&app, &cookie).await;
854+ let (note, _key) = note_with_pdf(&app, &db).await;
855+ let job_id = submit_job(&app, &cookie, &note).await;
856+
857+ assert_report_stored(
858+ &capability_call(
859+ &service.conn,
860+ report_frame(&job_id, &note, &user, "running", "tts", 0.25),
861+ )
862+ .await,
863+ &job_id,
864+ );
865+
866+ let bytes = episode_bytes();
867+ let answer = blob_upload(
868+ &service.conn,
869+ upload_frame(&job_id, AUDIO_NAME, AUDIO_TYPE, bytes.len()),
870+ &bytes,
871+ )
872+ .await;
873+ assert_eq!(answer["status"], "ok", "{answer}");
874+
875+ let mut done = report_frame(&job_id, &note, &user, "done", "", 1.0);
876+ done["payload"]["transcript"] = json!("bolum bir\n\nbolum iki");
877+ done["payload"]["sources"] = json!([
878+ { "key": "019732e3-7b00-7000-8000-00000000beef", "name": "tanim.pdf", "status": "ok" },
879+ { "key": "019732e3-7b00-7000-8000-00000000feed", "name": "ozet.txt", "status": "skipped:no_text_layer" },
880+ ]);
881+ assert_report_stored(&capability_call(&service.conn, done).await, &job_id);
882+
883+ let res = result_of(&app, &cookie, &job_id).await;
884+ assert_eq!(res.status, StatusCode::OK, "{}", res.body);
885+ assert_eq!(res.body["sources"][0]["key"], "019732e3-7b00-7000-8000-00000000beef");
886+ assert_eq!(res.body["sources"][0]["name"], "tanim.pdf");
887+ assert_eq!(res.body["sources"][0]["status"], "ok");
888+ assert_eq!(res.body["sources"][1]["key"], "019732e3-7b00-7000-8000-00000000feed");
889+ assert_eq!(res.body["sources"][1]["name"], "ozet.txt");
890+ assert_eq!(res.body["sources"][1]["status"], "skipped:no_text_layer");
891+
892+ // The audio-missing refusal earlier in the file proves a job cannot go
893+ // `done` without its upload; a report that never learns `sources` leaves
894+ // the field absent rather than an empty list.
895+}
896+
846 /// Cancelling a live job reaches the worker that owns the queue and stamps the897 /// Cancelling a live job reaches the worker that owns the queue and stamps the
847 /// verdict on the row — the row then records that the job stopped, so a poll898 /// verdict on the row — the row then records that the job stopped, so a poll
848 /// after the service is gone still reads the truth.899 /// after the service is gone still reads the truth.
@@ -1593,13 +1644,14 @@ async fn the_old_path_audio_door_is_gone() {
1593 assert_eq!(res.status, StatusCode::NOT_FOUND, "{}", res.body);1644 assert_eq!(res.status, StatusCode::NOT_FOUND, "{}", res.body);
1594 }1645 }
1595 1646
1596-/// The submit door resolves the source itself: a note with no PDF attachment1647+/// The submit door resolves the sources itself: a note with no attachments at
1597-/// is refused `409 source_missing` **before** anything is written. Pre-fix the1648+/// all is refused `409 source_missing` **before** anything is written.
1598-/// door accepted the job and it died later in the service's `kaynak` stage —1649+/// Pre-fix the door accepted the job and it died later in the service's
1599-/// a queued job guaranteed to fail, which is what this refusal exists to1650+/// `kaynak` stage — a queued job guaranteed to fail, which is what this
1600-/// prevent. A newer non-PDF attachment changes nothing: it is not a source.1651+/// refusal exists to prevent. A single attachment — PDF or not — is a valid
1652+/// source now, so the refusal is exactly about emptiness.
1601 #[tokio::test]1653 #[tokio::test]
1602-async fn a_note_with_no_pdf_is_refused_at_the_door() {1654+async fn a_note_with_no_attachments_is_refused_at_the_door() {
1603 let (service, app, cookie, db) = podcast_app().await;1655 let (service, app, cookie, db) = podcast_app().await;
1604 let user = common::me_id(&app, &cookie).await;1656 let user = common::me_id(&app, &cookie).await;
1605 let teacher = common::login_as(&app, &db, "hoca", "teacher").await;1657 let teacher = common::login_as(&app, &db, "hoca", "teacher").await;
@@ -1610,12 +1662,6 @@ async fn a_note_with_no_pdf_is_refused_at_the_door() {
1610 assert_eq!(res.status, StatusCode::CONFLICT, "{}", res.body);1662 assert_eq!(res.status, StatusCode::CONFLICT, "{}", res.body);
1611 assert_eq!(res.body["code"], "source_missing");1663 assert_eq!(res.body["code"], "source_missing");
1612 1664
1613- // A non-PDF attachment is newer than nothing, and is still not a source.
1614- let _txt = upload_attachment(&app, &teacher, &note, "ozet.txt", "text/plain").await;
1615- let res = submit(&app, &cookie, json!({ "source_id": &note })).await;
1616- assert_eq!(res.status, StatusCode::CONFLICT, "{}", res.body);
1617- assert_eq!(res.body["code"], "source_missing");
1618-
1619 assert!(1665 assert!(
1620 service.seen().is_empty(),1666 service.seen().is_empty(),
1621 "the refusal never reaches a worker: {:?}",1667 "the refusal never reaches a worker: {:?}",
@@ -1624,12 +1670,12 @@ async fn a_note_with_no_pdf_is_refused_at_the_door() {
1624 assert_eq!(rows_for(&db, &user).await, 0, "and no row is written");1670 assert_eq!(rows_for(&db, &user).await, 0, "and no row is written");
1625 }1671 }
1626 1672
1627-/// A note whose PDF is on record but whose blob is gone from this host is1673+/// A note whose attachment blobs are **all** gone from this host is refused
1628-/// refused the same way: the row is intact and the bytes are not, and the1674+/// the same way as a note with no attachments: the rows are intact and the
1629-/// service could only fail on it — so the door answers now instead of queueing1675+/// bytes are not, and the service could only fail on them — so the door
1630-/// a job nobody can finish.1676+/// answers now instead of queueing a job nobody can finish.
1631 #[tokio::test]1677 #[tokio::test]
1632-async fn a_pdf_whose_blob_is_gone_is_refused_at_the_door() {1678+async fn a_note_whose_blobs_are_all_gone_is_refused_at_the_door() {
1633 let (service, app, cookie, db) = podcast_app().await;1679 let (service, app, cookie, db) = podcast_app().await;
1634 let user = common::me_id(&app, &cookie).await;1680 let user = common::me_id(&app, &cookie).await;
1635 let (note, key) = note_with_pdf(&app, &db).await;1681 let (note, key) = note_with_pdf(&app, &db).await;
@@ -1647,22 +1693,58 @@ async fn a_pdf_whose_blob_is_gone_is_refused_at_the_door() {
1647 assert_eq!(rows_for(&db, &user).await, 0, "and no row is written");1693 assert_eq!(rows_for(&db, &user).await, 0, "and no row is written");
1648 }1694 }
1649 1695
1650-/// Which attachment narrates: the note's **newest PDF**, not its newest file —1696+/// One blob missing among several is **not** a refusal: the door dispatches
1651-/// a text recap uploaded after the PDF is not a source, and a corrected PDF1697+/// the attachments that are present (the skip is a log line) — the episode
1652-/// uploaded after that is.1698+/// just narrates fewer documents. Only an empty result set refuses.
1699+#[tokio::test]
1700+async fn a_missing_blob_among_several_is_skipped_not_a_refusal() {
1701+ let (service, app, cookie, db) = podcast_app().await;
1702+ let teacher = common::login_as(&app, &db, "hoca", "teacher").await;
1703+ let course = common::create_course(&app, &teacher, "Matematik").await;
1704+ let note = create_note(&app, &teacher, &course).await;
1705+ let kept = upload_attachment(&app, &teacher, &note, "kaldi.pdf", "application/pdf").await;
1706+ let gone = upload_attachment(&app, &teacher, &note, "gitti.txt", "text/plain").await;
1707+ let path = common::blob_dir().join(&gone);
1708+ std::fs::remove_file(&path).expect("take the blob away");
1709+
1710+ let res = submit(&app, &cookie, json!({ "source_id": &note })).await;
1711+ assert_eq!(res.status, StatusCode::ACCEPTED, "{}", res.body);
1712+
1713+ let seen = service.seen();
1714+ assert_eq!(seen.len(), 1, "exactly one dispatch");
1715+ assert_eq!(seen[0].payload["source_key"], kept, "the first present blob");
1716+ let sources = seen[0].payload["sources"].as_array().expect("a source list");
1717+ assert_eq!(sources.len(), 1, "the missing blob is filtered at the door");
1718+ assert_eq!(sources[0]["key"], kept);
1719+ assert_eq!(sources[0]["name"], "kaldi.pdf");
1720+ assert_eq!(
1721+ sources[0]["content_type"], "application/pdf",
1722+ "the declared type rides along as a hint"
1723+ );
1724+}
1725+
1726+/// Which sources narrate: **every** attachment of the note, in upload order
1727+/// (id ASC) — PDF, text and docx alike; the service extracts by magic bytes,
1728+/// not by the declared type, so the type rides along as a hint only.
1729+/// `source_key`, the one-release compat field, is the first source's key.
1653 #[tokio::test]1730 #[tokio::test]
1654-async fn the_source_is_the_newest_pdf_attachment() {1731+async fn the_sources_are_all_attachments_in_upload_order() {
1655 let (service, app, cookie, db) = podcast_app().await;1732 let (service, app, cookie, db) = podcast_app().await;
1656 let teacher = common::login_as(&app, &db, "hoca", "teacher").await;1733 let teacher = common::login_as(&app, &db, "hoca", "teacher").await;
1657 let course = common::create_course(&app, &teacher, "Matematik").await;1734 let course = common::create_course(&app, &teacher, "Matematik").await;
1658 let note = create_note(&app, &teacher, &course).await;1735 let note = create_note(&app, &teacher, &course).await;
1659 1736
1660- let draft = upload_attachment(&app, &teacher, &note, "taslak.pdf", "application/pdf").await;1737+ let first = upload_attachment(&app, &teacher, &note, "taslak.pdf", "application/pdf").await;
1661- let _newer_text =1738+ let second = upload_attachment(&app, &teacher, &note, "ozet.txt", "text/plain").await;
1662- upload_attachment(&app, &teacher, &note, "ozet.txt", "text/plain").await;1739+ let third = upload_attachment(
1663- let corrected =1740+ &app,
1664- upload_attachment(&app, &teacher, &note, "duzeltilmis.pdf", "application/pdf").await;1741+ &teacher,
1665- assert_ne!(draft, corrected, "two distinct attachment rows");1742+ &note,
1743+ "konusma.docx",
1744+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
1745+ )
1746+ .await;
1747+ assert_ne!(first, second, "two distinct attachment rows");
1666 1748
1667 let res = submit(&app, &cookie, json!({ "source_id": &note })).await;1749 let res = submit(&app, &cookie, json!({ "source_id": &note })).await;
1668 assert_eq!(res.status, StatusCode::ACCEPTED, "{}", res.body);1750 assert_eq!(res.status, StatusCode::ACCEPTED, "{}", res.body);
@@ -1671,10 +1753,25 @@ async fn the_source_is_the_newest_pdf_attachment() {
1671 assert_eq!(seen.len(), 1, "exactly one dispatch");1753 assert_eq!(seen.len(), 1, "exactly one dispatch");
1672 assert_eq!(seen[0].payload["source_id"], note);1754 assert_eq!(seen[0].payload["source_id"], note);
1673 assert_eq!(1755 assert_eq!(
1674- seen[0].payload["source_key"], corrected,1756+ seen[0].payload["source_key"], first,
1675- "the newest PDF, not the newest file: {}",1757+ "the compat alias is the first source's key: {}",
1676 seen[0].payload1758 seen[0].payload
1677 );1759 );
1760+ let sources = seen[0].payload["sources"].as_array().expect("a source list");
1761+ assert_eq!(sources.len(), 3, "{}", seen[0].payload);
1762+ for (source, (key, name, content_type)) in sources.iter().zip([
1763+ (first.as_str(), "taslak.pdf", "application/pdf"),
1764+ (second.as_str(), "ozet.txt", "text/plain"),
1765+ (
1766+ third.as_str(),
1767+ "konusma.docx",
1768+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
1769+ ),
1770+ ]) {
1771+ assert_eq!(source["key"], key);
1772+ assert_eq!(source["name"], name);
1773+ assert_eq!(source["content_type"], content_type);
1774+ }
1678 }1775 }
1679 1776
1680 /// Authentication is the whole gate on every door: no cookie is a `401`, not a1777 /// Authentication is the whole gate on every door: no cookie is a `401`, not a