Skip to content

Commit da6a867

Browse files
committed
bump version to 0.5.0-beta.0
1 parent 0e1ca46 commit da6a867

File tree

6 files changed

+82
-89
lines changed

6 files changed

+82
-89
lines changed

package.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
{
22
"name": "@webrecorder/awp-sw",
33
"browser": "dist/sw.js",
4-
"version": "0.4.4",
5-
"main": "index.js",
4+
"version": "0.5.0-beta.0",
65
"type": "module",
76
"repository": {
87
"type": "git",
98
"url": "git+https://github.com/webrecorder/awp-sw.git"
109
},
1110
"license": "AGPL-3.0-or-later",
1211
"exports": {
13-
".": "./src/index.js"
12+
".": {
13+
"types": "./dist/types/index.d.ts",
14+
"default": "./dist/index.js"
15+
}
1416
},
1517
"files": [
1618
"src/*"
1719
],
1820
"dependencies": {
1921
"@ipld/car": "^5.3.2",
2022
"@ipld/unixfs": "^3.0.0",
21-
"@webrecorder/wabac": "^2.20.0-beta.1",
23+
"@webrecorder/wabac": "^2.20.0-beta.2",
2224
"auto-js-ipfs": "^2.3.0",
2325
"client-zip": "^2.3.0",
2426
"hash-wasm": "^4.9.0",
@@ -46,7 +48,7 @@
4648
"ts-loader": "^9.5.1",
4749
"tsconfig-paths-webpack-plugin": "^4.1.0",
4850
"typescript": "^5.5.4",
49-
"webpack": "^5.91.0",
51+
"webpack": "^5.94.0",
5052
"webpack-cli": "^5.1.4"
5153
},
5254
"description": "This library has been factored out of [ArchiveWeb.page](https://webrecorder/archiveweb.page) and represents the core service worker implementation necessarily for high-fidelity web archiving.",

src/api.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,12 @@ class ExtAPI extends API {
170170
signal,
171171
// eslint-disable-next-line @typescript-eslint/no-explicit-any
172172
} as any);
173-
uploading.set(params["coll"], counter);
173+
uploading.set(params.coll, counter);
174174
if (event.waitUntil) {
175175
event.waitUntil(
176176
this.uploadFinished(
177177
fetchPromise,
178-
params["coll"],
178+
params.coll,
179179
dl.metadata,
180180
filename,
181181
counter,
@@ -184,7 +184,7 @@ class ExtAPI extends API {
184184
}
185185
return { uploading: true };
186186
} catch (e: unknown) {
187-
uploading.delete(params["coll"]);
187+
uploading.delete(params.coll);
188188
// eslint-disable-next-line @typescript-eslint/no-explicit-any
189189
return { error: "upload_failed", details: (e as any).toString() };
190190
}
@@ -224,7 +224,7 @@ class ExtAPI extends API {
224224
}
225225

226226
async deleteUpload(params: RouteMatch) {
227-
const collId = params["coll"];
227+
const collId = params.coll;
228228

229229
this.uploading.delete(collId);
230230

@@ -242,7 +242,7 @@ class ExtAPI extends API {
242242

243243
async getUploadStatus(params: RouteMatch) {
244244
let result: Metadata = {};
245-
const counter = this.uploading.get(params["coll"]);
245+
const counter = this.uploading.get(params.coll);
246246

247247
if (!counter) {
248248
result = { status: "idle" };
@@ -251,11 +251,11 @@ class ExtAPI extends API {
251251
result = { status, size, totalSize };
252252

253253
if (status !== "uploading") {
254-
this.uploading.delete(params["coll"]);
254+
this.uploading.delete(params.coll);
255255
}
256256
}
257257

258-
const coll = await this.collections.loadColl(params["coll"]);
258+
const coll = await this.collections.loadColl(params.coll);
259259

260260
if (coll?.metadata) {
261261
result.uploadTime = coll.metadata.uploadTime;
@@ -268,7 +268,7 @@ class ExtAPI extends API {
268268
}
269269

270270
async recordingPending(params: RouteMatch) {
271-
const coll = await this.collections.loadColl(params["coll"]);
271+
const coll = await this.collections.loadColl(params.coll);
272272
if (!coll) {
273273
return { error: "collection_not_found" };
274274
}
@@ -435,7 +435,9 @@ async function runIPFSAdd(
435435

436436
sendMessage("ipfsAdd", result);
437437

438-
await collections.updateMetadata(coll.name, coll.config["metadata"]);
438+
if (coll.config.metadata) {
439+
await collections.updateMetadata(coll.name, coll.config.metadata);
440+
}
439441
}
440442

441443
// ===========================================================================

src/downloader.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ class Downloader {
268268
this.db = coll.store;
269269
this.pageList = pageList || [];
270270
this.collId = coll.name;
271-
this.metadata = coll.config["metadata"];
271+
this.metadata = coll.config.metadata || {};
272272
this.gzip = gzip;
273273

274274
this.markers = markers || {};
@@ -281,12 +281,10 @@ class Downloader {
281281

282282
this.uuidNamespace = uuidNamespace || DEFAULT_UUID_NAMESPACE;
283283

284-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
285-
this.createdDateDt = new Date(coll.config.ctime);
284+
this.createdDateDt = new Date(coll.config.ctime!);
286285
this.createdDate = this.createdDateDt.toISOString();
287-
this.modifiedDate = coll.config["metadata"].mtime
288-
? // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
289-
new Date(coll.config.metadata.mtime).toISOString()
286+
this.modifiedDate = coll.config.metadata!.mtime
287+
? new Date(coll.config.metadata!.mtime).toISOString()
290288
: null;
291289

292290
this.format = format;
@@ -299,10 +297,9 @@ class Downloader {
299297
}
300298

301299
// determine filename from title, if it exists
302-
if (!filename && coll.config["metadata"].title) {
300+
if (!filename && coll.config.metadata!.title) {
303301
filename = encodeURIComponent(
304-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
305-
coll.config.metadata.title.toLowerCase().replace(/\s/g, "-"),
302+
coll.config.metadata!.title.toLowerCase().replace(/\s/g, "-"),
306303
);
307304
}
308305

src/ipfsutils.ts

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type Collection } from "@webrecorder/wabac/swlib";
1+
import { type CollMetadata, type Collection } from "@webrecorder/wabac/swlib";
22
import { Downloader, type DownloaderOpts, type Markers } from "./downloader";
33

44
// @ts-expect-error no types
@@ -31,6 +31,10 @@ type ReplayOpts = {
3131
loading?: boolean;
3232
};
3333

34+
type MetadataWithIPFS = CollMetadata & {
35+
ipfsPins?: {url: string, cid: string}[] | null;
36+
}
37+
3438
export async function setAutoIPFSUrl(url: string) {
3539
if (autoipfsOpts.daemonURL !== url) {
3640
autoipfs = null;
@@ -66,8 +70,10 @@ export async function ipfsAdd(
6670
throw new Error(dlResponse.error);
6771
}
6872

69-
if (!coll.config.metadata.ipfsPins) {
70-
coll.config.metadata.ipfsPins = [];
73+
const metadata : MetadataWithIPFS = coll.config.metadata || {};
74+
75+
if (!metadata.ipfsPins) {
76+
metadata.ipfsPins = [];
7177
}
7278

7379
let concur;
@@ -120,8 +126,8 @@ export async function ipfsAdd(
120126

121127
progress(0, totalSize);
122128

123-
let url,
124-
cid = "";
129+
let url = "";
130+
let cid = "";
125131

126132
let reject: ((reason?: string) => void) | null = null;
127133

@@ -132,7 +138,7 @@ export async function ipfsAdd(
132138
.pipeThrough(new ShardStoringStream(autoipfs, concur, reject!))
133139
.pipeTo(
134140
new WritableStream({
135-
write: (res) => {
141+
write: (res: {url: string, cid: string, size: number}) => {
136142
if (res.url && res.cid) {
137143
url = res.url;
138144
cid = res.cid;
@@ -160,7 +166,7 @@ export async function ipfsAdd(
160166

161167
const res = { cid: cid.toString(), url };
162168

163-
coll.config.metadata.ipfsPins.push(res);
169+
metadata.ipfsPins.push(res);
164170

165171
console.log("ipfs cid added " + url);
166172

@@ -172,8 +178,10 @@ export async function ipfsRemove(coll: Collection) {
172178
autoipfs = await createAutoIPFS(autoipfsOpts);
173179
}
174180

175-
if (coll.config.metadata.ipfsPins) {
176-
for (const { url } of coll.config.metadata.ipfsPins) {
181+
const metadata : MetadataWithIPFS = coll.config.metadata || {};
182+
183+
if (metadata.ipfsPins) {
184+
for (const { url } of metadata.ipfsPins) {
177185
try {
178186
await autoipfs.clear(url);
179187
} catch (_e) {
@@ -183,7 +191,7 @@ export async function ipfsRemove(coll: Collection) {
183191
}
184192
}
185193

186-
coll.config.metadata.ipfsPins = null;
194+
metadata.ipfsPins = null;
187195
return true;
188196
}
189197

@@ -205,6 +213,7 @@ async function ipfsWriteBuff(
205213
const file = UnixFS.createFileWriter(writer);
206214
if (content instanceof Uint8Array) {
207215
await file.write(content);
216+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
208217
} else if (content[Symbol.asyncIterator]) {
209218
for await (const chunk of content) {
210219
await file.write(chunk);
@@ -223,7 +232,7 @@ export async function ipfsGenerateCar(
223232
uiContent: Uint8Array,
224233
htmlContent: string,
225234
replayOpts: ReplayOpts,
226-
markers: Markers,
235+
markers: Markers | null,
227236
favicon: Uint8Array | null,
228237
// eslint-disable-next-line @typescript-eslint/no-explicit-any
229238
): Promise<any> {
@@ -268,7 +277,7 @@ export async function ipfsGenerateCar(
268277

269278
const { cid } = await rootDir.close();
270279

271-
writer.close();
280+
await writer.close();
272281

273282
return cid;
274283
}
@@ -338,6 +347,7 @@ async function splitByWarcRecordGroup(
338347
links = [];
339348
}
340349

350+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
341351
fileLinks.push(link);
342352

343353
const [dirName, filename] = getDirAndName(currName);
@@ -354,6 +364,7 @@ async function splitByWarcRecordGroup(
354364
dir = dirs[dirName];
355365
}
356366

367+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
357368
dir.set(filename, link);
358369

359370
inZipFile = false;
@@ -368,6 +379,7 @@ async function splitByWarcRecordGroup(
368379
file = UnixFS.createFileWriter(writer);
369380

370381
if (chunk === WARC_GROUP) {
382+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
371383
secondaryLinks.push(await concat(writer, links));
372384
links = [];
373385
}
@@ -376,7 +388,7 @@ async function splitByWarcRecordGroup(
376388
if (!inZipFile) {
377389
lastChunk = chunk;
378390
}
379-
file.write(chunk);
391+
await file.write(chunk);
380392
count++;
381393
}
382394
}
@@ -404,6 +416,7 @@ async function splitByWarcRecordGroup(
404416

405417
rootDir.set("webarchive", await waczDir.close());
406418

419+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
407420
rootDir.set(waczPath, await concat(writer, fileLinks));
408421
}
409422

@@ -416,6 +429,7 @@ async function concat(
416429
const { fileEncoder, hasher, linker } = writer.settings;
417430
// eslint-disable-next-line @typescript-eslint/no-explicit-any
418431
const advanced = (fileEncoder as any).createAdvancedFile(links);
432+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
419433
const bytes = fileEncoder.encode(advanced);
420434
const hash = await hasher.digest(bytes);
421435
const cid = linker.createLink(fileEncoder.code, hash);
@@ -435,6 +449,7 @@ async function concat(
435449

436450
export const iterate = async function* (stream: ReadableStream<Uint8Array>) {
437451
const reader = stream.getReader();
452+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
438453
while (true) {
439454
const next = await reader.read();
440455
if (next.done) {
@@ -447,6 +462,7 @@ export const iterate = async function* (stream: ReadableStream<Uint8Array>) {
447462

448463
// eslint-disable-next-line @typescript-eslint/no-explicit-any
449464
export async function encodeBlocks(blocks: UnixFS.Block[], root?: any) {
465+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
450466
const { writer, out } = CarWriter.create(root);
451467
/** @type {Error?} */
452468
let error;
@@ -464,6 +480,7 @@ export async function encodeBlocks(blocks: UnixFS.Block[], root?: any) {
464480
})();
465481
const chunks = [];
466482
for await (const chunk of out) chunks.push(chunk);
483+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
467484
if (error != null) throw error;
468485
const roots = root != null ? [root] : [];
469486
console.log("chunks", chunks.length);
@@ -537,6 +554,7 @@ export class ShardingStream extends TransformStream {
537554
shard = [];
538555
currSize = 0;
539556
}
557+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
540558
shard.push(block);
541559
currSize += block.bytes.length;
542560
},

webpack.config.cjs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,20 @@ const BANNER_TEXT = `'[name].js is part of the ArchiveWeb.page system (https://a
88

99

1010
module.exports = {
11-
target: "webworker",
11+
target: "web",
1212
entry: {
1313
"main": "./src/index.ts",
1414
},
1515
output: {
1616
filename: "sw.js",
17+
globalObject: "self",
1718
library: {
18-
type: "self"
19+
type: "module"
1920
}
2021
},
22+
experiments: {
23+
outputModule: true
24+
},
2125
optimization: {
2226
minimize: true,
2327
minimizer: [

0 commit comments

Comments
 (0)