generated from ztimson/template
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
60bceb195f | ||
|
|
33e4ee35c7 |
Generated
+12
-2
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@ztimson/zim-utils",
|
"name": "@ztimson/zim-utils",
|
||||||
"version": "0.4.8",
|
"version": "0.4.11",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@ztimson/zim-utils",
|
"name": "@ztimson/zim-utils",
|
||||||
"version": "0.4.8",
|
"version": "0.4.11",
|
||||||
"hasInstallScript": true,
|
"hasInstallScript": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -14,6 +14,7 @@
|
|||||||
"adm-zip": "^0.5.18",
|
"adm-zip": "^0.5.18",
|
||||||
"lzma1": "^0.3.0",
|
"lzma1": "^0.3.0",
|
||||||
"tar": "^7.4.3",
|
"tar": "^7.4.3",
|
||||||
|
"undici": "^8.11.2",
|
||||||
"zstd-codec": "^0.1.5"
|
"zstd-codec": "^0.1.5"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -106,6 +107,15 @@
|
|||||||
"node": ">=18"
|
"node": ">=18"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/undici": {
|
||||||
|
"version": "8.11.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/undici/-/undici-8.11.2.tgz",
|
||||||
|
"integrity": "sha512-u4UB2/IrKdU6lFxumHmmo1a3fCQO5tzQllRorfoRS63txhrB7xTpSn1PftwC4qEHkOaqP95fCWW4lJzwErwzhQ==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=22.19.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/var-persist": {
|
"node_modules/var-persist": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/var-persist/-/var-persist-1.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/var-persist/-/var-persist-1.0.1.tgz",
|
||||||
|
|||||||
+4
-3
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ztimson/zim-utils",
|
"name": "@ztimson/zim-utils",
|
||||||
"version": "0.4.11",
|
"version": "0.4.13",
|
||||||
"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",
|
||||||
@@ -16,9 +16,10 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ztimson/utils": "^0.30.9",
|
"@ztimson/utils": "^0.30.9",
|
||||||
|
"adm-zip": "^0.5.18",
|
||||||
"lzma1": "^0.3.0",
|
"lzma1": "^0.3.0",
|
||||||
"tar": "^7.4.3",
|
"tar": "^7.4.3",
|
||||||
"zstd-codec": "^0.1.5",
|
"undici": "^8.11.2",
|
||||||
"adm-zip": "^0.5.18"
|
"zstd-codec": "^0.1.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-4
@@ -5,6 +5,9 @@ import {Readable} from 'node:stream';
|
|||||||
import {PromiseProgress} from '@ztimson/utils';
|
import {PromiseProgress} from '@ztimson/utils';
|
||||||
import {KiwixServer} from './server.js';
|
import {KiwixServer} from './server.js';
|
||||||
import {zimCatalog, zimCatalogInfo, CATALOG_URL} from './catalog.js';
|
import {zimCatalog, zimCatalogInfo, CATALOG_URL} from './catalog.js';
|
||||||
|
import {Agent} from 'undici';
|
||||||
|
|
||||||
|
const agent = new Agent({headersTimeout: 0, bodyTimeout: 0});
|
||||||
|
|
||||||
const VISIBLE_TIMEOUT = 5_000;
|
const VISIBLE_TIMEOUT = 5_000;
|
||||||
const VISIBLE_POLL_INTERVAL = 200;
|
const VISIBLE_POLL_INTERVAL = 200;
|
||||||
@@ -65,13 +68,13 @@ export class ZimManager {
|
|||||||
|
|
||||||
/** Resolves a `.meta4` metalink URL down to the real mirror `.zim` download URL. */
|
/** Resolves a `.meta4` metalink URL down to the real mirror `.zim` download URL. */
|
||||||
async #resolveUrl(url) {
|
async #resolveUrl(url) {
|
||||||
const head = await fetch(url);
|
const head = await fetch(url, {dispatcher: agent});
|
||||||
const ct = head.headers.get('content-type') || '';
|
const ct = head.headers.get('content-type') || '';
|
||||||
if (!ct.includes('metalink') && !url.endsWith('.meta4')) return {res: head, url};
|
if (!ct.includes('metalink') && !url.endsWith('.meta4')) return {res: head, url};
|
||||||
const meta = await head.text();
|
const meta = await head.text();
|
||||||
const m = meta.match(/<url[^>]*>([^<]+\.zim)<\/url>/);
|
const m = meta.match(/<url[^>]*>([^<]+\.zim)<\/url>/);
|
||||||
if (!m) throw new Error('Could not resolve metalink mirror');
|
if (!m) throw new Error('Could not resolve metalink mirror');
|
||||||
const res = await fetch(m[1]);
|
const res = await fetch(m[1], {dispatcher: agent});
|
||||||
return {res, url: m[1]};
|
return {res, url: m[1]};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,7 +131,7 @@ export class ZimManager {
|
|||||||
async catalog(search, opts = {}) {
|
async catalog(search, opts = {}) {
|
||||||
const results = await zimCatalog(search, {url: this.#catalogUrl, ...opts});
|
const results = await zimCatalog(search, {url: this.#catalogUrl, ...opts});
|
||||||
return results.map(entry => this.#active[entry.href]
|
return results.map(entry => this.#active[entry.href]
|
||||||
? {...entry, ...this.#active[entry.href].dl.meta, downloading: true}
|
? {...this.#active[entry.href].dl.meta, ...entry, downloading: true}
|
||||||
: entry);
|
: entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,7 +201,7 @@ export class ZimManager {
|
|||||||
const localNames = new Set(local.map(l => l.name));
|
const localNames = new Set(local.map(l => l.name));
|
||||||
const pending = Object.values(this.#active)
|
const pending = Object.values(this.#active)
|
||||||
.filter(({entry}) => !localNames.has(entry.name))
|
.filter(({entry}) => !localNames.has(entry.name))
|
||||||
.map(({entry, dl}) => ({...entry, ...dl.meta, downloading: true}));
|
.map(({entry, dl}) => ({...dl.meta, ...entry, downloading: true}));
|
||||||
return [...local, ...pending];
|
return [...local, ...pending];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user