Skip to content

Commit

Permalink
additional fixes for wabac.js 2.20.0 with typescript!
Browse files Browse the repository at this point in the history
  • Loading branch information
ikreymer committed Sep 7, 2024
1 parent b636237 commit 97598b1
Show file tree
Hide file tree
Showing 10 changed files with 111 additions and 99 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"@fortawesome/fontawesome-free": "^5.13.0",
"@ipld/car": "^5.3.1",
"@webrecorder/awp-sw": "^0.4.4",
"@webrecorder/wabac": "^2.19.7",
"@webrecorder/wabac": "^2.20.0-beta.1",
"auto-js-ipfs": "^2.3.0",
"browsertrix-behaviors": "^0.6.4",
"btoa": "^1.2.1",
Expand All @@ -23,12 +23,12 @@
"node-fetch": "2.6.7",
"pdfjs-dist": "2.2.228",
"pretty-bytes": "^5.6.0",
"replaywebpage": "^2.0.2",
"replaywebpage": "^2.1.4",
"stream-browserify": "^3.0.0",
"tsconfig-paths-webpack-plugin": "^4.1.0",
"unused-filename": "^4.0.1",
"uuid": "^8.3.2",
"warcio": "^2.2.1"
"warcio": "^2.3.1"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^6.15.0",
Expand Down
3 changes: 1 addition & 2 deletions src/electron/app-popup.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//import { ipcRenderer } from "electron";
import { RecPopup } from "../popup";

// @ts-expect-error - TS7016 - Could not find a declaration file for module '@webrecorder/wabac/src/loaders'. '/Users/emma/Work/Webrecorder/archiveweb.page/node_modules/@webrecorder/wabac/src/loaders.js' implicitly has an 'any' type.
import { CollectionLoader } from "@webrecorder/wabac/src/loaders";
import { CollectionLoader } from "@webrecorder/wabac/swlib";
import { listAllMsg } from "../utils";
import { setLocalOption } from "../localstorage";

Expand Down
8 changes: 4 additions & 4 deletions src/electron/electron-recorder-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ class ElectronRecorderApp extends ElectronReplayApp {
const { url, responseHeaders, method } = details;

// Allow access to Browsertrix APIs
if (url.indexOf("/api") >= 0) {
if (url.indexOf("/api") >= 0 && responseHeaders) {
let { statusLine } = details;

if (method === "OPTIONS") {
statusLine = "HTTP/1.1 200 OK";
responseHeaders["Access-Control-Allow-Headers"] = "Authorization, Content-Type";
responseHeaders["Access-Control-Allow-Methods"] = "GET, PUT, POST";
responseHeaders["Access-Control-Allow-Headers"] = ["Authorization, Content-Type"];
responseHeaders["Access-Control-Allow-Methods"] = ["GET, PUT, POST"];
}
responseHeaders["Access-Control-Allow-Origin"] = "*";
responseHeaders["Access-Control-Allow-Origin"] = ["*"];
callback({responseHeaders, statusLine});
} else {
callback({responseHeaders});
Expand Down
3 changes: 1 addition & 2 deletions src/ext/bg.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { BrowserRecorder } from "./browser-recorder";

// @ts-expect-error - TS7016 - Could not find a declaration file for module '@webrecorder/wabac/src/loaders'. '/Users/emma/Work/Webrecorder/archiveweb.page/node_modules/@webrecorder/wabac/src/loaders.js' implicitly has an 'any' type.
import { CollectionLoader } from "@webrecorder/wabac/src/loaders";
import { CollectionLoader } from "@webrecorder/wabac/swlib";

import { listAllMsg } from "../utils";

Expand Down
13 changes: 5 additions & 8 deletions src/recorder.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { RequestResponseInfo } from "./requestresponseinfo";

// @ts-expect-error - Missing types
import { getCustomRewriter } from "@webrecorder/wabac/src/rewrite";
import {
rewriteDASH,
rewriteHLS,
// @ts-expect-error - Missing types
} from "@webrecorder/wabac/src/rewrite/rewriteVideo";
import { getCustomRewriter, rewriteDASH, rewriteHLS } from "@webrecorder/wabac";

import { Buffer } from "buffer";

// @ts-expect-error - Missing types
Expand Down Expand Up @@ -1457,7 +1452,9 @@ class Recorder {
const data = reqresp.toDBRecord(reqresp.payload, this.pageInfo);

// top-level URL is a non-GET request
if (data && data.requestUrl && data.requestUrl === this.pageInfo.url && !sessions.length) {
// @ts-expect-error - TS2339 - Property 'pageInfo' does not exist on type 'Recorder'.
if (data?.requestUrl && data.requestUrl === this.pageInfo.url && !sessions.length) {
// @ts-expect-error - TS2339 - Property 'pageInfo' does not exist on type 'Recorder'.
this.pageInfo.url = data.url;
}

Expand Down
10 changes: 4 additions & 6 deletions src/requestresponseinfo.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
"use strict";

// @ts-expect-error - Missing types
import { getCustomRewriter } from "@webrecorder/wabac/src/rewrite";
// @ts-expect-error - Missing types
import { getStatusText } from "@webrecorder/wabac/src/utils";
import { getCustomRewriter, getStatusText } from "@webrecorder/wabac";

import { postToGetUrl } from "warcio";

Expand Down Expand Up @@ -281,7 +276,9 @@ class RequestResponseInfo {
};
if (postToGetUrl(convData)) {
// if URL for custom rewriting, keep as is, otherwise truncate to avoid extra long URLs
// @ts-expect-error - TS2339 - Property 'url' does not exist on type 'RequestResponseInfo'.
if (getCustomRewriter(this.url, mime === "text/html")) {
// @ts-expect-error - TS2339 - Property 'url' does not exist on type 'RequestResponseInfo'.
this.url = convData.url;
} else {
try {
Expand All @@ -295,6 +292,7 @@ class RequestResponseInfo {
} catch (e) {
//ignore
}
// @ts-expect-error - TS2339 - Property 'url' does not exist on type 'RequestResponseInfo'.
this.url = convData.url.slice(0, MAX_URL_LENGTH);
}
}
Expand Down
9 changes: 1 addition & 8 deletions src/sw/main.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
// @ts-expect-error - TS7016 - Could not find a declaration file for module '@webrecorder/wabac/src/swmain'. '/Users/emma/Work/Webrecorder/archiveweb.page/node_modules/@webrecorder/wabac/src/swmain.js' implicitly has an 'any' type.
import { SWReplay } from "@webrecorder/wabac/src/swmain";
import { SWReplay, WorkerLoader } from "@webrecorder/wabac/swlib";

// @ts-expect-error - TS2307 - Cannot find module '@webrecorder/awp-sw' or its corresponding type declarations.
import { ExtAPI, RecordingCollections } from "@webrecorder/awp-sw";

import REC_INDEX_HTML from "@/static/index.html";
import RWP_INDEX_HTML from "replaywebpage/index.html";

// @ts-expect-error - TS7016 - Could not find a declaration file for module '@webrecorder/wabac/src/loaders'. '/Users/emma/Work/Webrecorder/archiveweb.page/node_modules/@webrecorder/wabac/src/loaders.js' implicitly has an 'any' type.
import { WorkerLoader } from "@webrecorder/wabac/src/loaders";

// @ts-expect-error - TS2339 - Property 'registration' does not exist on type 'Window & typeof globalThis'.
if (self.registration) {
const defaultConfig = {
Expand Down Expand Up @@ -38,13 +34,10 @@ if (self.registration) {
const ApiClass = ExtAPI;
const CollectionsClass = RecordingCollections;

const autoipfsOpts = {};

// @ts-expect-error - TS2339 - Property 'sw' does not exist on type 'Window & typeof globalThis'.
self.sw = new SWReplay({
ApiClass,
staticData,
autoipfsOpts,
defaultConfig,
CollectionsClass,
});
Expand Down
14 changes: 7 additions & 7 deletions src/ui/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { html, css, wrapCss, IS_APP, apiPrefix } from "replaywebpage/misc";
// replaywebpage imports
import { ReplayWebApp, Embed, Loader } from "replaywebpage";

import { SWManager } from "replaywebpage/src/swmanager";
import { SWManager } from "replaywebpage";

import fasHelp from "@fortawesome/fontawesome-free/svgs/solid/question-circle.svg";
import fasPlus from "@fortawesome/fontawesome-free/svgs/solid/plus.svg";
Expand Down Expand Up @@ -184,7 +184,7 @@ class ArchiveWebApp extends ReplayWebApp {
.register()
.catch(
() =>
(this.swErrorMsg = this.swmanager.renderErrorReport(this.mainLogo)),
(this.swErrorMsg = this.swmanager?.renderErrorReport(this.mainLogo) || ""),
);
}
}
Expand Down Expand Up @@ -1105,7 +1105,7 @@ class ArchiveWebApp extends ReplayWebApp {
type="text"
name="btrixOrgName"
id="btrixOrgName"
value="${this.btrixOpts?.orgName}"
value="${this.btrixOpts?.orgName || ""}"
placeholder="my-org"
/>
</p>
Expand Down Expand Up @@ -1188,7 +1188,7 @@ class ArchiveWebApp extends ReplayWebApp {
type="url"
name="btrixUrl"
id="btrixUrl"
value="${this.btrixOpts?.url}"
value="${this.btrixOpts?.url || ""}"
placeholder="https://..."
/>
</p>
Expand All @@ -1201,7 +1201,7 @@ class ArchiveWebApp extends ReplayWebApp {
type="text"
name="btrixUsername"
id="btrixUsername"
value="${this.btrixOpts?.username}"
value="${this.btrixOpts?.username || ""}"
placeholder="Username"
/>
</p>
Expand All @@ -1214,7 +1214,7 @@ class ArchiveWebApp extends ReplayWebApp {
type="password"
name="btrixPassword"
id="btrixPassword"
value="${this.btrixOpts?.password}"
value="${this.btrixOpts?.password || ""}"
placeholder="Password"
/>
</p>
Expand All @@ -1227,7 +1227,7 @@ class ArchiveWebApp extends ReplayWebApp {
type="text"
name="btrixOrgName"
id="btrixOrgName"
value="${this.btrixOpts?.orgName}"
value="${this.btrixOpts?.orgName || ""}"
placeholder="Organization (optional)"
/>
</p>
Expand Down
3 changes: 1 addition & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// @ts-expect-error - TS7016 - Could not find a declaration file for module '@webrecorder/wabac/src/utils'. '/Users/emma/Work/Webrecorder/archiveweb.page/node_modules/@webrecorder/wabac/src/utils.js' implicitly has an 'any' type.
import { getCollData } from "@webrecorder/wabac/src/utils";
import { rewriteHLS as getCollData } from "@webrecorder/wabac";
import { getLocalOption, setLocalOption } from "./localstorage";

// ===========================================================================
Expand Down
Loading

0 comments on commit 97598b1

Please sign in to comment.