gitoriaLog in with ident

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitfa1f9dfafa1f9dfatracker#29 (mission 063): unwatched check muted grey outline + check (accent only on hover), watched stays solid — no code regression, the accent outline read as ticked; gate checks real checks visibly (computed style + screenshot pixel) on /my/unwatched, show, movie, /my/movies; gate 266, tests/realdata-063.mjs, README + STATUSmrefa1f9dfa/project.hl

23.7 KB

  1. // project.hl — tracker.worldapi.org: STEP 1 (tracker.worldapi.org#1), an empty shell. Login copied unchanged from
  2. // calendar.worldapi.org (rejected once for a centered sign-in and no header selector — architect, 2026-09-27):
  3. // ident only, no own passwords (README "How apps use ident" of ident.worldapi.org), the identity selector in the
  4. // header (components/main.hl). No shows, no data yet — later steps come from the creator (CONCEPT.md).
  5. //
  6. // the header's ident-selector / "Log in with ident" -> <ident>/login?key=&return=<this app>/login/callback
  7. // /login/callback?ident_code=<code> the app's server exchanges the code for the identity's short id
  8. // (POST <ident>/api/exchange) and signs this app's OWN session in
  9. // (session.user = { id = <users @id> }, users.hl)
  10. // the header's "Log out" button signs this app's session out via the face trackerLogOut (components/main.hl)
  11. // — ident's own session, and the browser's ident cookie, are untouched
  12. //
  13. // Config (env; no committed secret — the first deploy registers this app in ident and sets these, done by the
  14. // architect, as with ident's own .env for SMTP):
  15. // TRACKER_PORT (45008), TRACKER_URL (this app's own public address, for the return URL),
  16. // IDENT_URL (https://ident.worldapi.org), TRACKER_KEY (pk_…), TRACKER_SECRET (sk_…)
  17. import WebFramework from 'hl:web'
  18. import { Response } from 'hl:http1'
  19. import { randomBytes } from 'hl:crypto'
  20. import { env } from 'hl:proc'
  21. import { readBytes, exists } from 'hl:fs'
  22. import { now, timestamp, every } from 'hl:time'
  23. import Styles from './styles.hl'
  24. import { exchangeCode, ensureUser } from './users.hl'
  25. import Home from './components/home.hl'
  26. import LoginFailed from './components/loginfailed.hl'
  27. import Show from './components/show.hl'
  28. import Unwatched from './components/unwatched.hl'
  29. import Schedule from './components/schedule.hl'
  30. import MyShows from './components/myshows.hl'
  31. import MyMovies from './components/mymovies.hl'
  32. import Movies from './components/movies.hl'
  33. import AllShows from './components/allshows.hl'
  34. import Search from './components/search.hl'
  35. import Person from './components/person.hl'
  36. import Genre from './components/genre.hl'
  37. import { ensureIndex, searchTitleChanged } from './search.hl'
  38. import { syncEnabled, syncShow, persistSync, emptyTotals, addTotals, totalsLine, pauseMsAfter, msPerRequest, adultBackfillQueue, backfillTitle } from './tmdbsync.hl'
  39. import { allFollowedShowIds } from './follows.hl'
  40. import { refreshCatalogShow } from './catalog.hl'
  41. import { ensureShortIds, shortIdStep, shortIdPath, shortIdsLeft, shortIdStats, persistShortIds } from './shortids.hl'
  42. import { dark, darker } from './shared/tokens.hl'
  43. static appTitle = "tracker"
  44. // ---- THE INSTALLABLE APP (tracker.worldapi.org#10), the same way calendar.worldapi.org does it: hl:web's own web app
  45. // manifest (/__hl/manifest.webmanifest, linked from every head with the apple-touch-icon and theme-color) and service
  46. // worker (/__hl/sw.js) from these settings — no JavaScript of ours. Icons in icons/ (icon.svg is the source, the PNGs
  47. // are rendered from it with rsvg-convert, README "Icons"). The theme colour is the header's background (darker), the
  48. // splash background the page's (dark) — both off the tokens, not written out again.
  49. appThemeColor = darker.value
  50. appBackgroundColor = dark.value
  51. appIcons = [
  52. { src = '/icons/icon-192.png' sizes = '192x192' purpose = 'any' }
  53. { src = '/icons/icon-512.png' sizes = '512x512' purpose = 'any' }
  54. { src = '/icons/icon-192.png' sizes = '192x192' purpose = 'maskable' }
  55. { src = '/icons/icon-512.png' sizes = '512x512' purpose = 'maskable' }
  56. ]
  57. appTouchIcon = '/icons/apple-touch-icon.png'
  58. appFavicon = '/icons/favicon.svg'
  59. // OFFLINE: only the shell — the header and `/` (components/main.hl says "You are offline" while the browser has no
  60. // network). The data pages are not kept: without a network they get hl:web's "Unavailable offline" page.
  61. offline = [ Home ]
  62. styles = Styles
  63. port = env('TRACKER_PORT') != null ? toNumber(env('TRACKER_PORT')) : 45008
  64. watching = env('TRACKER_WATCH') != '0'
  65. // read by hl:web's own manifest config (WebFramework.hl `cfg.sessionDir`), not the constructor call below
  66. sessionDir = env('TRACKER_SESSIONS') != null ? env('TRACKER_SESSIONS') : null
  67. // ---- THE LOGIN BUTTON'S RETURN (ident README "How apps use ident"), copied from calendar.worldapi.org's project.hl
  68. // BACK TO THE PAGE: /login.js puts `?next=` into the button's return URL at the click. Only a same-origin PATH
  69. // goes (one `/`, URL-safe characters, ≤ 500). Anything else → `/`.
  70. nextChars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~/?&=%+,;@!$()*:'
  71. safePath = (want) => {
  72. if (want == null || hlTypeName(want) != 'String' || want == '' || want.length > 500) { return '/' }
  73. if (want.slice(0, 1) != '/' || want.slice(0, 2) == '//' || want.slice(0, 7) == '/login/') { return '/' }
  74. let i = 0
  75. while (i < want.length) {
  76. if (!nextChars.includes(want[i])) { return '/' }
  77. i = i + 1
  78. }
  79. return want
  80. }
  81. // A FAILED LOGIN is a page (components/loginfailed.hl): the reason is parked in the session, then → /login/failed
  82. failed = (req, why) => {
  83. let s = req.session
  84. let fresh = s == null
  85. if (fresh) { s = server.sessions.mint() }
  86. s.data.loginError = why
  87. server.sessions.save(s)
  88. let res = new Response('login failed: ' + why, { status = 302 headers = { 'Location' = '/login/failed' 'Cache-Control' = 'no-store' 'Content-Type' = 'text/plain; charset=utf-8' } })
  89. if (fresh) { res.headers['Set-Cookie'] = server.sessions.cookieHeader(s.id) }
  90. return res
  91. }
  92. // the function route gets the cookie's session as req.session (hybriel #11); none yet → minted here
  93. loginCallback = (route, req) => {
  94. if (req.method != 'GET') { return failed(req, 'GET only') }
  95. let q = req.query != null ? req.query : {}
  96. let code = q.ident_code
  97. if (code == null || code == '') { return failed(req, 'ident sent no login code') }
  98. let x = exchangeCode(code)
  99. if (x.error != null) { return failed(req, x.error) }
  100. let u = ensureUser(x.identity)
  101. if (u == null) { return failed(req, 'could not store the user') }
  102. let s = req.session
  103. let fresh = s == null
  104. if (fresh) { s = server.sessions.mint() }
  105. s.user = { id = u.id }
  106. s.data.tag = randomBytes(16)
  107. s.data.loginError = null
  108. server.sessions.save(s)
  109. let res = new Response('logged in', { status = 302 headers = { 'Location' = safePath(q.next) 'Cache-Control' = 'no-store' 'Content-Type' = 'text/plain; charset=utf-8' } })
  110. if (fresh) { res.headers['Set-Cookie'] = server.sessions.cookieHeader(s.id) }
  111. return res
  112. }
  113. // ---- /posters/<name> (tracker.worldapi.org#4): a show's poster image, served dynamically from
  114. // storage/mpackdb/posters/ (the poster's file name is the show's oldId + its migrated extension,
  115. // shows.hl posterName) — falls back to a placeholder svg when the real file isn't there yet (the
  116. // mongo export never included the actual poster bytes, see the report's `open`).
  117. postersDir = (env('TRACKER_STORAGE') != null ? env('TRACKER_STORAGE') : './storage/mpackdb') + '/posters'
  118. placeholderPoster = './assets/poster-placeholder.svg'
  119. posterNameChars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-_'
  120. isSafePosterName = (name) => {
  121. if (name == null || hlTypeName(name) != 'String' || name == '' || name.length > 100) { return false }
  122. let i = 0
  123. while (i < name.length) {
  124. if (!posterNameChars.includes(name[i])) { return false }
  125. i = i + 1
  126. }
  127. return true
  128. }
  129. endsWithStr = (s, suffix) => { return s.length >= suffix.length && s.slice(s.length - suffix.length) == suffix }
  130. mimeOfPoster = (name) => {
  131. if (endsWithStr(name, '.png')) { return 'image/png' }
  132. if (endsWithStr(name, '.webp')) { return 'image/webp' }
  133. if (endsWithStr(name, '.svg')) { return 'image/svg+xml' }
  134. return 'image/jpeg'
  135. }
  136. posterRoute = (route, req) => {
  137. let name = route.params != null ? route.params.name : null
  138. if (!isSafePosterName(name)) { return new Response('bad poster name', { status = 400 headers = { 'Content-Type' = 'text/plain; charset=utf-8' } }) }
  139. let path = postersDir + '/' + name
  140. if (exists(path)) { return new Response(readBytes(path), { headers = { 'Content-Type' = mimeOfPoster(name) 'Cache-Control' = 'public, max-age=86400' } }) }
  141. return new Response(readBytes(placeholderPoster), { headers = { 'Content-Type' = 'image/svg+xml' 'Cache-Control' = 'public, max-age=3600' } })
  142. }
  143. // ---- /profiles/<name> (tracker.worldapi.org#16): a person's photo, from storage/mpackdb/profiles/ (people.hl syncProfile
  144. // downloads it on the first visit of the person page) — the same checks and placeholder as /posters/<name>
  145. profilesDir = (env('TRACKER_STORAGE') != null ? env('TRACKER_STORAGE') : './storage/mpackdb') + '/profiles'
  146. profileRoute = (route, req) => {
  147. let name = route.params != null ? route.params.name : null
  148. if (!isSafePosterName(name)) { return new Response('bad photo name', { status = 400 headers = { 'Content-Type' = 'text/plain; charset=utf-8' } }) }
  149. let path = profilesDir + '/' + name
  150. if (exists(path)) { return new Response(readBytes(path), { headers = { 'Content-Type' = mimeOfPoster(name) 'Cache-Control' = 'public, max-age=86400' } }) }
  151. return new Response(readBytes(placeholderPoster), { headers = { 'Content-Type' = 'image/svg+xml' 'Cache-Control' = 'public, max-age=3600' } })
  152. }
  153. // ---- the old addresses of the personal lists (tracker.worldapi.org#8): they all live under /my/ now —
  154. // a permanent redirect so old links keep working (architect's decision)
  155. movedTo = (path) => { return new Response('moved to ' + path, { status = 301 headers = { 'Location' = path 'Content-Type' = 'text/plain; charset=utf-8' } }) }
  156. unwatchedMoved = (route, req) => { return movedTo('/my/unwatched') }
  157. scheduleMoved = (route, req) => { return movedTo('/my/schedule') }
  158. // mission 058: the show page's genre pills linked `/genre/<x>` (no page there) — the genre pages are `/genres/<x>`
  159. genreMoved = (route, req) => {
  160. let g = route.params != null ? route.params.genre : null
  161. return movedTo(isSafePosterName(g) ? '/genres/' + g : '/')
  162. }
  163. // mission 060 (tracker.worldapi.org#27): `/<shortId>` → 301 to the title's or person's page (shortids.hl); upper case is
  164. // read as lower case; anything else is a 404
  165. shortIdRoute = (route, req) => {
  166. let sid = route.params != null ? route.params.sid : null
  167. let path = sid != null && hlTypeName(sid) == 'String' ? shortIdPath(sid.toLowerCase()) : null
  168. if (path == null) { return new Response('not found', { status = 404 headers = { 'Content-Type' = 'text/plain; charset=utf-8' } }) }
  169. return movedTo(path)
  170. }
  171. routes = [
  172. { pattern = "/favicon.ico" file = "./icons/favicon.ico" headers = { 'Cache-Control' = 'no-cache' } }
  173. // the installable app (tracker.worldapi.org#10): the icons (manifest and service worker are hl:web's own, from appIcons / offline)
  174. { pattern = "/icons/icon-192.png" file = "./icons/icon-192.png" headers = { 'Cache-Control' = 'no-cache' } }
  175. { pattern = "/icons/icon-512.png" file = "./icons/icon-512.png" headers = { 'Cache-Control' = 'no-cache' } }
  176. { pattern = "/icons/apple-touch-icon.png" file = "./icons/apple-touch-icon.png" headers = { 'Cache-Control' = 'no-cache' } }
  177. { pattern = "/icons/favicon.svg" file = "./icons/favicon.svg" headers = { 'Cache-Control' = 'no-cache' } }
  178. { pattern = "/login/callback" function = loginCallback }
  179. { pattern = "/login/failed" component = LoginFailed }
  180. { pattern = "/login.js" file = "./login.js" headers = { 'Cache-Control' = 'no-cache' } }
  181. { pattern = "/posters/:name" function = posterRoute }
  182. // tracker.worldapi.org#13: every movie / every series, 24 per page — the page is a PATH segment (`/movies/page/2`), a
  183. // page component cannot read `?page=` (hybriel#11) — and the movies the user follows
  184. { pattern = "/movies" component = Movies }
  185. { pattern = "/movies/page/:page" component = Movies }
  186. { pattern = "/shows" component = AllShows }
  187. { pattern = "/shows/page/:page" component = AllShows }
  188. { pattern = "/shows/:slug" component = Show }
  189. { pattern = "/my/shows" component = MyShows }
  190. { pattern = "/my/movies" component = MyMovies }
  191. { pattern = "/my/unwatched" component = Unwatched }
  192. { pattern = "/my/schedule" component = Schedule }
  193. { pattern = "/unwatched" function = unwatchedMoved }
  194. { pattern = "/schedule" function = scheduleMoved }
  195. // tracker.worldapi.org#14: the search — `/search/<text>` (hl:web gives a page no query string, so not `?q=`)
  196. { pattern = "/search/:q?" component = Search }
  197. // tracker.worldapi.org#16: a person's page (the show page's cast and the search link here) and their photo
  198. { pattern = "/person/:slug" component = Person }
  199. { pattern = "/profiles/:name" function = profileRoute }
  200. // mission 058 (tracker.worldapi.org#25): a genre's movies and series, like /movies (the page in the path)
  201. { pattern = "/genres/:genre" component = Genre }
  202. { pattern = "/genres/:genre/page/:page" component = Genre }
  203. { pattern = "/genre/:genre" function = genreMoved }
  204. { pattern = "/" component = Home }
  205. // mission 060 (tracker.worldapi.org#27): a short id → its page (LAST: every named one-segment route above wins)
  206. { pattern = "/:sid" function = shortIdRoute }
  207. ]
  208. // WHO GETS THE PUSH: the login state reaches the tabs of one session (components/main.hl trackerSignedIn/Out).
  209. tagOf = (session) => { return session != null && session.data != null ? session.data.tag : null }
  210. audience = {
  211. trackerSignedIn = (tag, session) => { return tag != null && tagOf(session) == tag }
  212. trackerSignedOut = (tag, session) => { return tag != null && tagOf(session) == tag }
  213. }
  214. // cookies are per host, not per port: an own name keeps this app's session apart from
  215. // ident's own (and from any other worldapi app sharing a dev host), see ident README "Design
  216. // tokens" / hybriel#10 hybriel#17.
  217. sessionCookie = 'trackersid'
  218. // tracker.worldapi.org#14: the search index (search.hl) is built once here at boot (~0.6 s on the real data), not by the
  219. // first search
  220. searchIndexReady = ensureIndex()
  221. // mission 060: every short id in use (one map over shows AND persons) and the records still without one, before the first request
  222. shortIdsReady = ensureShortIds()
  223. server =new WebFramework(routes = routes, styles = styles, port = port, sessionCookie = sessionCookie, watchMode = watching)
  224. // ---- THE DAILY TMDB SYNC (tracker.worldapi.org#9, tmdbsync.hl) --------------------------------------
  225. // Once a day at TRACKER_SYNC_HOUR (UTC, default 4 — hl:time has no time zones; the container runs UTC) every
  226. // followed show is synced from TMDB. hl:web serves ONE request at a time, so the run never takes the server
  227. // for itself: a 1-second clock does ONE show per tick (1–3 TMDB requests + maybe its poster) and returns — the
  228. // requests that queued meanwhile are served between two ticks, and a tick never starts inside a page render.
  229. // After a show that made n requests the next waits n × 260 ms (TMDB: ≤ 40 requests / 10 s) + 550 ms per TVmaze lookup
  230. // (≤ 20 / 10 s, tracker.worldapi.org#12).
  231. // TRACKER_SYNC=0 switches it off; without TMDB_READ_TOKEN it is off too (logged once).
  232. syncHour = env('TRACKER_SYNC_HOUR') != null ? toNumber(env('TRACKER_SYNC_HOUR')) : 4
  233. syncOn = env('TRACKER_SYNC') != '0' && syncEnabled
  234. syncQueue = []
  235. syncAt = 0
  236. syncDay = ''
  237. syncNextAt = 0
  238. syncTotals = emptyTotals()
  239. syncTick = () => {
  240. let t = now()
  241. if (syncQueue.length == 0) {
  242. let stamp = timestamp(t)
  243. let day = stamp.slice(0, 10)
  244. if (toNumber(stamp.slice(11, 13)) != syncHour || day == syncDay) { return null }
  245. syncDay = day
  246. syncQueue = allFollowedShowIds()
  247. syncAt = t
  248. syncNextAt = 0
  249. syncTotals = emptyTotals()
  250. console.log('tmdb sync: start, ' + syncQueue.length + ' followed shows')
  251. return null
  252. }
  253. if (t < syncNextAt) { return null }
  254. let id = syncQueue[0]
  255. let rest = []
  256. let i = 1
  257. while (i < syncQueue.length) { rest.push(syncQueue[i]) i = i + 1 }
  258. syncQueue = rest
  259. let r = syncShow(id)
  260. // the public lists (catalog.hl, tracker.worldapi.org#13): this show's place by its newest released episode; the sync
  261. // also brings TMDB's adult flag (mission 054) → the search's view of it too
  262. refreshCatalogShow(id)
  263. searchTitleChanged(id)
  264. let took = now() - t
  265. syncTotals = addTotals(syncTotals, r)
  266. if (r.error != '') { console.log('tmdb sync: ' + r.error) }
  267. // a step blocks every request meanwhile (Saturday Night Live, 53 seasons, 4 requests: ~1.7 s) — say so in the log
  268. if (took > 1500) { console.log('tmdb sync: slow step, show ' + id + ', ' + r.requests + ' requests, ' + took + ' ms') }
  269. syncNextAt = now() + pauseMsAfter(r)
  270. if (syncQueue.length == 0 || syncTotals.shows % 10 == 0) { persistSync() }
  271. if (syncQueue.length == 0) { console.log('tmdb sync done: ' + totalsLine(syncTotals) + ' seconds=' + ((now() - syncAt) / 1000)) }
  272. return null
  273. }
  274. // ---- THE ADULT-FLAG BACKFILL (mission 054, tmdbsync.hl backfillTitle) -----------------------------------
  275. // The public lists and the search show only titles TMDB says are not adult (shows.hl isPublicTitle; unknown = hidden). At
  276. // start the app collects every title whose flag is still unknown and asks TMDB for ONE title per step — like the daily
  277. // sync, on the same clock, so requests queued meanwhile are served between two steps: one details request (adult,
  278. // poster_path, external ids) + the poster file when missing, then a pause of 260 ms per TMDB API request (≤ 40 / 10 s;
  279. // the poster comes from TMDB's image host, not the API, and is not counted). Each answered title goes into the lists
  280. // (catalog.hl refreshCatalogShow) and the search at once. RESUMES after a restart: the queue is built from what is
  281. // still unknown. Stops when the queue is empty; titles TMDB answers 404 for are marked (`adultCheck`) and stay hidden; a
  282. // passing failure (no answer, 429, 5xx) goes to the back of the queue, at most 2 more tries per start.
  283. // While the daily sync runs, the backfill waits. Log: start, every TRACKER_BACKFILL_LOG_EVERY (500) titles, done.
  284. // TRACKER_BACKFILL=0 switches it off; without TMDB_READ_TOKEN it is off too.
  285. backfillOn = env('TRACKER_BACKFILL') != '0' && syncEnabled
  286. backfillLogEvery = env('TRACKER_BACKFILL_LOG_EVERY') != null ? toNumber(env('TRACKER_BACKFILL_LOG_EVERY')) : 500
  287. backfillQueue = null
  288. backfillPos = 0
  289. backfillDone = false
  290. backfillAt = 0
  291. backfillNextAt = 0
  292. backfillTries = {}
  293. backfillTotals = { titles = 0 adult = 0 notAdult = 0 unknown = 0 posters = 0 ids = 0 requests = 0 errors = 0 retries = 0 }
  294. backfillLine = () => {
  295. let b = backfillTotals
  296. return b.titles + '/' + backfillQueue.length + ' titles, adult=' + b.adult + ' notAdult=' + b.notAdult + ' unknown=' + b.unknown + ' posters=' + b.posters
  297. + ' ids=' + b.ids + ' requests=' + b.requests + ' errors=' + b.errors + ' retries=' + b.retries + ' seconds=' + ((now() - backfillAt) / 1000)
  298. }
  299. backfillTick = () => {
  300. if (backfillDone) { return null }
  301. let t = now()
  302. if (backfillQueue == null) {
  303. backfillQueue = adultBackfillQueue()
  304. backfillAt = t
  305. console.log('adult backfill: start, ' + backfillQueue.length + ' titles without an adult flag (' + (now() - t) + ' ms to find them)')
  306. if (backfillQueue.length == 0) { backfillDone = true console.log('adult backfill: nothing to do') }
  307. return null
  308. }
  309. if (t < backfillNextAt) { return null }
  310. let id = backfillQueue[backfillPos]
  311. backfillPos = backfillPos + 1
  312. let r = backfillTitle(id)
  313. if (r.retry && (backfillTries[id] == null || backfillTries[id] < 2)) {
  314. backfillTries[id] = backfillTries[id] == null ? 1 : backfillTries[id] + 1
  315. let q = backfillQueue
  316. q.push(id)
  317. backfillQueue = q
  318. backfillTotals.retries = backfillTotals.retries + 1
  319. } else {
  320. backfillTotals.titles = backfillTotals.titles + 1
  321. if (r.adult == true) { backfillTotals.adult = backfillTotals.adult + 1 } else if (r.adult == false) { backfillTotals.notAdult = backfillTotals.notAdult + 1 } else { backfillTotals.unknown = backfillTotals.unknown + 1 }
  322. }
  323. backfillTotals.posters = backfillTotals.posters + r.posters
  324. backfillTotals.ids = backfillTotals.ids + r.ids
  325. backfillTotals.requests = backfillTotals.requests + r.requests
  326. backfillTotals.errors = backfillTotals.errors + r.errors
  327. if (r.error != '') { console.log('adult backfill: ' + r.error) }
  328. if (r.adult != null) {
  329. refreshCatalogShow(id)
  330. searchTitleChanged(id)
  331. }
  332. let took = now() - t
  333. if (took > 1500) { console.log('adult backfill: slow step, show ' + id + ', ' + took + ' ms') }
  334. backfillNextAt = now() + r.requests * msPerRequest
  335. let finished = backfillPos >= backfillQueue.length
  336. if (finished || backfillPos % 25 == 0) { persistSync() }
  337. if (!finished && backfillTotals.titles > 0 && backfillTotals.titles % backfillLogEvery == 0 && !r.retry) { console.log('adult backfill: ' + backfillLine()) }
  338. if (finished) {
  339. backfillDone = true
  340. console.log('adult backfill done: ' + backfillLine())
  341. }
  342. return null
  343. }
  344. // ONE clock for both (a tick every 0.1 s): the daily sync's step once a second as before; the backfill's steps in between,
  345. // only while no daily run is going on
  346. clockOn = syncOn || backfillOn
  347. clockTicks = 0
  348. if (syncOn) { console.log('tmdb sync: daily at ' + syncHour + ':00 UTC') } else { console.log('tmdb sync: off (' + (syncEnabled ? 'TRACKER_SYNC=0' : 'no TMDB_READ_TOKEN') + ')') }
  349. if (!backfillOn) { console.log('adult backfill: off (' + (syncEnabled ? 'TRACKER_BACKFILL=0' : 'no TMDB_READ_TOKEN') + ')') }
  350. if (clockOn) {
  351. syncClock = every(0.1)
  352. on syncClock.tick(x) {
  353. clockTicks = clockTicks + 1
  354. let busy = syncQueue.length > 0
  355. if (syncOn && clockTicks % 10 == 0) { syncTick() }
  356. if (backfillOn && !busy && syncQueue.length == 0) { backfillTick() }
  357. return null
  358. }
  359. }
  360. // ---- THE SHORT-ID BACKFILL (mission 060, tracker.worldapi.org#27, shortids.hl shortIdStep) ----------------------------
  361. // Every show and person without a short id gets one in the background: on its own clock (every 0.1 s) ONE batch per tick,
  362. // as many records as fit into TRACKER_SHORTID_BUDGET_MS (default 40 ms) — no TMDB, only the tables — so a page waits at
  363. // most one batch. The queue is built at start (`ensureShortIds`) from what is still missing = it resumes after a restart.
  364. // Persisted every 20 batches and at the end. Log: start, every TRACKER_SHORTID_LOG_EVERY (5000) records, done; with nothing
  365. // to do one line. TRACKER_SHORTIDS=0 switches it off (the gate's resume check).
  366. shortIdOn = env('TRACKER_SHORTIDS') != '0'
  367. shortIdBudget = env('TRACKER_SHORTID_BUDGET_MS') != null ? toNumber(env('TRACKER_SHORTID_BUDGET_MS')) : 40
  368. shortIdLogEvery = env('TRACKER_SHORTID_LOG_EVERY') != null ? toNumber(env('TRACKER_SHORTID_LOG_EVERY')) : 5000
  369. shortIdRun = { at = 0 batches = 0 assigned = 0 nextLog = 0 slowest = 0 slowestPersist = 0 done = false }
  370. shortIdTick = () => {
  371. if (shortIdRun.done) { return null }
  372. let t = now()
  373. let r = shortIdStep(shortIdBudget)
  374. let took = now() - t
  375. shortIdRun.batches = shortIdRun.batches + 1
  376. shortIdRun.assigned = shortIdRun.assigned + r.assigned
  377. if (took > shortIdRun.slowest) { shortIdRun.slowest = took }
  378. if (r.done || shortIdRun.batches % 20 == 0) {
  379. let tp = now()
  380. persistShortIds()
  381. if (now() - tp > shortIdRun.slowestPersist) { shortIdRun.slowestPersist = now() - tp }
  382. }
  383. if (!r.done && shortIdRun.assigned >= shortIdRun.nextLog) {
  384. console.log('short ids: ' + shortIdRun.assigned + ' assigned, ' + r.left + ' left, ' + ((now() - shortIdRun.at) / 1000) + ' s')
  385. shortIdRun.nextLog = shortIdRun.nextLog + shortIdLogEvery
  386. }
  387. if (r.done) {
  388. shortIdRun.done = true
  389. let s = shortIdStats()
  390. console.log('short ids done: assigned=' + shortIdRun.assigned + ' oldKept=' + s.oldKept + ' batches=' + shortIdRun.batches + ' slowestBatchMs=' + shortIdRun.slowest + ' slowestPersistMs=' + shortIdRun.slowestPersist + ' seconds=' + ((now() - shortIdRun.at) / 1000))
  391. }
  392. return null
  393. }
  394. if (!shortIdOn) { console.log('short ids: backfill off (TRACKER_SHORTIDS=0), ' + shortIdsLeft() + ' records without one') }
  395. else if (shortIdsLeft() == 0) { console.log('short ids: nothing to do') }
  396. else {
  397. shortIdRun.at = now()
  398. shortIdRun.nextLog = shortIdLogEvery
  399. console.log('short ids: backfill start, ' + shortIdsLeft() + ' records, ' + shortIdBudget + ' ms per batch')
  400. shortIdClock = every(0.1)
  401. on shortIdClock.tick(x) {
  402. shortIdTick()
  403. return null
  404. }
  405. }
  406. on Error(e) { console.log('error absorbed: ' + e.message) }

Branches

Latest commits

  • fa1f9dfatracker#29 (mission 063): unwatched check muted grey outline + check (accent only on hover), watched stays solid — no code regression, the accent outline read as ticked; gate checks real checks visibly (computed style + screenshot pixel) on /my/unwatched, show, movie, /my/movies; gate 266, tests/realdata-063.mjs, README + STATUSmre
  • d8b12d67tracker#27 (mission 060): short ids for movies, series and persons — old 702 kept (data/old-short-ids.json), new random [a-z0-9]{5} unique across both, claimed at creation, background backfill (resumes), shown under poster/photo, /<shortId> → 301; gate 259, tests/realdata-060*, README + STATUSmre
  • f14db671tracker#22-#25 (mission 058): episode air dates, season check = all episodes watched, movie watched check (+ /my/movies count), /genres/<genre> pages (movies + series, newest first, paginated); gate 238, tests/realdata-058.mjs, README + STATUSmre
  • 1704ec45tracker#17 (mission 057): season caret down/up, skeleton rows while a season loads, sessionless showSeasonEpisodes face (no page re-mount), client-only close; gate 214, tests/realdata-057.mjs, README + STATUSmre
  • f2fe3e36mission 056: README + STATUS (merge, fixes, Hybriel 8590df63, real-data check), tests/realdata-056.mjs, tools/check-public-slugs.hlmre
  • f40c250emission 056: re-vendor hybriel master 8590df63 (#121, #122); an adult title's page is Not found for non-followers; gate: leave the page before stopping the servermre
  • 2b7fdd6cmission 056: signed-out header one row on phones ("Log in", nowrap), backfill skips adult titles' posters, gate checksmre
  • 2c53d5efMerge branch 't16-person' (tracker#16 person pages) into main; filmography shows only public titles (054 adult flag), gate race fix (backfill start line)mre
  • c171227emission 054: hide adult/unknown titles from the public lists and the search; in-app adult-flag backfill (TMDB details + poster per title, resumes), gate + real-data proofmre
  • 139fafd8tracker#16: short bio (4 lines, click = all), real-data check script, README + STATUSmre
  • 93be9476tracker#16: person pages /person/<slug> with the filmography fetched from TMDB on the first visit (step by step), gatemre
  • 47a3cae6STATUS: mission 053 merge commit idsmre
  • dcc5eecaMerge branch 't14-search'mre
  • 03edc783Merge branch 't15-tvmaze'mre
  • 71b46345tracker#15: numbering check by date or title, placeholder titles in other languages, docs + real-data proofmre
  • 6bb2daf1tracker#13: homepage (tiles, intro, latest movies/shows), /shows, /movies/page/N, /my/movies; lists cached in memorymre
  • b8bd1157tracker#14: README + STATUS (search, real-data numbers, gate, merge notes)mre
  • 65c694a8tracker#14: search — header magnifier, /search/<text> (in-memory word-prefix index over titles + people), Fetch from web (TMDB search/multi, ours left out), Add = import via syncShow; gate +25 checks, real-data scriptmre
  • 34f2c15btracker#15: TVmaze merge in the sync (gaps only: new episodes/seasons, empty titles/air dates; numbering check), fake TVmaze episodes + gatemre
  • cbdc4ea7tracker#12: link icons TMDB/IMDb/TVDB/TVmaze; sync fills missing ids (TVmaze lookup); movies fetched via /movie/mre