gitoria
All repositories: gitoria
5.8 KB
// lib/util.hl — small helpers every topic shares: env, the storage folder, the addresses (main / repo), lists, text// checks, the newest-first sort, Vienna time. Statics only; no topic logic here.import { env } from 'hl:proc'import { timestamp } from 'hl:time'// a newline (the language has no \n escape in a string: a literal line break, as in tickets mdview.hl)static NL = ""// ---- env and storage -----------------------------------------------------------------------------// Config (environment, or `.env` beside project.hl — never read or printed by workers)static envOr = (name, fallback) => {let v = env(name)return v != null && v.trim() != '' ? v.trim() : fallback}// THE TABLE DIRECTORY of every hl:mpackdb table (GITORIA_STORAGE, default ./storage/mpackdb). A relative path resolves// against the ENTRY SCRIPT's directory (project.hl's) — a tool in tools/ must get an absolute one.static storageDir = envOr('GITORIA_STORAGE', './storage/mpackdb')// ---- the addresses: main = <scheme>://<hostport>, a repo = <scheme>://<slug>.<hostport> ---------// GITORIA_PUBLIC_URL the main address, default https://gitoria.worldapi.org; repos live at <scheme>://<slug>.<host[:port] of this url>static publicUrl = envOr('GITORIA_PUBLIC_URL', 'https://gitoria.worldapi.org')static schemeEnd = publicUrl.indexOf('://')static scheme = publicUrl.slice(0, schemeEnd)static hostPort = publicUrl.slice(schemeEnd + 3).replaceAll('/', '')static hostOnly = hostPort.split(':')[0]static repoOrigin = (slug) => { return scheme + '://' + slug + '.' + hostPort }// the session cookie's Domain: every <slug>.<host> shares the login. A host without a dot (localhost) or// an IP address gets a host-only cookie. GITORIA_COOKIE_DOMAIN overrides ('-' = host-only).static domainFor = (h) => {let given = env('GITORIA_COOKIE_DOMAIN')if (given != null && given != '') { return given == '-' ? '' : given }if (!h.includes('.')) { return '' }let last = h.charCodeAt(h.length - 1)if (last >= 48 && last <= 57) { return '' }return '.' + h}// THE REPO OF A REQUEST HOST (gitoria#16): hl:web hands a page component that declares `host = null` the// request's Host without port (hybriel#74). '' = the main address (or any other host) → the repo list;// else the label before .<hostOnly> (a slug that fails slugError, e.g. x.y, is "No such repository").static slugOfHost = (h) => {if (h == null || hlTypeName(h) != 'String') { return '' }let x = h.toLowerCase()if (x == hostOnly) { return '' }let tail = '.' + hostOnlyreturn x.endsWith(tail) ? x.slice(0, x.length - tail.length) : ''}// ---- lists ---------------------------------------------------------------------------------------// an empty list read from hl:mpackdb comes back without a `.length`: every found list goes through herestatic countOfList = (list) => {if (list == null) { return 0 }let n = list.lengthreturn n == null ? 0 : n}static firstOf = (list) => { return countOfList(list) > 0 ? list[0] : null }// rows newest first by `createdMs` (an insertion sort: no sort(), hybriel #1); sorts its copy and returns itstatic newestFirst = (rows) => {let i = 1while (i < rows.length) {let cur = rows[i]let j = i - 1while (j >= 0 && rows[j].createdMs < cur.createdMs) {rows[j + 1] = rows[j]j = j - 1}rows[j + 1] = curi = i + 1}return rows}// ---- text checks ---------------------------------------------------------------------------------// a short one-line text: trimmed, at most `max` characters, no control characters → null or the complaintstatic plainError = (s, max, what) => {if (s == null || hlTypeName(s) != 'String') { return what + ' must be text' }let t = s.trim()if (t.length > max) { return what + ' is too long (at most ' + max + ' characters)' }let i = 0while (i < t.length) {let c = t.charCodeAt(i)if (c < 32 || c == 127) { return what + ' must be one line without control characters' }i = i + 1}return null}// only lowercase hex (ident's one-time codes are 48 hex)static isHex = (s, max) => {if (s == null || hlTypeName(s) != 'String' || s.length == 0 || s.length > max) { return false }let i = 0while (i < s.length) {let c = s.charCodeAt(i)if (!((c >= 48 && c <= 57) || (c >= 97 && c <= 102))) { return false }i = i + 1}return true}// ---- Vienna time (ticket #10): epoch ms → "YYYY-MM-DD HH:MM" in Europe/Vienna ------------------------// hl:time has no time zones (now() + a UTC timestamp() only; "timezones are a userland// concern" — its header). This is the smallest correct userland rule for Vienna: the EU// rule in force since 1996 — CEST (UTC+2) from the last Sunday of March 01:00 UTC to the// last Sunday of October 01:00 UTC, CET (UTC+1) otherwise. Storage stays epoch ms (UTC);// only the rendering shifts.static DAY = 86400000static HOUR = 3600000// integer division for a >= 0 (the language has `%` but no floor in the core)static idiv = (a, b) => { return (a - a % b) / b }// days since 1970-01-01 of a civil date (H. Hinnant's days_from_civil, years >= 1970)static daysFromCivil = (y, m, d) => {let yy = m <= 2 ? y - 1 : ylet era = idiv(yy, 400)let yoe = yy - era * 400let mp = m > 2 ? m - 3 : m + 9let doy = idiv(153 * mp + 2, 5) + d - 1let doe = yoe * 365 + idiv(yoe, 4) - idiv(yoe, 100) + doyreturn era * 146097 + doe - 719468}// the last Sunday of a 31-day month (March, October), 01:00 UTC, as epoch msstatic lastSundayAt1 = (y, m) => {let days = daysFromCivil(y, m, 31)let wd = (days + 4) % 7 // 0 = Sunday: 1970-01-01 was a Thursdayreturn (days - wd) * DAY + HOUR}static viennaOffset = (ms) => {let y = toNumber(timestamp(ms).slice(0, 4))return ms >= lastSundayAt1(y, 3) && ms < lastSundayAt1(y, 10) ? 2 * HOUR : HOUR}// "YYYY-MM-DD HH:MM", Vienna wall timestatic localStamp = (ms) => {let t = timestamp(ms + viennaOffset(ms))return t.slice(0, 10) + ' ' + t.slice(11, 16)}
Branches
- mainmain branch
Latest commits
- 090a20c6mission 002 (code order) 2/4: one lib/ file per topic — git.hl split into git (calls, branches, init, temp folder) / homepage / code / pulls / releases (+ git-helpers: paths, ids, |||PR/|||RL markers); repos-helpers, tickets-helpers, transport-helpers; util.hl = localtime + env, storage dir, addresses, lists, text checks, one newest-first sort (was 3 copies); the function routes out of project.hl into lib/api.hl (thin; plumbing in api-helpers.hl), sshgate.hl folded into api.hl + sshkeys.hl keyLine + repos.hl mayPush; 'Make main' and the merge answer out of the faces (code.hl makeMain, pulls.hl pullsView), one login helper (users.hl userOfLoginCode); project.hl is the map. Session-writing routes get &req + &server.sessions. gates 200/0, 46/0, 44/0; real-data identical except /login/failed now shows the parked reason for a browser that already had a session (the old copy-of-req lost it)mre
- 110c2799mission 002 (code order) 1/4: .hl files out of the root — lib/ (api, git, localtime, markdown, repos, sshgate, sshkeys, tickets, tokens, transport, users), components/styles.hl; jsoncheck.hl removed (imported nowhere); import paths only. gates 200/0, 46/0, 44/0; real-data reads + writes identicalmre
- fdfb4b1bgitoria: Hybriel master 06617221 (plugin allocators 3a781359 + 413f60e4, mpackdb 2cb7ae5e, http1 773de63e); gates 200/0, 46/0, 44/0mre
- 5b46ac84antcolony#40: LOG.md — missions 069/072 are antcolony missions (report paths on Byrodin)mre
- 5602ff41gitoria: Hybriel master 190aa11d (fc838894 GC correctness, #127 mountKids by reference, #126, #48) — tracker README flat; gates 200/0, 46/0, 44/0mre
- e85eaf01gitoria: 069 round 2 — hybriel 1a096ad3 not adopted (Markdown SSR still grows); browser gate waits for the server-side logout before restartmre
- 09ce4f3fgitoria: mission 069 re-vendor hybriel 8efba065 stopped (big SSR pages grow + slow down); lambda audit clean; old vendor keptmre
- 3dc43108antcolony#40: mission references point to the moved missionsmre
- 8d9450fdantcolony#40: history (LOG.md), worker briefs (missions/) and reports moved here from antcolony, numbered per project; old numbers in antcolony docs/mission-map.mdmre
- 205d5fe4gitoria: Hybriel master ff51cf46; ssh keys/tokens no double rows (session sync); gates follow #20mre
- 9b27cb26gitoria#21: installable app (manifest, service worker, offline start page), own iconmre
- 68dcb603deploy.sh: back up live storage/.sessions/.env before every deploy (newest 5 kept)mre
- e2deed6dgitoria#20: "Add code" only on the Code page of an empty repository, no collapsiblemre
- 8bb97ffddeploy.sh: never send .git or .gitignore to Byrodinmre
- fd981932State of 2026-09-27; bin/ no longer tracked (Hybriel commit is in README)mre
- 4a2d7125initial commitmre