|
|
|
|
@@ -10,7 +10,7 @@ import {zimCatalog, zimCatalogInfo, CATALOG_URL} from './catalog.js';
|
|
|
|
|
export class ZimManager {
|
|
|
|
|
#catalogUrl;
|
|
|
|
|
#dir;
|
|
|
|
|
server;
|
|
|
|
|
#server;
|
|
|
|
|
#ownsServer;
|
|
|
|
|
|
|
|
|
|
/** @param {{catalog?: string, server?: KiwixServer, port?: number, host?: string, binDir?: string, url?: string}} [opts]
|
|
|
|
|
@@ -21,15 +21,15 @@ export class ZimManager {
|
|
|
|
|
this.#catalogUrl = catalog;
|
|
|
|
|
this.#dir = dir;
|
|
|
|
|
this.#ownsServer = !server;
|
|
|
|
|
this.server = server ?? new KiwixServer(dir, {port, host, binDir, url});
|
|
|
|
|
this.#server = server ?? new KiwixServer(dir, {port, host, binDir, url});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** The KiwixServer backing this manager - reuse it directly for content/search access, or pass into another ZimManager. */
|
|
|
|
|
get server() { return this.server; }
|
|
|
|
|
get server() { return this.#server; }
|
|
|
|
|
|
|
|
|
|
async #ensureServer() {
|
|
|
|
|
if (!this.server.running) await this.server.start();
|
|
|
|
|
return this.server;
|
|
|
|
|
if (!this.#server.running) await this.#server.start();
|
|
|
|
|
return this.#server;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async #download(url, destPath) {
|
|
|
|
|
@@ -74,7 +74,7 @@ export class ZimManager {
|
|
|
|
|
|
|
|
|
|
/** Stops the internally-owned KiwixServer, if this manager created its own (no-op if one was passed in). */
|
|
|
|
|
async close() {
|
|
|
|
|
if (this.#ownsServer) await this.server.stop();
|
|
|
|
|
if (this.#ownsServer) await this.#server.stop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async delete(nameOrFile) {
|
|
|
|
|
|