tracker
All repositories: gitoria
2.5 KB
// lib/images.hl — THE IMAGE FILES the pages show (mission 028: out of project.hl, whose routes /posters/:name and// /profiles/:name call `imageResponse`):// /posters/<name> a title's poster (tracker.worldapi.org#4) from storage/mpackdb/posters/ — the file name is the title's// oldId + its extension (shows.hl posterName), downloaded by the sync (tmdb.hl syncPoster)// /profiles/<name> a person's photo (tracker.worldapi.org#16) from storage/mpackdb/profiles/ — downloaded on the first visit// of the person page (people.hl syncProfile)// Both fall back to a placeholder svg when the file isn't there yet (the mongo export never included the poster bytes): "no poster",// a person's "no photo" (tracker#37: /people's tiles).import { Response } from 'hl:http1'import { readBytes, exists } from 'hl:fs'import { imageHeaders } from './security.hl'static placeholderPoster = './assets/poster-placeholder.svg'static placeholderPhoto = './assets/photo-placeholder.svg'static posterNameChars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-_'// a plain file name: letters, digits, '.', '-', '_', at most 100 (also the genre redirect's check, project.hl genreMoved)static isSafePosterName = (&name) => {if (name == null || hlTypeName(name) != 'String' || name == '' || name.length > 100) { return false }let i = 0while (i < name.length) {if (!posterNameChars.includes(name[i])) { return false }i = i + 1}return true}static endsWithStr = (&s, suffix) => { return s.length >= suffix.length && s.slice(s.length - suffix.length) == suffix }static mimeOfPoster = (&name) => {if (endsWithStr(&name, '.png')) { return 'image/png' }if (endsWithStr(&name, '.webp')) { return 'image/webp' }if (endsWithStr(&name, '.svg')) { return 'image/svg+xml' }return 'image/jpeg'}// the answer for `<dir>/<name>`: the file (a day in the browser's cache), else the placeholder (an hour); a name that is no// plain file name → 400 "bad <what> name"static imageResponse = (&dir, &name, &what) => {if (!isSafePosterName(&name)) { return new Response('bad ' + what + ' name', { status = 400 headers = { 'Content-Type' = 'text/plain; charset=utf-8' 'X-Content-Type-Options' = 'nosniff' } }) }path = dir + '/' + nameif (exists(path)) { return new Response(readBytes(path), { headers = imageHeaders(mimeOfPoster(&name), 'public, max-age=86400') }) }return new Response(readBytes(what == 'photo' ? placeholderPhoto : placeholderPoster), { headers = imageHeaders('image/svg+xml', 'public, max-age=3600') })}
Branches
Latest commits
- 87ad2dc1log: GC1 deployingmre
- 53f10fb8Merge branch 'gc1-deploy'mre
- 7fcbf1d2log: GC1 deploy GOmre
- 1fb6664bcompose: TRACKER_QSTATS=1 (GC1 measurement)mre
- 6576c1cdgc1: release the people-view scan lists once the view is builtmre
- 94f8a373gc1: back out the kept episode-id set (no measurable gain on /my/unwatched: 4.69 -> 4.61 GB per 150 loads)mre
- a1a88bd4gc1: search skips the stale-key string while no entry is stale; /my/unwatched asks a kept id set instead of building a key string per episode rowmre
- cd830744gc1: dbSearch: no split / map / list copy per candidate (scores from the stored text, top list touched only when the hit can enter)mre
- 451db7cdgc1: show page and check clicks read the kept watched set instead of building one from a by-value copy of every watchmre
- ddb4127egc1: TRACKER_QSTATS=1 logs queue and cache sizes every 10 s (measurement only)mre
- da60547fstatus: GC1 done, backup bugmre
- e4171021log: GC1 result, backup hard-link bugmre
- f1597214deploy.sh backup: tar --hard-dereference (hot tar stored mpackdb sidecars as hard links to .sessions files)mre
- 6b58571elog: GC windowmre
- 5c8baa1fdeploy lock: hold only around deploy.shmre
- b8dac822log: hybriel#309mre
- bf676d9elog: GC1 startedmre
- c7828541mission GC1mre
- ef949994conductor: neutral ticket rulemre
- 89e91ef3log: RV39 livemre