fix: audio asset playback and orphan-cleanup thumbnail deletion

The audio proxy resolved ownership only through voice comments, so
R2_AUDIO video assets (which store the same proxy path in
videoAsset.sourceUrl) always got 403s. Resolve ownership the way the
image proxy does: query comments and video assets, merge into a
unique-owning-video map, deny on ambiguity.

r2-orphan-cleanup marked videoAsset.sourceUrl as referenced but not
videoAsset.thumbnailUrl, so every R2_VIDEO asset thumbnail older than
the TTL was deleted as an orphan. Widen the query to both columns.

Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
eehkay
2026-07-19 13:17:13 -07:00
co-authored by Claude Fable 5
parent 33008d33ad
commit 16efba4e19
2 changed files with 37 additions and 22 deletions
+5 -2
View File
@@ -119,8 +119,10 @@ async function findReferencedUrls(urls: string[]): Promise<Set<string>> {
})
: Promise.resolve([] as Array<{ url: string }>),
db.videoAsset.findMany({
where: { sourceUrl: { in: group } },
select: { sourceUrl: true },
where: {
OR: [{ sourceUrl: { in: group } }, { thumbnailUrl: { in: group } }],
},
select: { sourceUrl: true, thumbnailUrl: true },
}),
db.videoVersion.findMany({
where: {
@@ -142,6 +144,7 @@ async function findReferencedUrls(urls: string[]): Promise<Set<string>> {
}
for (const row of assetRows) {
if (row.sourceUrl) referenced.add(row.sourceUrl);
if (row.thumbnailUrl) referenced.add(row.thumbnailUrl);
}
for (const row of versionRows) {
if (row.originalUrl) referenced.add(row.originalUrl);