generated from ztimson/template
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a1aa158264 |
+1
-1
@@ -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
@@ -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;
|
||||||
|
|||||||
+8
-12
@@ -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);
|
||||||
|
} else {
|
||||||
for(const file of files)
|
for(const file of files)
|
||||||
await execFileAsync(this.#bin('kiwix-manage'), [
|
await execFileAsync(this.#bin('kiwix-manage'), [tmpPath, 'add', path.join(this.#dir, file)]);
|
||||||
this.#libraryPath,
|
}
|
||||||
'add',
|
await fs.promises.rename(tmpPath, this.#libraryPath);
|
||||||
path.join(this.#dir, file),
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async #waitUntilReady() {
|
async #waitUntilReady() {
|
||||||
|
|||||||
Reference in New Issue
Block a user