Delete library stills from disk before the catalog write, and stop caching their media.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Towsty
2026-10-25 17:55:30 -05:00
co-authored by Cursor
parent 545a3d749b
commit 20359bfbd4
26 changed files with 635 additions and 247 deletions
+38
View File
@@ -0,0 +1,38 @@
import test from 'node:test'
import assert from 'node:assert/strict'
import { readFileSync, readdirSync, statSync } from 'node:fs'
import { join } from 'node:path'
import { fileURLToPath } from 'node:url'
const root = fileURLToPath(new URL('../server/api/library/', import.meta.url))
function walk(dir) {
const files = []
for (const name of readdirSync(dir)) {
const path = join(dir, name)
if (statSync(path).isDirectory()) files.push(...walk(path))
else if (name.endsWith('.ts')) files.push(path)
}
return files
}
const media = walk(root).filter((path) => (
/[/\\](thumb|preview|video|audio|first-frame|last-frame)\.get\.ts$/.test(path)
|| /[/\\]stills[/\\]\[id\]\.get\.ts$/.test(path)
|| /[/\\]drafts[/\\]\[id\][/\\]still\.get\.ts$/.test(path)
))
test('library media routes are uncached and do not answer 304', () => {
const helper = readFileSync(new URL('../server/utils/library.ts', import.meta.url), 'utf8')
assert.match(helper, /Cache-Control', 'no-store, no-cache, must-revalidate'/)
assert.match(helper, /Pragma', 'no-cache'/)
assert.ok(media.length >= 8, media.join('\n'))
for (const path of media) {
const source = readFileSync(path, 'utf8')
assert.match(source, /setLibraryMediaHeaders/, path)
assert.doesNotMatch(source, /304/, path)
assert.doesNotMatch(source, /if-none-match/i, path)
assert.doesNotMatch(source, /max-age=\d+/, path)
assert.doesNotMatch(source, /public, max-age/, path)
}
})