tracker
All repositories: gitoria
18.8 KB
// project.hl — tracker.worldapi.org: THE MAP (mission 028, docs: README "Files"). Config, the routes and how the parts are wired;// what each feature does is in the file named here, not in this one.//// login (ident only, the header's selector + button) lib/users.hl, components/main.hl, login.js, /login/* below// the shell: header, main menu, user menu, sidebar components/main.hl (theme/shell/*, vendored from layouts.worldapi.org)// /genres · /people (the main menu) · /settings lib/catalog.hl genreList · lib/people.hl peoplePage · components/settings.hl// titles: records, slugs, kinds, list caches lib/shows.hl a title's page: components/show.hl// public lists /movies /series /shows /genres, home lib/catalog.hl// components/{movies,allseries,allshows,genre,home,tilelist}.hl// follows · watches · /my/* lib/follows.hl · lib/watches.hl// components/{myshows,mymovies,unwatched,schedule}.hl// search, web search, import lib/search.hl (+ search-helpers.hl) components/search.hl// people, a person's page and filmography fill lib/people.hl components/person.hl// cast + crew, the credits job lib/credits.hl (+ credits-helpers.hl)// a title completed from TMDB (details repair) lib/details.hl// TMDB / TVmaze requests, posters lib/tmdb.hl// the sync of one title · which titles a day lib/sync.hl (+ sync-helpers.hl) · lib/dailysync.hl// adult flag + kind backfills lib/backfill.hl// short ids (/<shortId>) lib/shortids.hl// franchises + timelines · TMDB collection seed lib/franchises.hl · lib/collections.hl// the curated franchises (data/franchises.json, #40) lib/franchiseseed.hl// components/franchise*.hl, timelineedit.hl// duplicate titles merged lib/merge.hl// the background jobs and their clocks lib/jobs.hl (one instance, made below after the server)// poster + photo files lib/images.hl// shared helpers (env, paths, dates, ids, lists) lib/util.hl// styles · design tokens · the WorldAPI theme components/styles.hl · shared/tokens.hl · theme/ (never edited here)//// Config (env; no committed secret — the first deploy registers this app in ident and sets these, done by the architect, as// with ident's own .env for SMTP): TRACKER_PORT (45008), TRACKER_URL (this app's own public address, for the return URL),// IDENT_URL (https://ident.worldapi.org), TRACKER_KEY (pk_…), TRACKER_SECRET (sk_…), TRACKER_STORAGE, TRACKER_SESSIONS,// TRACKER_WATCH, TMDB_READ_TOKEN; the jobs' switches and limits: lib/jobs.hl (README "Config").import WebFramework from 'hl:web'import { Response } from 'hl:http1'import { env } from 'hl:proc'import { now } from 'hl:time'import Styles from './components/styles.hl'import Home from './components/home.hl'import LoginFailed from './components/loginfailed.hl'import Show from './components/show.hl'import Unwatched from './components/unwatched.hl'import Schedule from './components/schedule.hl'import MyShows from './components/myshows.hl'import MyMovies from './components/mymovies.hl'import Movies from './components/movies.hl'import AllShows from './components/allshows.hl'import AllSeries from './components/allseries.hl'import Search from './components/search.hl'import Person from './components/person.hl'import Genre from './components/genre.hl'import Genres from './components/genres.hl'import People from './components/people.hl'import Settings from './components/settings.hl'import Franchises from './components/franchises.hl'import Franchise from './components/franchise.hl'import FranchiseEdit from './components/franchiseedit.hl'import TimelineEdit from './components/timelineedit.hl'import { dark, darker } from './shared/tokens.hl'import { postersDir, profilesDir, movedResponse } from './lib/util.hl'import { loginCallbackOf } from './lib/users.hl'import { imageResponse, isSafePosterName } from './lib/images.hl'import { ensureIndex } from './lib/search.hl'import { showsMovedPath, warmTitleCaches, warmEpisodeKeys, movedSlugCount, personById } from './lib/shows.hl'import { allWatchedEpisodeIds } from './lib/watches.hl'import { allFollowedShowIds } from './lib/follows.hl'import { ensureShortIds, shortIdPath } from './lib/shortids.hl'import { guestPersonId, warmPeopleView, peopleViewStats } from './lib/people.hl'import { moveCopiedSummaries } from './lib/dailysync.hl'import { ensureFranchises } from './lib/franchises.hl'import Jobs from './lib/jobs.hl'static appTitle = "tracker"// ---- THE INSTALLABLE APP (tracker.worldapi.org#10), the same way calendar.worldapi.org does it: hl:web's own web app// manifest (/__hl/manifest.webmanifest, linked from every head with the apple-touch-icon and theme-color) and service// worker (/__hl/sw.js) from these settings — no JavaScript of ours. Icons in icons/ (icon.svg is the source, the PNGs// are rendered from it with rsvg-convert, README "Icons"). The theme colour is the header's background (darker), the// splash background the page's (dark) — both off the tokens, not written out again.appThemeColor = darker.valueappBackgroundColor = dark.valueappIcons = [{ src = '/icons/icon-192.png' sizes = '192x192' purpose = 'any' }{ src = '/icons/icon-512.png' sizes = '512x512' purpose = 'any' }{ src = '/icons/icon-192.png' sizes = '192x192' purpose = 'maskable' }{ src = '/icons/icon-512.png' sizes = '512x512' purpose = 'maskable' }]appTouchIcon = '/icons/apple-touch-icon.png'appFavicon = '/icons/favicon.svg'// OFFLINE: only the shell — the header and `/` (components/main.hl says "You are offline" while the browser has no// network). The data pages are not kept: without a network they get hl:web's "Unavailable offline" page.offline = [ Home ]styles = Stylesport = env('TRACKER_PORT') != null ? toNumber(env('TRACKER_PORT')) : 45008watching = env('TRACKER_WATCH') != '0'// read by hl:web's own manifest config (WebFramework.hl `cfg.sessionDir`), not the constructor call belowsessionDir = env('TRACKER_SESSIONS') != null ? env('TRACKER_SESSIONS') : null// ---- the function routes: each checks its input, asks the topic, answers ---------------------------------------------------// /login/callback?ident_code=… (lib/users.hl): the code exchanged, this app's session signed in, back to the page (`?next=`)loginCallback = (&route, &req) => { return loginCallbackOf(server.sessions, req) }// /posters/<name>, /profiles/<name> (lib/images.hl): the file, else the placeholderposterRoute = (&route, &req) => { return imageResponse(postersDir, route.params != null ? route.params.name : null, 'poster') }profileRoute = (&route, &req) => { return imageResponse(profilesDir, route.params != null ? route.params.name : null, 'photo') }// the old addresses of the personal lists (tracker.worldapi.org#8): they all live under /my/ now — a permanent redirect so old// links keep working (architect's decision)movedTo = (&path) => { return movedResponse(path) }notFoundText = (&text) => { return new Response(text, { status = 404 headers = { 'Content-Type' = 'text/plain; charset=utf-8' } }) }unwatchedMoved = (&route, &req) => { return movedTo('/my/unwatched') }scheduleMoved = (&route, &req) => { return movedTo('/my/schedule') }// mission 058: the show page's genre pills linked `/genre/<x>` (no page there) — the genre pages are `/genres/<x>`genreMoved = (&route, &req) => {g = route.params != null ? route.params.genre : nullreturn movedTo(isSafePosterName(g) ? '/genres/' + g : '/')}// mission 060 (tracker.worldapi.org#27): `/<shortId>` → 301 to the title's or person's page (lib/shortids.hl); upper case is// read as lower case; anything else is a 404shortIdRoute = (&route, &req) => {sid = route.params != null ? route.params.sid : nullpath = sid != null && hlTypeName(sid) == 'String' ? shortIdPath(sid.toLowerCase()) : nullif (path == null) { return notFoundText('not found') }return movedTo(path)}// mission 062: a GUEST STAR's link (components/show.hl castRowsOf) — `/person/tmdb/<tmdbId>?show=<show id>` creates the person// (lib/people.hl guestPersonId) or finds the one we have, then 302 → `/person/<slug>`. A function route: the browser loads it// itself (hl:web's client router hands every non-component link to the browser)guestRoute = (&route, &req) => {t = route.params != null ? route.params.tmdb : nulltmdbId = t != null && hlTypeName(t) == 'String' && t.length <= 10 ? toNumber(t) : nullif (tmdbId == null || tmdbId < 1) { return notFoundText('not found') }q = req.query != null ? req.query : {}r = guestPersonId(tmdbId, q.show)p = r.id != null ? personById(r.id) : nullif (p == null || p.urlSegment == null) { return notFoundText('not found: ' + (r.error != null ? r.error : 'no such person')) }return new Response('see /person/' + p.urlSegment, { status = 302 headers = { 'Location' = '/person/' + p.urlSegment 'Cache-Control' = 'no-store' 'Content-Type' = 'text/plain; charset=utf-8' } })}// tracker#32 (mission 031): the header's search field sends GET /find?q=<text> (the theme's AppHeader form); a page cannot read a// query string, so this answers 302 → /search/<text> ('/', '?', '#' as spaces, like components/search.hl), no text → /searchfindRoute = (&route, &req) => {q = req.query != null && req.query.q != null && hlTypeName(req.query.q) == 'String' ? req.query.q.replaceAll('/', ' ').replaceAll('?', ' ').replaceAll('#', ' ').trim() : ''to = q != '' ? '/search/' + encodeURIComponent(q) : '/search'return new Response('see ' + to, { status = 302 headers = { 'Location' = to 'Cache-Control' = 'no-store' 'Content-Type' = 'text/plain; charset=utf-8' } })}// /shows/<slug> (tracker.worldapi.org#21, mission 068): a series or movie (or a merged duplicate's slug) answers 301 to its page// (lib/shows.hl showsMovedPath). hl:web has no way for a component route to answer a redirect, so this is a FUNCTION route, and// for a show (or an unknown slug: the page's own "Not found") it renders the title page the way hl:web renders a component// route (WebFramework.hl `on http.request`, the `component` branch): the Show component matched at /series/<slug> — same// component, same params — with the cookie's session, a new one (and its cookie) when the browser brought none. In the browser// a link to /shows/<slug> is then a full page load; every other title page stays a client-side navigation.showsRoute = (&route, &req) => {slug = route.params != null ? route.params.slug : nullto = showsMovedPath(slug)if (to != null) { return movedTo(to) }m = server.router.match('/series/' + slug)let s = req.sessionfresh = s == nullif (fresh) { s = server.sessions.mint() }let res = server.page(m, s, server.hostOf(req.headers['host']), server.requestHeaders(req.headers))if (fresh) { res.headers['Set-Cookie'] = server.sessions.cookieHeader(s.id) }return res}routes = [{ pattern = "/favicon.ico" file = "./icons/favicon.ico" headers = { 'Cache-Control' = 'no-cache' } }// the installable app (tracker.worldapi.org#10): the icons (manifest and service worker are hl:web's own, from appIcons / offline){ pattern = "/icons/icon-192.png" file = "./icons/icon-192.png" headers = { 'Cache-Control' = 'no-cache' } }{ pattern = "/icons/icon-512.png" file = "./icons/icon-512.png" headers = { 'Cache-Control' = 'no-cache' } }{ pattern = "/icons/apple-touch-icon.png" file = "./icons/apple-touch-icon.png" headers = { 'Cache-Control' = 'no-cache' } }{ pattern = "/icons/favicon.svg" file = "./icons/favicon.svg" headers = { 'Cache-Control' = 'no-cache' } }{ pattern = "/login/callback" function = loginCallback }{ pattern = "/login/failed" component = LoginFailed }{ pattern = "/login.js" file = "./login.js" headers = { 'Cache-Control' = 'no-cache' } }{ pattern = "/posters/:name" function = posterRoute }// tracker.worldapi.org#13: every movie / every series, 24 per page — the page is a PATH segment (`/movies/page/2`), a// page component cannot read `?page=` (hybriel#11) — and the movies the user follows{ pattern = "/movies" component = Movies }{ pattern = "/movies/page/:page" component = Movies }// tracker.worldapi.org#21 (mission 068): series and shows split — /series lists the series, /shows the shows; a title's page// is /movies/<slug>, /series/<slug> or /shows/<slug> (one component; /shows/<slug> is showsRoute above){ pattern = "/movies/:slug" component = Show }{ pattern = "/series" component = AllSeries }{ pattern = "/series/page/:page" component = AllSeries }{ pattern = "/series/:slug" component = Show }{ pattern = "/shows" component = AllShows }{ pattern = "/shows/page/:page" component = AllShows }{ pattern = "/shows/:slug" function = showsRoute }{ pattern = "/my/movies" component = MyMovies }{ pattern = "/my/unwatched" component = Unwatched }{ pattern = "/my/schedule" component = Schedule }// #21: /my/series and /my/shows (one component, components/myshows.hl; any other word there is its "Not found"){ pattern = "/my/:tv" component = MyShows }{ pattern = "/unwatched" function = unwatchedMoved }{ pattern = "/schedule" function = scheduleMoved }// tracker.worldapi.org#14: the search — `/search/<text>` (hl:web gives a page no query string, so not `?q=`){ pattern = "/search/:q?" component = Search }{ pattern = "/find" function = findRoute }// tracker.worldapi.org#16: a person's page (the show page's cast and the search link here) and their photo{ pattern = "/person/tmdb/:tmdb" function = guestRoute }{ pattern = "/person/:slug" component = Person }{ pattern = "/profiles/:name" function = profileRoute }// mission 058 (tracker.worldapi.org#25): a genre's movies and series, like /movies (the page in the path){ pattern = "/genres/:genre" component = Genre }{ pattern = "/genres/:genre/page/:page" component = Genre }{ pattern = "/genre/:genre" function = genreMoved }// tracker#32 (mission 031): the main menu's Genres and People, the user menu's Settings{ pattern = "/genres" component = Genres }// tracker#37 (mission 032): /people = everyone, the one updated last first, 24 per page (the page in the path, like /movies){ pattern = "/people" component = People }{ pattern = "/people/page/:page" component = People }{ pattern = "/settings" component = Settings }// tracker.worldapi.org#19 (mission 066): franchises and timelines, the creator's editor (`/franchises/edit` before the slug){ pattern = "/franchises" component = Franchises }{ pattern = "/franchises/edit" component = FranchiseEdit }{ pattern = "/franchises/:slug" component = Franchise }{ pattern = "/timelines/:tslug" component = Franchise }{ pattern = "/timelines/:slug/edit" component = TimelineEdit }{ pattern = "/" component = Home }// mission 060 (tracker.worldapi.org#27): a short id → its page (LAST: every named one-segment route above wins){ pattern = "/:sid" function = shortIdRoute }]// WHO GETS THE PUSH: the login state reaches the tabs of one session (components/main.hl trackerSignedIn/Out).tagOf = (&session) => { return session != null && session.data != null ? session.data.tag : null }audience = {trackerSignedIn = (tag, &session) => { return tag != null && tagOf(session) == tag }trackerSignedOut = (tag, &session) => { return tag != null && tagOf(session) == tag }}// cookies are per host, not per port: an own name keeps this app's session apart from// ident's own (and from any other worldapi app sharing a dev host), see ident README "Design// tokens" / hybriel#10 hybriel#17.sessionCookie = 'trackersid'// tracker.worldapi.org#14: the search index (lib/search.hl) is built once here at boot (~0.6 s on the real data), not by the// first searchsearchIndexReady = ensureIndex()// mission 060: every short id in use (one map over shows AND persons) and the records still without one, before the first requestshortIdsReady = ensureShortIds()// tracker#30 (mission 025): the slim list caches (lib/shows.hl cardOf / episodeRowsOf) of every followed title, before the first// /my/ load — not filled by that loadtitleCachesStart = now()titleCachesWarm = warmTitleCaches(allFollowedShowIds())episodeKeysWarm = warmEpisodeKeys(allWatchedEpisodeIds())console.log('list caches: ' + titleCachesWarm + ' followed titles, ' + episodeKeysWarm + ' watched episodes in ' + (now() - titleCachesStart) + ' ms')// tracker#37 (mission 032, lib/people.hl): /people's order (everyone, the one updated last first) and the photos from the titles'// casts, before the first /people load — not built by that loadpeopleViewStart = now()peopleViewWarm = warmPeopleView()console.log('people view: ' + peopleViewWarm + ' people, ' + peopleViewStats().castProfiles + ' cast photos in ' + (now() - peopleViewStart) + ' ms')// tracker#18, ONCE (lib/dailysync.hl moveCopiedSummaries): a `summary` that is only the migrated copy of tmdbSummary is MOVED to// `migratedSummary` (mission 070: kept, not shown) — the current TMDB text shows; the creator's own texts staysummariesMoved = moveCopiedSummaries()if (summariesMoved.ran) { console.log('summaries: moved ' + summariesMoved.moved + ' copies of tmdbSummary to migratedSummary, kept ' + summariesMoved.kept + ' own texts, errors ' + summariesMoved.errors + ', ' + summariesMoved.ms + ' ms') }// mission 066: which timelines every title is in (one scan of the timelines), before the first show pagefranchisesReady = ensureFranchises()console.log('moved slugs: ' + movedSlugCount() + ' (their pages show the keeper)')// tracker#31 + #41 (missions 026, 037, 037b): the slug of a merged duplicate, or a keeper's former slug, has NO route of its own: hl:web// writes every route into each page's HTML (its client route table) — one per moved slug listed 56 of them, adult titles' among// them, on every page (#41). /movies/:slug and /series/:slug (component routes, which cannot redirect) find the keeper by the slug// map (lib/shows.hl showBySlug) and render its page with its canonical address in the head (components/show.hl `__meta` og:url);// /shows/<slug> (showsRoute, a function route) answers 301. No request tap: the class tap of mission 037 crashed hybriel 06617221// after ~37 answers.server = new WebFramework(routes = routes, styles = styles, port = port, sessionCookie = sessionCookie, watchMode = watching)// ---- THE BACKGROUND JOBS (lib/jobs.hl): the daily TMDB sync, the backfills, the details repair, the credits job, the duplicate// merge, the short-id backfill, the collection seed, the curated franchise seed — constructing it starts their clocks and logs which ones are offjobs = new Jobs()on Error(e) { console.log('error absorbed: ' + e.message) }
Branches
Latest commits
- f03dfbfcmission 040: re-vendor Hybriel 0f396652 (static build): plugins, compose cache volume/HL_CACHE_DIR/tmpfs, README, reportmre
- 5d4683b4mission brief 040mre
- e00d3bf7paths: projects moved into /media/STORAGE/projects/WorldAPI/mre
- a8c7f234tracker#36 (mission 039): tools/tmdb-check.hl survives a dropped connection (on Error, asked again, failed lines) and resumes with --from N; tests/tmdbcheck.mjs 6/6 against a fake TMDBmre
- 9c230516mission brief w39mre
- 3609121dmission 038 docs + report (quota stop): README/kinds.md for #43 #42 #36, STATUS, LOG; HEAD browser gate 374/8 in the in-app daily run block (hour-boundary suspected, rerun pending), other gates green; #36 real run needs TMDB_READ_TOKENmre
- a5d06e79tracker#36 (mission 038): tools/tmdb-check.hl + lib/tmdbcheck.hl — every live migrated title's migrated title + year against its TMDB entry (one GET /movie|tv/<id>?append_to_response=alternative_titles, 260 ms apart, passing failures asked once more): ok / ambiguous (one of title, year disagrees) / clear (both, or 404); read-only; token only from TMDB_READ_TOKEN; --stored = a title-only preview from the TMDB names already stored (no request). Tested against a fake TMDB (.scratch/w38/t36): 7 titles, 3 ok, 2 ambiguous, 2 clear, data unchangedmre
- 982554f3tracker#42 (mission 038): series pages — an unknown slug no longer scans every title (lib/shows.hl showBySlug: the slug map only; new titles are noted by refreshTitleCaches, which both title puts already reach): 10.7–15.7 s → 0.013 s on the real copy (the one-request-at-a-time server was blocked meanwhile); cast/crew rows take name + slug from a person-link cache (personLinkOf) instead of whole person records (SNL: 303 cast with 4,761 credits, ~49k allocations per render) — allocations per series page −5…−40 %; HTML of 20 pages identical to beforemre
- 4586b6e3docker-compose: init: true (hybriel#156)mre
- 085c2e5ftracker#43 (mission 038): TVmaze's type makes Variety / Talk Show / Game Show / Reality / News / Panel Show / Award Show / Sports titles Shows (TMDB calls Saturday Night Live UK Scripted) — the #43 part of parked w37-wip a79c8c1 only (no re-vendor, no cache volume): tvmazeType stored by the sync and the TVmaze status backfill (asks every series with a TVmaze id once), kindOfTitle/kindWithTvmaze, tools/tvmaze-types.hl, gate fixture Variety Gate Series; start waits 150 smre
- 4fa303b5mission brief w38mre
- 975f6843tracker#41 (mission 037b): no request tap — an old /movies|/series slug renders the keeper's page (slug map) with og:url naming the keeper's address, /shows/ 301; no moved slug in any page's HTML. Real copy 168/168 old addresses, 0 moved slugs in 54 pages, 300x + 1000x stress without a crash; gates on 06617221 380/0, 32/0, 53/0, 229/0, 26/0, theme 0mre
- 6decff4ftracker#41 (mission 037): moved slugs no longer listed in every page's HTML — a request tap answers their 301 by a slug-map lookup (shows.hl movedTitlePath); catalog.hl buildIndex pushes genre lists in place (the quadratic copy hung the boot > 20 min on today's data); gate: no moved slug in 19 page kinds signed out/in, immediate 301 after a merge. Gates on hybriel 06617221 green (380/0, 32/0, 53/0, 229/0, 26/0, theme 0); real copy 84/84 301, 0 moved slugs in 54 pages. NOT deployable: the tap faults after ~38 answers on 06617221 (report 037).mre
- 35f7a872mission brief 037mre
- 5cbcddd7tracker mission 036: recheck of the 16 review tickets — 15 WORKS, #39 PARTLY; review packages + bugs in reports/036-review-recheck.md (no code change)mre
- 9e18c2d0mission brief (w36)mre
- 216fac57missions 028-035 + reports 033/034 (were untracked)mre
- 5cb85d75deploy.sh: a backup taken while a background job writes (tar exit 1) is a warning; archive checked with gzip -tmre
- 9abda75dtracker: report 035mre
- 12595e47mission 035: theme re-vendored from layouts.worldapi.org 0222f67 (two corner radii: radiusSmall 5px, radiusLarge 10px); the tracker's 18 own radii -> radiusSmall/radiusLarge (--layout-radius is gone); check-theme 0; gates 379/0, 32/0, 53/0, 229/0, 26/0; real copy: every computed radius in {0, 5px, 10px, 50%}mre