generated from ztimson/template
Fixed server getter
This commit is contained in:
@@ -87,6 +87,7 @@ await server.stop(); // Kill server
|
|||||||
```
|
```
|
||||||
|
|
||||||
#### List Local ZIMs
|
#### List Local ZIMs
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const local = await server.list();
|
const local = await server.list();
|
||||||
[
|
[
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ztimson/zim-utils",
|
"name": "@ztimson/zim-utils",
|
||||||
"version": "0.3.1",
|
"version": "0.3.2",
|
||||||
"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",
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import {zimCatalog, zimCatalogInfo, CATALOG_URL} from './catalog.js';
|
|||||||
export class ZimManager {
|
export class ZimManager {
|
||||||
#catalogUrl;
|
#catalogUrl;
|
||||||
#dir;
|
#dir;
|
||||||
server;
|
#server;
|
||||||
#ownsServer;
|
#ownsServer;
|
||||||
|
|
||||||
/** @param {{catalog?: string, server?: KiwixServer, port?: number, host?: string, binDir?: string, url?: string}} [opts]
|
/** @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.#catalogUrl = catalog;
|
||||||
this.#dir = dir;
|
this.#dir = dir;
|
||||||
this.#ownsServer = !server;
|
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. */
|
/** 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() {
|
async #ensureServer() {
|
||||||
if (!this.server.running) await this.server.start();
|
if (!this.#server.running) await this.#server.start();
|
||||||
return this.server;
|
return this.#server;
|
||||||
}
|
}
|
||||||
|
|
||||||
async #download(url, destPath) {
|
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). */
|
/** Stops the internally-owned KiwixServer, if this manager created its own (no-op if one was passed in). */
|
||||||
async close() {
|
async close() {
|
||||||
if (this.#ownsServer) await this.server.stop();
|
if (this.#ownsServer) await this.#server.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
async delete(nameOrFile) {
|
async delete(nameOrFile) {
|
||||||
|
|||||||
Reference in New Issue
Block a user