Skip to content

Commit 6ef8bf4

Browse files
authored
Support for dynamic page loading for Multi-WACZs (#399)
Support querying pages dynamically via pages endpoint: - If loaded pages < total pages, load additional pages via /pages endpoint if canQueryPages is set to true on item - If query provided, do `/pages?search=...` to search for pages. Use pagination of 25 pages for now. WACZ hash: - if provided, store waczhash per page, and use for thumbnail, favicon and top-level replay loading. Embed: better support for force reloading, call delete with reload directly in embed Depends on webrecorder/wabac.js#220
1 parent 94cbf5e commit 6ef8bf4

File tree

9 files changed

+203
-66
lines changed

9 files changed

+203
-66
lines changed

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "replaywebpage",
33
"productName": "ReplayWeb.page",
4-
"version": "2.2.5",
4+
"version": "2.3.0",
55
"description": "Serverless Web Archive Replay",
66
"repository": "https://github.com/webrecorder/replayweb.page",
77
"homepage": "https://replayweb.page/",
@@ -18,7 +18,7 @@
1818
"dependencies": {
1919
"@fortawesome/fontawesome-free": "^5.15.4",
2020
"@shoelace-style/shoelace": "~2.15.1",
21-
"@webrecorder/wabac": "^2.20.8",
21+
"@webrecorder/wabac": "^2.21.0",
2222
"bulma": "^0.9.3",
2323
"electron-log": "^4.4.1",
2424
"electron-updater": "^6.3.9",

src/embed.ts

+23-9
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import {
77
} from "lit";
88
import { ifDefined } from "lit/directives/if-defined.js";
99

10-
import { wrapCss, updateFaviconLinks } from "./misc";
10+
import { wrapCss, updateFaviconLinks, apiPrefix } from "./misc";
1111
import { SWManager } from "./swmanager";
12-
import { property } from "lit/decorators.js";
12+
import { property, query } from "lit/decorators.js";
1313
import type { FavIconEventDetail } from "./types";
1414
import type { EmbedReplayData, EmbedReplayEvent } from "./item";
1515

@@ -82,6 +82,9 @@ class Embed extends LitElement {
8282

8383
@property({ type: Boolean }) useRuffle = false;
8484

85+
@query("iframe")
86+
private readonly iframe?: HTMLIFrameElement | null;
87+
8588
replayfile = defaultReplayFile;
8689
mainElementName = "replay-app-main";
8790
appName = "ReplayWeb.page";
@@ -126,17 +129,28 @@ class Embed extends LitElement {
126129
}
127130
}
128131

129-
fullReload() {
130-
const iframe = this.renderRoot.querySelector("iframe");
131-
if (iframe?.contentWindow) {
132-
iframe.contentWindow.postMessage({ type: "fullReload" });
132+
async fullReload() {
133+
if (!this.iframe?.contentWindow) {
134+
return false;
133135
}
136+
137+
const deleteURL = apiPrefix + "/c/" + this.coll + "?reload=1";
138+
139+
const resp = await this.iframe.contentWindow.fetch(deleteURL, {
140+
method: "DELETE",
141+
});
142+
143+
if (resp.status !== 200) {
144+
return false;
145+
}
146+
147+
this.iframe.contentWindow.location.reload();
148+
149+
return true;
134150
}
135151

136152
handleMessage(event: IframeMessage) {
137-
const iframe = this.renderRoot.querySelector("iframe");
138-
139-
if (iframe && event.source === iframe.contentWindow) {
153+
if (this.iframe && event.source === this.iframe.contentWindow) {
140154
switch (event.data.type) {
141155
case "urlchange":
142156
if (this.deepLink) {

src/item.ts

+2-10
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export type EmbedReplayData = {
8585
ts?: string;
8686
title?: string;
8787
query?: string;
88+
waczhash?: string;
8889
};
8990

9091
export type EmbedReplayEvent = EmbedReplayData & {
@@ -229,16 +230,6 @@ class Item extends LitElement {
229230

230231
this.observer.observe(this);
231232
}
232-
233-
if (this.embed) {
234-
window.addEventListener("message", (event: MessageEvent) => {
235-
if (event.source === window.parent) {
236-
if (event.data.type === "fullReload") {
237-
void this.deleteFully(true);
238-
}
239-
}
240-
});
241-
}
242233
}
243234

244235
async runUpdateLoop() {
@@ -976,6 +967,7 @@ class Item extends LitElement {
976967
sourceUrl="${this.sourceUrl || ""}"
977968
url="${this.tabData.url || ""}"
978969
ts="${this.tabData.ts || ""}"
970+
waczhash="${this.tabData.waczhash || ""}"
979971
@coll-tab-nav="${this.onItemTabNav}"
980972
id="replay"
981973
@replay-loading="${this.onReplayLoading}"

src/pageentry.ts

+12-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { property, state } from "lit/decorators.js";
55

66
import "keyword-mark-element/lib/keyword-mark.js";
77

8-
import { getReplayLink } from "./pageutils";
8+
import { getPageDateTS, getReplayLink } from "./pageutils";
99

1010
import { wrapCss } from "./misc";
1111
import type { URLResource } from "./types";
@@ -192,7 +192,7 @@ class PageEntry extends LitElement {
192192

193193
render() {
194194
const p = this.page!;
195-
const date = this.page!.date;
195+
const { date } = getPageDateTS(p);
196196

197197
const hasSize = typeof p.size === "number";
198198

@@ -245,6 +245,7 @@ class PageEntry extends LitElement {
245245
"pages",
246246
this.page!.url,
247247
this.page!.timestamp!,
248+
this.page!.waczhash,
248249
)}"
249250
>
250251
<p class="is-size-6 has-text-weight-bold has-text-link text">
@@ -298,16 +299,20 @@ class PageEntry extends LitElement {
298299
`;
299300
}
300301

302+
private getReplayPrefix() {
303+
const waczhash = this.page!.waczhash ? `:${this.page!.waczhash}/` : "";
304+
const ts = this.page!.timestamp || "";
305+
return this.replayPrefix + "/" + waczhash + ts + "id_";
306+
}
307+
301308
private renderPageIcon() {
302309
if (!this.thumbnailValid) {
303310
return this.renderFavicon();
304311
}
305312
return html`<img
306313
class="thumbnail"
307314
@error=${() => (this.thumbnailValid = false)}
308-
src=${`${this.replayPrefix}/${this.page!.timestamp}id_/urn:thumbnail:${
309-
this.page!.url
310-
}`}
315+
src=${`${this.getReplayPrefix()}/urn:thumbnail:${this.page!.url}`}
311316
loading="lazy"
312317
/>`;
313318
}
@@ -319,9 +324,7 @@ class PageEntry extends LitElement {
319324
return html`<img
320325
class="favicon"
321326
@error=${() => (this.iconValid = false)}
322-
src=${`${this.replayPrefix}/${this.page!.timestamp}id_/${
323-
this.page!.favIconUrl
324-
}`}
327+
src=${`${this.getReplayPrefix()}/${this.page!.favIconUrl}`}
325328
loading="lazy"
326329
/>`;
327330
}
@@ -377,6 +380,7 @@ class PageEntry extends LitElement {
377380
const data = {
378381
url: this.page!.url,
379382
ts: this.page!.timestamp,
383+
waczhash: this.page!.waczhash,
380384
};
381385
this.sendChangeEvent(data, reload);
382386
return false;

0 commit comments

Comments
 (0)