mirror of
https://github.com/tiennm99/thptqg.git
synced 2026-10-13 06:15:48 +00:00
fix(web): take the database length from a range probe, not the host
GitHub Pages serves .sqlite3 as application/octet-stream, which mime-db marks compressible, so an un-ranged response comes back gzipped with the compressed length. sql.js-httpvfs sizes a file with a HEAD request, sees that length is unusable and refuses to open the database: Length of the file not known. It must either be supplied in the config or given by the HTTP server. Page reads were never affected. The Fetch standard requires browsers to send Accept-Encoding: identity on any request carrying a Range header, and the live site returns 206 with raw bytes to one. So the length is probed the same way and passed as fileLength, which is the escape hatch the library's own message points at. The probe reads the first 100 bytes, so it also checks the file starts with the SQLite magic and that its page size matches the request size — a host that ever compresses a ranged response now fails with a clear message rather than feeding the library the wrong bytes. The post-deploy check the docs prescribed could not have caught this: a bare `curl -sI` advertises no encoding, so it reports success whatever the host does. It is replaced, in the docs and in CI, by a ranged read that verifies the bytes.
This commit is contained in:
1 parent
3fed50cf8f
commit
9571fb7d55
7 files changed
+253
-12
No files matched your search
@@ -121,3 +121,30 @@ jobs:
|
||||
steps:
|
||||
- id: deployment
|
||||
uses: actions/deploy-pages@v5
|
||||
|
||||
- uses: actions/checkout@v7
|
||||
|
||||
# The site reads the databases a page at a time over range requests, so
|
||||
# what matters is not that the host leaves the file alone in general — it
|
||||
# gzips the un-ranged response, and browsers work around that by sending
|
||||
# Accept-Encoding: identity whenever a request carries a Range header —
|
||||
# but that a ranged read returns raw database bytes. Checking headers is
|
||||
# what missed this before: a bare `curl -sI` advertises no encoding and
|
||||
# so passes whatever the host does. Check the bytes instead.
|
||||
- name: Verify ranged reads return database bytes
|
||||
env:
|
||||
PAGE_URL: ${{ steps.deployment.outputs.page_url }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
for id in $(jq -r '.datasets[].id' datasets.json); do
|
||||
url="${PAGE_URL%/}/db/${id}.sqlite3"
|
||||
if ! magic=$(curl -sf -r 0-14 -H 'Accept-Encoding: identity;q=1, *;q=0' "$url"); then
|
||||
echo "::error::$url is not fetchable"
|
||||
exit 1
|
||||
fi
|
||||
if [ "$magic" != "SQLite format 3" ]; then
|
||||
echo "::error::$url did not return database bytes over a range request"
|
||||
exit 1
|
||||
fi
|
||||
echo "$url: SQLite format 3"
|
||||
done
|
||||
Reference in new issue
Block a user