gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit3fb871123fb87112|||PR HM55b record six additional focused toggle bisectsTracker3fb87112/lib/util.hl

3.2 KB

  1. // lib/util.hl — small helpers every topic shares (env, paths, dates, lists, text), each ONCE (mission 028: they were copied
  2. // into follows, users, shows, watches, tmdbsync, catalog, franchises, details, people, merge, search, shortids).
  3. import SortRows from './sort-rows.hl'
  4. import { env } from 'hl:proc'
  5. import { now, timestamp } from 'hl:time'
  6. import { randomBytes } from 'hl:crypto'
  7. import { Response } from 'hl:http1'
  8. // an environment value, trimmed — `fallback` when it is not set or empty
  9. static envOr = (&name, &fallback) => {
  10. v = env(name)
  11. return v != null && v.trim() != '' ? v.trim() : fallback
  12. }
  13. // every table and file of the app's data: TRACKER_STORAGE, else storage/mpackdb beside project.hl (relative paths resolve
  14. // against the ENTRY script)
  15. static storageDir = envOr('TRACKER_STORAGE', './storage/mpackdb')
  16. // the image files: a title's poster (tmdb.hl syncPoster) and a person's photo (people.hl syncProfile), served by images.hl
  17. static postersDir = storageDir + '/posters'
  18. static profilesDir = storageDir + '/profiles'
  19. // a new record id: 16 hex (self-assigned — hl:mpackdb's own generated @id can repeat within one millisecond, hybriel#113)
  20. static newId = () => { return randomBytes(8, 'hex') }
  21. static hexDigits = '0123456789abcdef'
  22. // today as 'YYYY-MM-DD' (UTC, like the rest of the app — hl:time has no time zones)
  23. static todayStr = () => { return timestamp(now()).slice(0, 10) }
  24. // the day `days` from today ('YYYY-MM-DD', UTC; negative = before)
  25. static dayStr = (days) => { return timestamp(now() + days * 86400000).slice(0, 10) }
  26. // a stored date ('YYYY-MM-DD…') or '' when it is none
  27. static dateOr = (&v) => { return v != null && hlTypeName(v) == 'String' && v.length >= 4 ? v : '' }
  28. // a face's text argument: the string itself, '' for anything else (a peer may send a list or an object: `'' + x` then aborts the
  29. // request with a 500 that names the source line)
  30. static textArg = (&v) => { return v != null && hlTypeName(v) == 'String' ? v : '' }
  31. // a text value or null when it is none or only white space (the value itself, not trimmed)
  32. static textOr = (&v) => { return v != null && hlTypeName(v) == 'String' && v.trim() != '' ? v : null }
  33. // an id (a string or a number) that is there
  34. static hasId = (&v) => { return v != null && ('' + v).trim() != '' }
  35. static listOr = (&v) => { return v == null ? [] : v }
  36. static countOfList = (&list) => {
  37. if (list == null) { return 0 }
  38. n = list.length
  39. return n == null ? 0 : n
  40. }
  41. static firstOf = (&list) => { return countOfList(&list) > 0 ? list[0] : null }
  42. // The synchronous entry point uses the same stable natural merge as boot slices.
  43. static sortDesc = (&list) => {
  44. sorter = new SortRows()
  45. for (row of list) { sorter.add(row) }
  46. sorter.step()
  47. out = []
  48. for (let i = 0; i < sorter.count(); i = i + 1) { out.push(sorter.row(i)) }
  49. return out
  50. }
  51. // a permanent redirect (the route adapters: the old /my/ addresses, /shows/<slug> of a series or movie, short ids)
  52. static movedResponse = (&path) => { return new Response('moved to ' + path, { status = 301 headers = { 'Location' = path 'Content-Type' = 'text/plain; charset=utf-8' 'X-Content-Type-Options' = 'nosniff' } }) }
  53. static notFoundText = (&text) => { return new Response(text, { status = 404 headers = { 'Content-Type' = 'text/plain; charset=utf-8' 'X-Content-Type-Options' = 'nosniff' } }) }

Branches

Latest commits

  • 3fb87112|||PR HM55b record six additional focused toggle bisectsTracker
  • 20131f51|||PR HM55b record incomplete episode-toggle bisectTracker
  • 17feb7abHM55 WIP: hm54-fill re-applied on main; browser gate fails at ep3 toggleTracker
  • 28eab08cMerge branch 'records-hm55' into mainTracker
  • d3edaa05|||PR records: HM55 start, PROCEDURES.mdTracker
  • 3059f86cMerge branch 'records-design-rule' into mainTracker
  • 421a4809|||PR records: his-design rule (Apollo 2026-11-13)Tracker
  • d1390692Merge branch 'records-dp75b' into mainTracker
  • 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