gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitac6268e3ac6268e3mission 046a: re-vendor Hybriel 528bc89f (integration 6): plugins mpackdb/time/web (bin/ git-ignored)mreac6268e3/project.hl

18.3 KB

  1. // project.hl — tracker.worldapi.org: THE MAP (mission 028, docs: README "Files"). Config, the routes and how the parts are wired;
  2. // what each feature does is in the file named here, not in this one.
  3. //
  4. // login (ident only, the header's selector + button) lib/users.hl, components/main.hl, login.js, /login/* below
  5. // the shell: header, main menu, user menu, sidebar components/main.hl (theme/shell/*, vendored from layouts.worldapi.org)
  6. // /genres · /people (the main menu) · /settings lib/catalog.hl genreList · lib/people.hl peoplePage · components/settings.hl
  7. // titles: records, slugs, kinds, list caches lib/shows.hl a title's page: components/show.hl
  8. // public lists /movies /series /shows /genres, home lib/catalog.hl
  9. // components/{movies,allseries,allshows,genre,home,tilelist}.hl
  10. // follows · watches · /my/* lib/follows.hl · lib/watches.hl
  11. // components/{myshows,mymovies,unwatched,schedule}.hl
  12. // search, web search, import lib/search.hl (+ search-helpers.hl) components/search.hl
  13. // people, a person's page and filmography fill lib/people.hl components/person.hl
  14. // cast + crew, the credits job lib/credits.hl (+ credits-helpers.hl)
  15. // a title completed from TMDB (details repair) lib/details.hl
  16. // TMDB / TVmaze requests, posters lib/tmdb.hl
  17. // the sync of one title · which titles a day lib/sync.hl (+ sync-helpers.hl) · lib/dailysync.hl
  18. // adult flag + kind backfills lib/backfill.hl
  19. // short ids (/<shortId>) lib/shortids.hl
  20. // the boot scans: ONE streamed pass per table lib/bootscan.hl
  21. // franchises + timelines · TMDB collection seed lib/franchises.hl · lib/collections.hl
  22. // the curated franchises (data/franchises.json, #40) lib/franchiseseed.hl
  23. // components/franchise*.hl, timelineedit.hl
  24. // duplicate titles merged lib/merge.hl
  25. // the background jobs and their clocks lib/jobs.hl (one instance, made below after the server)
  26. // poster + photo files lib/images.hl
  27. // shared helpers (env, paths, dates, ids, lists) lib/util.hl
  28. // styles · design tokens · the WorldAPI theme components/styles.hl · shared/tokens.hl · theme/ (never edited here)
  29. //
  30. // Config (env; no committed secret — the first deploy registers this app in ident and sets these, done by the architect, as
  31. // with ident's own .env for SMTP): TRACKER_PORT (45008), TRACKER_URL (this app's own public address, for the return URL),
  32. // IDENT_URL (https://ident.worldapi.org), TRACKER_KEY (pk_…), TRACKER_SECRET (sk_…), TRACKER_STORAGE, TRACKER_SESSIONS,
  33. // TRACKER_WATCH, TMDB_READ_TOKEN; the jobs' switches and limits: lib/jobs.hl (README "Config").
  34. import WebFramework from 'hl:web'
  35. import { Response } from 'hl:http1'
  36. import { env } from 'hl:proc'
  37. import { now } from 'hl:time'
  38. import Styles from './components/styles.hl'
  39. import Home from './components/home.hl'
  40. import LoginFailed from './components/loginfailed.hl'
  41. import Show from './components/show.hl'
  42. import Unwatched from './components/unwatched.hl'
  43. import Schedule from './components/schedule.hl'
  44. import MyShows from './components/myshows.hl'
  45. import MyMovies from './components/mymovies.hl'
  46. import Movies from './components/movies.hl'
  47. import AllShows from './components/allshows.hl'
  48. import AllSeries from './components/allseries.hl'
  49. import Search from './components/search.hl'
  50. import Person from './components/person.hl'
  51. import Genre from './components/genre.hl'
  52. import Genres from './components/genres.hl'
  53. import People from './components/people.hl'
  54. import Settings from './components/settings.hl'
  55. import Franchises from './components/franchises.hl'
  56. import Franchise from './components/franchise.hl'
  57. import FranchiseEdit from './components/franchiseedit.hl'
  58. import TimelineEdit from './components/timelineedit.hl'
  59. import { dark, darker } from './shared/tokens.hl'
  60. import { postersDir, profilesDir, movedResponse } from './lib/util.hl'
  61. import { loginCallbackOf } from './lib/users.hl'
  62. import { imageResponse, isSafePosterName } from './lib/images.hl'
  63. import { bootScan } from './lib/bootscan.hl'
  64. import { showsMovedPath, warmTitleCaches, warmEpisodeKeys, movedSlugCount, personById } from './lib/shows.hl'
  65. import { allWatchedEpisodeIds } from './lib/watches.hl'
  66. import { allFollowedShowIds } from './lib/follows.hl'
  67. import { shortIdPath } from './lib/shortids.hl'
  68. import { guestPersonId } from './lib/people.hl'
  69. import { moveCopiedSummaries } from './lib/dailysync.hl'
  70. import { ensureFranchises } from './lib/franchises.hl'
  71. import Jobs from './lib/jobs.hl'
  72. static appTitle = "tracker"
  73. // ---- THE INSTALLABLE APP (tracker.worldapi.org#10), the same way calendar.worldapi.org does it: hl:web's own web app
  74. // manifest (/__hl/manifest.webmanifest, linked from every head with the apple-touch-icon and theme-color) and service
  75. // worker (/__hl/sw.js) from these settings — no JavaScript of ours. Icons in icons/ (icon.svg is the source, the PNGs
  76. // are rendered from it with rsvg-convert, README "Icons"). The theme colour is the header's background (darker), the
  77. // splash background the page's (dark) — both off the tokens, not written out again.
  78. appThemeColor = darker.value
  79. appBackgroundColor = dark.value
  80. appIcons = [
  81. { src = '/icons/icon-192.png' sizes = '192x192' purpose = 'any' }
  82. { src = '/icons/icon-512.png' sizes = '512x512' purpose = 'any' }
  83. { src = '/icons/icon-192.png' sizes = '192x192' purpose = 'maskable' }
  84. { src = '/icons/icon-512.png' sizes = '512x512' purpose = 'maskable' }
  85. ]
  86. appTouchIcon = '/icons/apple-touch-icon.png'
  87. appFavicon = '/icons/favicon.svg'
  88. // OFFLINE: only the shell — the header and `/` (components/main.hl says "You are offline" while the browser has no
  89. // network). The data pages are not kept: without a network they get hl:web's "Unavailable offline" page.
  90. offline = [ Home ]
  91. styles = Styles
  92. port = env('TRACKER_PORT') != null ? toNumber(env('TRACKER_PORT')) : 45008
  93. watching = env('TRACKER_WATCH') != '0'
  94. // read by hl:web's own manifest config (WebFramework.hl `cfg.sessionDir`), not the constructor call below
  95. sessionDir = env('TRACKER_SESSIONS') != null ? env('TRACKER_SESSIONS') : null
  96. // ---- the function routes: each checks its input, asks the topic, answers ---------------------------------------------------
  97. // /login/callback?ident_code=… (lib/users.hl): the code exchanged, this app's session signed in, back to the page (`?next=`)
  98. loginCallback = (&route, &req) => { return loginCallbackOf(server.sessions, req) }
  99. // /posters/<name>, /profiles/<name> (lib/images.hl): the file, else the placeholder
  100. posterRoute = (&route, &req) => { return imageResponse(postersDir, route.params != null ? route.params.name : null, 'poster') }
  101. profileRoute = (&route, &req) => { return imageResponse(profilesDir, route.params != null ? route.params.name : null, 'photo') }
  102. // the old addresses of the personal lists (tracker.worldapi.org#8): they all live under /my/ now — a permanent redirect so old
  103. // links keep working (architect's decision)
  104. movedTo = (&path) => { return movedResponse(path) }
  105. notFoundText = (&text) => { return new Response(text, { status = 404 headers = { 'Content-Type' = 'text/plain; charset=utf-8' } }) }
  106. unwatchedMoved = (&route, &req) => { return movedTo('/my/unwatched') }
  107. scheduleMoved = (&route, &req) => { return movedTo('/my/schedule') }
  108. // mission 058: the show page's genre pills linked `/genre/<x>` (no page there) — the genre pages are `/genres/<x>`
  109. genreMoved = (&route, &req) => {
  110. g = route.params != null ? route.params.genre : null
  111. return movedTo(isSafePosterName(g) ? '/genres/' + g : '/')
  112. }
  113. // mission 060 (tracker.worldapi.org#27): `/<shortId>` → 301 to the title's or person's page (lib/shortids.hl); upper case is
  114. // read as lower case; anything else is a 404
  115. shortIdRoute = (&route, &req) => {
  116. sid = route.params != null ? route.params.sid : null
  117. path = sid != null && hlTypeName(sid) == 'String' ? shortIdPath(sid.toLowerCase()) : null
  118. if (path == null) { return notFoundText('not found') }
  119. return movedTo(path)
  120. }
  121. // mission 062: a GUEST STAR's link (components/show.hl castRowsOf) — `/person/tmdb/<tmdbId>?show=<show id>` creates the person
  122. // (lib/people.hl guestPersonId) or finds the one we have, then 302 → `/person/<slug>`. A function route: the browser loads it
  123. // itself (hl:web's client router hands every non-component link to the browser)
  124. guestRoute = (&route, &req) => {
  125. t = route.params != null ? route.params.tmdb : null
  126. tmdbId = t != null && hlTypeName(t) == 'String' && t.length <= 10 ? toNumber(t) : null
  127. if (tmdbId == null || tmdbId < 1) { return notFoundText('not found') }
  128. q = req.query != null ? req.query : {}
  129. r = guestPersonId(tmdbId, q.show)
  130. p = r.id != null ? personById(r.id) : null
  131. if (p == null || p.urlSegment == null) { return notFoundText('not found: ' + (r.error != null ? r.error : 'no such person')) }
  132. 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' } })
  133. }
  134. // tracker#32 (mission 031): the header's search field sends GET /find?q=<text> (the theme's AppHeader form); a page cannot read a
  135. // query string, so this answers 302 → /search/<text> ('/', '?', '#' as spaces, like components/search.hl), no text → /search
  136. findRoute = (&route, &req) => {
  137. q = req.query != null && req.query.q != null && hlTypeName(req.query.q) == 'String' ? req.query.q.replaceAll('/', ' ').replaceAll('?', ' ').replaceAll('#', ' ').trim() : ''
  138. to = q != '' ? '/search/' + encodeURIComponent(q) : '/search'
  139. return new Response('see ' + to, { status = 302 headers = { 'Location' = to 'Cache-Control' = 'no-store' 'Content-Type' = 'text/plain; charset=utf-8' } })
  140. }
  141. // /shows/<slug> (tracker.worldapi.org#21, mission 068): a series or movie (or a merged duplicate's slug) answers 301 to its page
  142. // (lib/shows.hl showsMovedPath). hl:web has no way for a component route to answer a redirect, so this is a FUNCTION route, and
  143. // 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
  144. // route (WebFramework.hl `on http.request`, the `component` branch): the Show component matched at /series/<slug> — same
  145. // component, same params — with the cookie's session, a new one (and its cookie) when the browser brought none. In the browser
  146. // a link to /shows/<slug> is then a full page load; every other title page stays a client-side navigation.
  147. showsRoute = (&route, &req) => {
  148. slug = route.params != null ? route.params.slug : null
  149. to = showsMovedPath(slug)
  150. if (to != null) { return movedTo(to) }
  151. m = server.router.match('/series/' + slug)
  152. let s = req.session
  153. fresh = s == null
  154. if (fresh) { s = server.sessions.mint() }
  155. let res = server.page(m, s, server.hostOf(req.headers['host']), server.requestHeaders(req.headers))
  156. if (fresh) { res.headers['Set-Cookie'] = server.sessions.cookieHeader(s.id) }
  157. return res
  158. }
  159. routes = [
  160. { pattern = "/favicon.ico" file = "./icons/favicon.ico" headers = { 'Cache-Control' = 'no-cache' } }
  161. // the installable app (tracker.worldapi.org#10): the icons (manifest and service worker are hl:web's own, from appIcons / offline)
  162. { pattern = "/icons/icon-192.png" file = "./icons/icon-192.png" headers = { 'Cache-Control' = 'no-cache' } }
  163. { pattern = "/icons/icon-512.png" file = "./icons/icon-512.png" headers = { 'Cache-Control' = 'no-cache' } }
  164. { pattern = "/icons/apple-touch-icon.png" file = "./icons/apple-touch-icon.png" headers = { 'Cache-Control' = 'no-cache' } }
  165. { pattern = "/icons/favicon.svg" file = "./icons/favicon.svg" headers = { 'Cache-Control' = 'no-cache' } }
  166. { pattern = "/login/callback" function = loginCallback }
  167. { pattern = "/login/failed" component = LoginFailed }
  168. { pattern = "/login.js" file = "./login.js" headers = { 'Cache-Control' = 'no-cache' } }
  169. { pattern = "/posters/:name" function = posterRoute }
  170. // tracker.worldapi.org#13: every movie / every series, 24 per page — the page is a PATH segment (`/movies/page/2`), a
  171. // page component cannot read `?page=` (hybriel#11) — and the movies the user follows
  172. { pattern = "/movies" component = Movies }
  173. { pattern = "/movies/page/:page" component = Movies }
  174. // tracker.worldapi.org#21 (mission 068): series and shows split — /series lists the series, /shows the shows; a title's page
  175. // is /movies/<slug>, /series/<slug> or /shows/<slug> (one component; /shows/<slug> is showsRoute above)
  176. { pattern = "/movies/:slug" component = Show }
  177. { pattern = "/series" component = AllSeries }
  178. { pattern = "/series/page/:page" component = AllSeries }
  179. { pattern = "/series/:slug" component = Show }
  180. { pattern = "/shows" component = AllShows }
  181. { pattern = "/shows/page/:page" component = AllShows }
  182. { pattern = "/shows/:slug" function = showsRoute }
  183. { pattern = "/my/movies" component = MyMovies }
  184. { pattern = "/my/unwatched" component = Unwatched }
  185. { pattern = "/my/schedule" component = Schedule }
  186. // #21: /my/series and /my/shows (one component, components/myshows.hl; any other word there is its "Not found")
  187. { pattern = "/my/:tv" component = MyShows }
  188. { pattern = "/unwatched" function = unwatchedMoved }
  189. { pattern = "/schedule" function = scheduleMoved }
  190. // tracker.worldapi.org#14: the search — `/search/<text>` (hl:web gives a page no query string, so not `?q=`)
  191. { pattern = "/search/:q?" component = Search }
  192. { pattern = "/find" function = findRoute }
  193. // tracker.worldapi.org#16: a person's page (the show page's cast and the search link here) and their photo
  194. { pattern = "/person/tmdb/:tmdb" function = guestRoute }
  195. { pattern = "/person/:slug" component = Person }
  196. { pattern = "/profiles/:name" function = profileRoute }
  197. // mission 058 (tracker.worldapi.org#25): a genre's movies and series, like /movies (the page in the path)
  198. { pattern = "/genres/:genre" component = Genre }
  199. { pattern = "/genres/:genre/page/:page" component = Genre }
  200. { pattern = "/genre/:genre" function = genreMoved }
  201. // tracker#32 (mission 031): the main menu's Genres and People, the user menu's Settings
  202. { pattern = "/genres" component = Genres }
  203. // tracker#37 (mission 032): /people = everyone, the one updated last first, 24 per page (the page in the path, like /movies)
  204. { pattern = "/people" component = People }
  205. { pattern = "/people/page/:page" component = People }
  206. { pattern = "/settings" component = Settings }
  207. // tracker.worldapi.org#19 (mission 066): franchises and timelines, the creator's editor (`/franchises/edit` before the slug)
  208. { pattern = "/franchises" component = Franchises }
  209. { pattern = "/franchises/edit" component = FranchiseEdit }
  210. { pattern = "/franchises/:slug" component = Franchise }
  211. { pattern = "/timelines/:tslug" component = Franchise }
  212. { pattern = "/timelines/:slug/edit" component = TimelineEdit }
  213. { pattern = "/" component = Home }
  214. // mission 060 (tracker.worldapi.org#27): a short id → its page (LAST: every named one-segment route above wins)
  215. { pattern = "/:sid" function = shortIdRoute }
  216. ]
  217. // WHO GETS THE PUSH: the login state reaches the tabs of one session (components/main.hl trackerSignedIn/Out).
  218. tagOf = (&session) => { return session != null && session.data != null ? session.data.tag : null }
  219. audience = {
  220. trackerSignedIn = (tag, &session) => { return tag != null && tagOf(session) == tag }
  221. trackerSignedOut = (tag, &session) => { return tag != null && tagOf(session) == tag }
  222. }
  223. // cookies are per host, not per port: an own name keeps this app's session apart from
  224. // ident's own (and from any other worldapi app sharing a dev host), see ident README "Design
  225. // tokens" / hybriel#10 hybriel#17.
  226. sessionCookie = 'trackersid'
  227. // mission 043 (tracker#45): ONE streamed pass per table builds the public lists, the slug maps, the search index, the short ids, the
  228. // cast photos and /people's order (lib/bootscan.hl) — no table is ever held whole in memory
  229. bootScanned = bootScan()
  230. // tracker#30 (mission 025): the slim list caches (lib/shows.hl cardOf / episodeRowsOf) of every followed title, before the first
  231. // /my/ load — not filled by that load
  232. titleCachesStart = now()
  233. titleCachesWarm = warmTitleCaches(allFollowedShowIds())
  234. episodeKeysWarm = warmEpisodeKeys(allWatchedEpisodeIds())
  235. console.log('list caches: ' + titleCachesWarm + ' followed titles, ' + episodeKeysWarm + ' watched episodes in ' + (now() - titleCachesStart) + ' ms')
  236. // tracker#18, ONCE (lib/dailysync.hl moveCopiedSummaries): a `summary` that is only the migrated copy of tmdbSummary is MOVED to
  237. // `migratedSummary` (mission 070: kept, not shown) — the current TMDB text shows; the creator's own texts stay
  238. summariesMoved = moveCopiedSummaries()
  239. 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') }
  240. // mission 066: which timelines every title is in (one scan of the timelines), before the first show page
  241. franchisesReady = ensureFranchises()
  242. console.log('moved slugs: ' + movedSlugCount() + ' (their pages show the keeper)')
  243. // 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
  244. // writes every route into each page's HTML (its client route table) — one per moved slug listed 56 of them, adult titles' among
  245. // them, on every page (#41). /movies/:slug and /series/:slug (component routes, which cannot redirect) find the keeper by the slug
  246. // map (lib/shows.hl showBySlug) and render its page with its canonical address in the head (components/show.hl `__meta` og:url);
  247. // /shows/<slug> (showsRoute, a function route) answers 301. No request tap: the class tap of mission 037 crashed hybriel 06617221
  248. // after ~37 answers.
  249. server = new WebFramework(routes = routes, styles = styles, port = port, sessionCookie = sessionCookie, watchMode = watching)
  250. // ---- THE BACKGROUND JOBS (lib/jobs.hl): the daily TMDB sync, the backfills, the details repair, the credits job, the duplicate
  251. // merge, the short-id backfill, the collection seed, the curated franchise seed — constructing it starts their clocks and logs which ones are off
  252. jobs = new Jobs()
  253. on Error(e) { console.log('error absorbed: ' + e.message) }

Branches

Latest commits

  • ac6268e3mission 046a: re-vendor Hybriel 528bc89f (integration 6): plugins mpackdb/time/web (bin/ git-ignored)mre
  • 322b3293mission 046: photoQueue guard for non-row fetch results (damaged persons index)mre
  • e5b99aecmission 046: photoQueue in slices (people.hl photoQueueStart/Step, jobs.hl photoTick), tests/photoqueue.hlmre
  • 31dcf2admission 045: report, LOGmre
  • 9c3971d0tests/persons-skip-count.hlmre
  • 4d72e365mission 045mre
  • b9cae4c9slices: skip and count non-row values from range(); merge persons pass falls back to iterate; guard testmre
  • 3db7dc31merge w44-jobs-slices into w43-trkmemmre
  • 593dab6fmission 043: report, LOGmre
  • 1a5a4818boot scans back to iterate (slices measured slower: titles 114 s, episodes 141 s, persons failed); lambda per rowmre
  • 03d29893boot scans read primary-key slices (lib/slices.hl from mission 044): iterate is eager too; people view log line back; allShows/allEpisodes stay for toolsmre
  • 23375c58mission 044: report, LOG, STATUSmre
  • c6fd928emission 044: 4096 slices for tables over 200 K rows, 15 ms budget, TRACKER_SLICE_DEPTH for testsmre
  • fb057680mission 044: jobs.hl imports mergeLeft (gate found it), mission file, slices benchmre
  • 0d6293ebmission 043: mission filemre
  • d25bd14amission 044: sliced merge prepare + sliced collections prepare; jobs-dump old/new check + bulk fixturemre
  • 633ee210mission 044: sliced table scans (slices.hl, pk-range slices) for the adult/kind/status/art/credits/details-repair queuesmre
  • 55bbd619boot: one streamed pass per table (lib/bootscan.hl) instead of find(null,null) per module; follows/watches/franchises scans streammre
  • 1d465d3ere-vendor plugins to Hybriel master f9614007 (mpackdb #202 copy fix, libmpackdb sha 6fb3b9d6)mre
  • 6648ba44mission 042: real-browser E2E on ce6f2e0a re-vendor 69/0 at 390 + 1280mre