Skip to content

Commit

Permalink
pass totalPages in pages api even when no query
Browse files Browse the repository at this point in the history
rename seedPages -> initialPages
  • Loading branch information
ikreymer committed Feb 13, 2025
1 parent 89ddc74 commit c09bed6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ class API {
if (!coll) {
return { error: "collection_not_found" };
}
let total = undefined;
if (coll.store instanceof MultiWACZ) {
// @ts-expect-error [TODO] - TS4111 - Property '_query' comes from an index signature, so it must be accessed with ['_query'].
const search = params._query.get("search");
Expand All @@ -312,10 +313,12 @@ class API {
pageSize,
);
return { pages, total };
} else {
total = coll.store.totalPages;
}
}
const pages = await coll.store.getAllPages();
return { pages };
return { pages, total };
}

case "textIndex": {
Expand Down
14 changes: 10 additions & 4 deletions src/wacz/multiwacz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ export class MultiWACZ

pagesQueryUrl = "";

totalPages?: number = undefined;

preloadResources: string[] = [];
seedPageWACZs: Map<string, Set<string>> = new Map<string, Set<string>>();

Expand Down Expand Up @@ -959,7 +961,7 @@ export class MultiWACZ
async loadWACZFiles(
// [TODO]
// eslint-disable-next-line @typescript-eslint/no-explicit-any
json: { resources: any; seedPages: any; preloadResources: any },
json: { resources: any; initialPages: any; preloadResources: any, totalPages: number },
parent: WACZLoadSource = this,
) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down Expand Up @@ -1009,14 +1011,18 @@ export class MultiWACZ
}
}

if (json.seedPages) {
if (json.initialPages) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
await this.addSeedPages(json.seedPages);
await this.addInitialPages(json.initialPages);
}

if (!isNaN(json.totalPages)) {
this.totalPages = json.totalPages;
}
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
async addSeedPages(pagesImport: Record<string, any>[]) {
async addInitialPages(pagesImport: Record<string, any>[]) {
const pages: PageEntry[] = [];
for (const {
id,
Expand Down

0 comments on commit c09bed6

Please sign in to comment.