From 0e0aa25a20a070a8617cf72bc113cd20345b2a10 Mon Sep 17 00:00:00 2001 From: Yevhen Boichuk Date: Wed, 21 Oct 2026 22:18:04 +0300 Subject: [PATCH] fix: sorting after a combined deploy, files with %XX in their name Sorting: PR #50 changed the site and the API in one push, so the Pages and API workflows started together and the mirror read the old Worker, which had no listing.json. The site fell back to the fixed pages, where the sort selector changed nothing. - api.yml starts the Pages deploy after the Worker is live, so the mirror always reads the new one (actions: write, deploy job only). - Without listing.json the selector is hidden instead of doing nothing. Names with a literal escape, e.g. bmp280%2Bbme280_lilka.lua: Keira and the site request the name as written, Pages decodes it and looked for bmp280+bme280_lilka.lua, a 404 (also on the old build.py site). The mirror now also writes the decoded copy; only the file name is decoded, never into another path. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/api.yml | 14 ++++++++++++++ scripts/mirror_api.py | 23 ++++++++++++++++++++--- site/script.js | 3 +++ site/styles.css | 4 ++++ 4 files changed, 41 insertions(+), 3 deletions(-) diff --git a/.github/workflows/api.yml b/.github/workflows/api.yml index 906999c..3ce5a35 100644 --- a/.github/workflows/api.yml +++ b/.github/workflows/api.yml @@ -64,6 +64,10 @@ jobs: timeout-minutes: 15 # Repository settings can require a reviewer for this environment environment: production + permissions: + contents: read + # Only to start the Pages deploy below (workflow_dispatch) + actions: write env: WRANGLER_SEND_METRICS: "false" steps: @@ -102,3 +106,13 @@ jobs: env: CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} run: npx wrangler deploy + + # When one push changes the site and the API, both workflows start at + # once and the mirror can read the old Worker (that is how listing.json + # was missing after the sorting release). Rebuilding the mirror once the + # new Worker is live makes the order right; an unchanged catalog costs + # one request and reuses every file. + - name: Rebuild the Pages mirror from the new Worker + env: + GH_TOKEN: ${{ github.token }} + run: gh workflow run deploy-pages.yml --repo "$GITHUB_REPOSITORY" --ref main diff --git a/scripts/mirror_api.py b/scripts/mirror_api.py index ce8ad55..070e980 100644 --- a/scripts/mirror_api.py +++ b/scripts/mirror_api.py @@ -33,7 +33,7 @@ import os import sys from concurrent.futures import ThreadPoolExecutor -from urllib.parse import quote +from urllib.parse import quote, unquote import requests @@ -53,6 +53,23 @@ def write(out, path, data): f.write(data) +def write_file(out, path, data): + """A static file, plus a copy under its percent-decoded name. + + Some names hold a literal escape, e.g. `bmp280%2Bbme280_lilka.lua`. Keira + and the website request the name as written, and GitHub Pages decodes the + path first, so it looks for `bmp280+bme280_lilka.lua`. The decoded copy is + what that request finds; the literal one stays for encoded requests. + """ + write(out, path, data) + folder, name = path.rsplit("/", 1) + decoded = unquote(name) + # Only the file name is decoded, and never into another path: `%2F..` + # must not write outside the item's folder + if decoded != name and "/" not in decoded and "\\" not in decoded and decoded not in (".", ".."): + write(out, f"{folder}/{decoded}", data) + + def github_output(**values): target = os.environ.get("GITHUB_OUTPUT") if target: @@ -118,12 +135,12 @@ def fetch(job): # Unchanged version: identical bytes are already on Pages r = session.get(path_url(args.pages, path), timeout=120) if r.ok: - write(args.out, path, r.content) + write_file(args.out, path, r.content) counts["pages"] += 1 return r = session.get(path_url(api, path), headers=api_headers, timeout=120) r.raise_for_status() - write(args.out, path, r.content) + write_file(args.out, path, r.content) counts["api"] += 1 errors = [] diff --git a/site/script.js b/site/script.js index e90435d..d227f11 100644 --- a/site/script.js +++ b/site/script.js @@ -624,6 +624,9 @@ class LilkaRepository { try { const listing = await this.loadListing(this.currentType); + // Without listing.json only the fixed pages exist, sorted by id: a + // selector that cannot change anything would only look broken + document.querySelector('.list-toolbar').hidden = !listing; if (listing) { const sorted = this.sortItems(listing); this.totalPages = Math.max(1, Math.ceil(sorted.length / PAGE_SIZE)); diff --git a/site/styles.css b/site/styles.css index b894140..a3e8abb 100644 --- a/site/styles.css +++ b/site/styles.css @@ -1879,3 +1879,7 @@ footer { .rating-star:disabled { cursor: wait; } + +.list-toolbar[hidden] { + display: none; +}