Compare commits

..
1 Commits
Author SHA1 Message Date
ztimson a1aa158264 Fix new zim reload
Publish Library / Build NPM Project (push) Successful in 1m25s
Publish Library / Tag Version (push) Successful in 7s
2026-10-05 19:20:08 -04:00
3 changed files with 18 additions and 16 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@ztimson/zim-utils", "name": "@ztimson/zim-utils",
"version": "0.4.9", "version": "0.4.10",
"description": "Native, dependency-light ZIM archive reader/searcher and Kiwix catalog downloader for Node.js", "description": "Native, dependency-light ZIM archive reader/searcher and Kiwix catalog downloader for Node.js",
"author": "Zak Timson", "author": "Zak Timson",
"license": "MIT", "license": "MIT",
+8 -2
View File
@@ -80,10 +80,16 @@ export class ZimManager {
* KiwixServer's directory watcher does the real reload work in the background; this just waits for it. */ * KiwixServer's directory watcher does the real reload work in the background; this just waits for it. */
async #waitUntilVisible(filename, {expect = true, timeout = VISIBLE_TIMEOUT} = {}) { async #waitUntilVisible(filename, {expect = true, timeout = VISIBLE_TIMEOUT} = {}) {
const deadline = Date.now() + timeout; const deadline = Date.now() + timeout;
const server = await this.#ensureServer();
while (Date.now() < deadline) { while (Date.now() < deadline) {
const local = await this.#rawList(); const local = await this.#rawList();
const present = local.some(l => l.file === filename); const match = local.find(l => l.file === filename);
if (present === expect) return true; if (!expect) {
if (!match) return true;
} else if (match?.name) {
const probe = await fetch(`${server.baseUrl}/content/${encodeURIComponent(match.name)}/`).catch(() => null);
if (probe?.ok) return true;
}
await new Promise(r => setTimeout(r, VISIBLE_POLL_INTERVAL)); await new Promise(r => setTimeout(r, VISIBLE_POLL_INTERVAL));
} }
return false; return false;
+9 -13
View File
@@ -95,20 +95,16 @@ export class KiwixServer {
async #rebuildLibrary() { async #rebuildLibrary() {
if(this.#remote) return; if(this.#remote) return;
await fs.promises.rm(this.#libraryPath, {force: true});
const files = await this.#zimFiles(); const files = await this.#zimFiles();
const tmpPath = `${this.#libraryPath}.tmp-${process.pid}`;
if(!files.length) await fs.promises.rm(tmpPath, {force: true});
return fs.promises.writeFile(this.#libraryPath, KiwixServer.#empty); if(!files.length) {
await fs.promises.writeFile(tmpPath, KiwixServer.#empty);
for(const file of files) } else {
await execFileAsync(this.#bin('kiwix-manage'), [ for(const file of files)
this.#libraryPath, await execFileAsync(this.#bin('kiwix-manage'), [tmpPath, 'add', path.join(this.#dir, file)]);
'add', }
path.join(this.#dir, file), await fs.promises.rename(tmpPath, this.#libraryPath);
]);
} }
async #waitUntilReady() { async #waitUntilReady() {