gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitd7232e86d7232e86Merge hm49-styles: tracker#49 first batch of component stylesmred7232e86/project.hl

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

Branches

Latest commits

  • d7232e86Merge hm49-styles: tracker#49 first batch of component stylesmre
  • 079f376dMove seven components' styles into Style blocksmre
  • 17d66feelog: #58 mergedmre
  • 69a6640bMerge hm58-map: tracker#58 project.hl only the mapmre
  • a85f7900Move route logic out of the project mapmre
  • 13dea5belog: #56 live, HM49 and HM58 startedmre
  • a31c8f2fdocs: tracker#36 remaining listmre
  • 975d06d1log: #36 live, DP66 startedmre
  • d6d03fa3mission: T36Bmre
  • e7512d00status: #36 rolled back, retry askedmre
  • c98e2043log: T36A rollbackmre
  • ae905f15Merge t36a: tracker#36 apply rechecks, reportmre
  • 796bfaceT36A: report validated fixes, failed live SSH check and verified rollbackmre
  • 55257852log: #53 live, #56 mergedmre
  • 78b39f1bMerge hm56-rows: tracker#56 list builders insert oncemre
  • 7aea52batmdb fix: protect owners without slugs and record passing gatesmre
  • 9b3c2559tmdb fix: revalidate planned identities and reserve target idsmre
  • 6da612fclog: T36A tool defectmre
  • d56ee0daT36A: report unsafe TMDB apply revalidation and stop before livemre
  • 08e55255log: HM56 done, T36A startedmre