Skip to content

Commit

Permalink
dynamic pages query: support pages 'q' and 'size' params for querying…
Browse files Browse the repository at this point in the history
… pages dynamically

bump version to 2.21.0
  • Loading branch information
ikreymer committed Feb 11, 2025
1 parent 559d31f commit 25e6e69
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@webrecorder/wabac",
"version": "2.20.9.1",
"version": "2.21.0-beta.0",
"main": "index.js",
"type": "module",
"exports": {
Expand Down
10 changes: 10 additions & 0 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,16 @@ class API {
if (!coll) {
return { error: "collection_not_found" };
}
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 q = params._query.get("q");
// @ts-expect-error [TODO] - TS4111 - Property '_query' comes from an index signature, so it must be accessed with ['_query'].
const limit = Number(params._query.get("limit")) || 25;
if (q) {
const pages = await coll.store.queryPages(q, limit);

Check warning on line 306 in src/api.ts

View workflow job for this annotation

GitHub Actions / Test

Unsafe argument of type `any` assigned to a parameter of type `string`
return { pages };
}
}
const pages = await coll.store.getAllPages();
return { pages };
}
Expand Down
34 changes: 34 additions & 0 deletions src/wacz/multiwacz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1240,6 +1240,40 @@ export class MultiWACZ
}
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
async queryPages(urlPrefix: string, limit = 25) : Promise<Record<string, any>[]> {
const params = new URLSearchParams();
params.set("urlPrefix", urlPrefix);
params.set("pageSize", limit + "");
const res = await fetch(this.pagesQuery + "?" + params.toString(), {
headers: this.sourceLoader?.headers,
});
if (res.status !== 200) {
return [];
}
const json = await res.json();
if (!json) {
return [];
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const pages = json.items.map((x: any) => {
x.wacz = x.filename;
const file = this.waczfiles[x.filename];
if (file) {
x.waczhash = file.hash;
}
if (typeof(x.ts) === "string") {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
x.ts = new Date(x.ts).getTime();
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return x;
});

// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return pages;
}

async getWACZFilesForPagesQuery(requestUrl: string) {
const params = new URLSearchParams();
const url = new URL(requestUrl);
Expand Down

0 comments on commit 25e6e69

Please sign in to comment.