gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commita4d1a7d2a4d1a7d2|||PR records: later steps checked, branch auditTrackera4d1a7d2/project.hl

15.1 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. // HTTP redirects / title page adapter lib/redirects.hl · lib/title-route.hl
  28. // shared helpers (env, paths, dates, ids, lists) lib/util.hl
  29. // styles · design tokens · the WorldAPI theme components/styles.hl · shared/tokens.hl · theme/ (never edited here)
  30. //
  31. // Config (env; no committed secret — the first deploy registers this app in ident and sets these, done by the architect, as
  32. // with ident's own .env for SMTP): TRACKER_PORT (45008), TRACKER_URL (this app's own public address, for the return URL),
  33. // IDENT_URL (https://ident.worldapi.org), TRACKER_KEY (pk_…), TRACKER_SECRET (sk_…), TRACKER_STORAGE, TRACKER_SESSIONS,
  34. // TRACKER_WATCH, TMDB_READ_TOKEN; the jobs' switches and limits: lib/jobs.hl (README "Config").
  35. import WebFramework from 'hl:web'
  36. import { env, exit } from 'hl:proc'
  37. import { now, every } 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 { loginCallback, sessionAudience } from './lib/users.hl'
  61. import { posterRoute, profileRoute } from './lib/images.hl'
  62. import { bootStep, bootBegin } from './lib/bootscan.hl'
  63. import { warmTitleCaches, warmEpisodeKeys, movedSlugCount } from './lib/shows.hl'
  64. import { allWatchedEpisodeIds } from './lib/watches.hl'
  65. import { allFollowedShowIds } from './lib/follows.hl'
  66. import { shortIdRoute } from './lib/shortids.hl'
  67. import { guestRoute } from './lib/people.hl'
  68. import { moveCopiedSummaries } from './lib/dailysync.hl'
  69. import { ensureFranchises } from './lib/franchises.hl'
  70. import Jobs from './lib/jobs.hl'
  71. import { findRoute } from './lib/search.hl'
  72. import { unwatchedMoved, scheduleMoved, genreMoved } from './lib/redirects.hl'
  73. import { showsRoute } from './lib/title-route.hl'
  74. import App from './lib/app.hl'
  75. static appTitle = App.appTitle
  76. // ---- THE INSTALLABLE APP (tracker.worldapi.org#10), the same way calendar.worldapi.org does it: hl:web's own web app
  77. // manifest (/__hl/manifest.webmanifest, linked from every head with the apple-touch-icon and theme-color) and service
  78. // worker (/__hl/sw.js) from these settings — no JavaScript of ours. Icons in icons/ (icon.svg is the source, the PNGs
  79. // are rendered from it with rsvg-convert, README "Icons"). The theme colour is the header's background (darker), the
  80. // splash background the page's (dark) — both off the tokens, not written out again.
  81. appThemeColor = darker.value
  82. appBackgroundColor = dark.value
  83. appIcons = [
  84. { src = '/icons/icon-192.png' sizes = '192x192' purpose = 'any' }
  85. { src = '/icons/icon-512.png' sizes = '512x512' purpose = 'any' }
  86. { src = '/icons/icon-192.png' sizes = '192x192' purpose = 'maskable' }
  87. { src = '/icons/icon-512.png' sizes = '512x512' purpose = 'maskable' }
  88. ]
  89. appTouchIcon = '/icons/apple-touch-icon.png'
  90. appFavicon = '/icons/favicon.svg'
  91. // OFFLINE: only the shell — the header and `/` (components/main.hl says "You are offline" while the browser has no
  92. // network). The data pages are not kept: without a network they get hl:web's "Unavailable offline" page.
  93. offline = [ Home ]
  94. styles = Styles
  95. port = env('TRACKER_PORT') != null ? toNumber(env('TRACKER_PORT')) : 45008
  96. watching = env('TRACKER_WATCH') != '0'
  97. // read by hl:web's own manifest config (WebFramework.hl `cfg.sessionDir`), not the constructor call below
  98. sessionDir = env('TRACKER_SESSIONS') != null ? env('TRACKER_SESSIONS') : null
  99. routes = [
  100. { pattern = "/favicon.ico" file = "./icons/favicon.ico" headers = { 'Cache-Control' = 'no-cache' } }
  101. // the installable app (tracker.worldapi.org#10): the icons (manifest and service worker are hl:web's own, from appIcons / offline)
  102. { pattern = "/icons/icon-192.png" file = "./icons/icon-192.png" headers = { 'Cache-Control' = 'no-cache' } }
  103. { pattern = "/icons/icon-512.png" file = "./icons/icon-512.png" headers = { 'Cache-Control' = 'no-cache' } }
  104. { pattern = "/icons/apple-touch-icon.png" file = "./icons/apple-touch-icon.png" headers = { 'Cache-Control' = 'no-cache' } }
  105. { pattern = "/icons/favicon.svg" file = "./icons/favicon.svg" headers = { 'Cache-Control' = 'no-cache' } }
  106. { pattern = "/login/callback" function = loginCallback }
  107. { pattern = "/login/failed" component = LoginFailed }
  108. { pattern = "/login.js" file = "./login.js" headers = { 'Cache-Control' = 'no-cache' } }
  109. { pattern = "/posters/:name" function = posterRoute }
  110. // tracker.worldapi.org#13: every movie / every series, 24 per page — the page is a PATH segment (`/movies/page/2`), a
  111. // page component cannot read `?page=` (hybriel#11) — and the movies the user follows
  112. { pattern = "/movies" component = Movies }
  113. { pattern = "/movies/page/:page" component = Movies }
  114. // tracker.worldapi.org#21 (mission 068): series and shows split — /series lists the series, /shows the shows; a title's page
  115. // is /movies/<slug>, /series/<slug> or /shows/<slug> (one component; /shows/<slug> is showsRoute above)
  116. { pattern = "/movies/:slug" component = Show }
  117. { pattern = "/series" component = AllSeries }
  118. { pattern = "/series/page/:page" component = AllSeries }
  119. { pattern = "/series/:slug" component = Show }
  120. { pattern = "/shows" component = AllShows }
  121. { pattern = "/shows/page/:page" component = AllShows }
  122. { pattern = "/shows/:slug" function = showsRoute }
  123. { pattern = "/my/movies" component = MyMovies }
  124. { pattern = "/my/unwatched" component = Unwatched }
  125. { pattern = "/my/schedule" component = Schedule }
  126. // #21: /my/series and /my/shows (one component, components/myshows.hl; any other word there is its "Not found")
  127. { pattern = "/my/:tv" component = MyShows }
  128. { pattern = "/unwatched" function = unwatchedMoved }
  129. { pattern = "/schedule" function = scheduleMoved }
  130. // tracker.worldapi.org#14: the search — `/search/<text>` (hl:web gives a page no query string, so not `?q=`)
  131. { pattern = "/search/:q?" component = Search }
  132. { pattern = "/find" function = findRoute }
  133. // tracker.worldapi.org#16: a person's page (the show page's cast and the search link here) and their photo
  134. { pattern = "/person/tmdb/:tmdb" function = guestRoute }
  135. { pattern = "/person/:slug" component = Person }
  136. { pattern = "/profiles/:name" function = profileRoute }
  137. // mission 058 (tracker.worldapi.org#25): a genre's movies and series, like /movies (the page in the path)
  138. { pattern = "/genres/:genre" component = Genre }
  139. { pattern = "/genres/:genre/page/:page" component = Genre }
  140. { pattern = "/genre/:genre" function = genreMoved }
  141. // tracker#32 (mission 031): the main menu's Genres and People, the user menu's Settings
  142. { pattern = "/genres" component = Genres }
  143. // tracker#37 (mission 032): /people = everyone, the one updated last first, 24 per page (the page in the path, like /movies)
  144. { pattern = "/people" component = People }
  145. { pattern = "/people/page/:page" component = People }
  146. { pattern = "/settings" component = Settings }
  147. // tracker.worldapi.org#19 (mission 066): franchises and timelines, the creator's editor (`/franchises/edit` before the slug)
  148. { pattern = "/franchises" component = Franchises }
  149. { pattern = "/franchises/page/:page" component = Franchises }
  150. { pattern = "/franchises/edit" component = FranchiseEdit }
  151. { pattern = "/franchises/:slug" component = Franchise }
  152. { pattern = "/timelines/:tslug" component = Franchise }
  153. { pattern = "/timelines/:slug/edit" component = TimelineEdit }
  154. { pattern = "/" component = Home }
  155. // mission 060 (tracker.worldapi.org#27): a short id → its page (LAST: every named one-segment route above wins)
  156. { pattern = "/:sid" function = shortIdRoute }
  157. ]
  158. // WHO GETS THE PUSH: the login state reaches the tabs of one session (components/main.hl trackerSignedIn/Out).
  159. audience = {
  160. trackerSignedIn = sessionAudience
  161. trackerSignedOut = sessionAudience
  162. }
  163. // cookies are per host, not per port: an own name keeps this app's session apart from
  164. // ident's own (and from any other worldapi app sharing a dev host), see ident README "Design
  165. // tokens" / hybriel#10 hybriel#17.
  166. sessionCookie = 'trackersid'
  167. // tracker#30 (mission 025): the slim list caches (lib/shows.hl cardOf / episodeRowsOf) of every followed title, before the first
  168. // /my/ load — not filled by that load
  169. titleCachesStart = now()
  170. titleCachesWarm = warmTitleCaches(allFollowedShowIds())
  171. episodeKeysWarm = warmEpisodeKeys(allWatchedEpisodeIds())
  172. console.log('list caches: ' + titleCachesWarm + ' followed titles, ' + episodeKeysWarm + ' watched episodes in ' + (now() - titleCachesStart) + ' ms')
  173. // tracker#18, ONCE (lib/dailysync.hl moveCopiedSummaries): a `summary` that is only the migrated copy of tmdbSummary is MOVED to
  174. // `migratedSummary` (mission 070: kept, not shown) — the current TMDB text shows; the creator's own texts stay
  175. summariesMoved = moveCopiedSummaries()
  176. 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') }
  177. // mission 066: which timelines every title is in (one scan of the timelines), before the first show page
  178. franchisesReady = ensureFranchises()
  179. // mission 043 (tracker#45): ONE streamed pass per table builds the public lists, the slug maps, the search index, the short ids, the
  180. // cast photos and /people's order (lib/bootscan.hl). Mission T17 (boot time): the pass is resumable — it runs here for up to
  181. // TRACKER_WARM_SYNC_MS (default 1000; the gates give 600000 = a complete start, as before) and, if the tables are bigger, goes
  182. // on from a clock AFTER the server listens (a 5 GB copy: 2.3 M rows, minutes of CPU). Pages that need more than is built say "starting up"
  183. // (components/warm*.hl); the jobs start when the scan is done (lib/jobs.hl needs the complete short-id map and indexes).
  184. warmSyncMs = env('TRACKER_WARM_SYNC_MS') != null ? toNumber(env('TRACKER_WARM_SYNC_MS')) : 1000
  185. warmStepMs = env('TRACKER_WARM_STEP_MS') != null ? toNumber(env('TRACKER_WARM_STEP_MS')) : 60
  186. // (test knob: TRACKER_WARM_HOLD_MS = the clock leaves the scan alone for that long after the server listens; tests/warmstart.mjs)
  187. warmHoldMs = env('TRACKER_WARM_HOLD_MS') != null ? toNumber(env('TRACKER_WARM_HOLD_MS')) : 0
  188. bootDone = false
  189. if (warmSyncMs > 0) { bootDone = bootStep(&warmSyncMs) } else { bootBegin() }
  190. if (bootDone) { console.log('moved slugs: ' + movedSlugCount() + ' (their pages show the keeper)') }
  191. // 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
  192. // writes every route into each page's HTML (its client route table) — one per moved slug listed 56 of them, adult titles' among
  193. // them, on every page (#41). /movies/:slug and /series/:slug (component routes, which cannot redirect) find the keeper by the slug
  194. // map (lib/shows.hl showBySlug) and render its page with its canonical address in the head (components/show.hl `__meta` og:url);
  195. // /shows/<slug> (showsRoute, a function route) answers 301. No request tap: the class tap of mission 037 crashed hybriel 06617221
  196. // after ~37 answers.
  197. server = new WebFramework(routes = routes, styles = styles, port = port, sessionCookie = sessionCookie, watchMode = watching, sessionMaxAge = 3122064000)
  198. // ---- THE BACKGROUND JOBS (lib/jobs.hl): the daily TMDB sync, the backfills, the details repair, the credits job, the duplicate
  199. // merge, the short-id backfill, the collection seed, the curated franchise seed — constructing it starts their clocks and logs which ones are off
  200. jobs = null
  201. if (bootDone) { jobs = new Jobs() }
  202. else {
  203. console.log('boot scan: listening first, the scan goes on in steps of ' + warmStepMs + ' ms')
  204. warmListenAt = now()
  205. warmClock = every(0.004)
  206. on warmClock.tick(x) {
  207. if (bootDone || now() - warmListenAt < warmHoldMs) { return null }
  208. bootDone = bootStep(&warmStepMs)
  209. if (bootDone) {
  210. warmClock.stop()
  211. console.log('moved slugs: ' + movedSlugCount() + ' (their pages show the keeper)')
  212. jobs = new Jobs()
  213. }
  214. return null
  215. }
  216. }
  217. on Error(e) {
  218. if (e.phase == 'startup') { exit(1) }
  219. console.log('error absorbed: ' + e.message)
  220. }

Branches

Latest commits

  • a4d1a7d2|||PR records: later steps checked, branch auditTracker
  • e070e16fMerge branch 'records-dp75' into mainTracker
  • 642b4fa8|||PR records: DP75 day62 live, AP62 briefTracker
  • bfc4ea4dMerge branch 'ap62' into mainTracker
  • 2c95ac46|||PR AP62: re-vendor Hybriel set day62 (source 70341ad2, bin a54f5f08)Tracker
  • b9c7c3c8Merge branch 'records-dp74' into mainTracker
  • 85cfb4ae|||PR records: AP61 day61, DP74 liveTracker
  • b1496147Merge branch 'ap61' into mainTracker
  • 2047955bMerge branch 'u12-gateports' into mainTracker
  • c8da40f3|||PR AP61: re-vendor Hybriel set day61 (source a05af47c, bin a11042e5)Tracker
  • 4e018678|||PR deploy.sh: gates use Tracker's ports 8716-8719 and LC_ALL=C; README: 2 backups keptTracker
  • 0b86324aMerge branch 'records-dp73' into mainTracker
  • 9ce5f59b|||PR records: DP73 live 613ae0e; deploy.sh keeps 2 backupsTracker
  • 613ae0ecMerge branch 'bs3' into mainTracker
  • 1383264b|||PR BS3: keep shared synchronous sorting fastTracker
  • 63e5ba1a|||PR BS3: guard boot imports and share resumable sort buffersTracker
  • 310613f1Merge branch 'records-dp72' into mainTracker
  • 6f7b61ba|||PR records: deploy-swap fix live, Kunibert findingsTracker
  • c41587d2Merge branch 'bs2' into mainTracker
  • 0dd538a6|||PR BS2: finish the boot index in slices so a booting instance keeps answeringTracker