@lls/offline 24.24.0-4afe3600 → 24.24.0-4f552474

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -63,6 +63,13 @@ var makeSyncHandler = a(
63
63
  );
64
64
  var jsonToBuf = (json) => new TextEncoder().encode(JSON.stringify(json));
65
65
  var openCache = async (mode) => caches.open(`LLS_OFFLINE_${mode}`);
66
+ var isStoryZip = (name) => /story-.*?\.zip/.test(name);
67
+ var isValidZipName = (name) => {
68
+ return /lecture-cp\.zip/.test(name) || isStoryZip(name);
69
+ };
70
+ var isValidS3Zip = (response) => {
71
+ return Number(response?.headers.get("Content-Length")) >= 1e4 || isStoryZip(response.url);
72
+ };
66
73
 
67
74
  // src/worker/swFetchScreenCall.ts
68
75
  var zipSlugName = (str) => str.replace(/[^a-zA-Z0-9-.]/g, "");
@@ -302,6 +309,9 @@ var putInCache = async (request, response) => {
302
309
  var onlineFirst = async (request, event) => {
303
310
  try {
304
311
  const responseFromNetwork = await fetch(request);
312
+ if (isValidZipName(request.url) && !isValidS3Zip(responseFromNetwork)) {
313
+ throw new Error(`zip is invalid: got ${responseFromNetwork.headers.get("Content-Length")} bytes`);
314
+ }
305
315
  const cached = putInCache(request, responseFromNetwork.clone());
306
316
  if (request.url.endsWith(".zip")) {
307
317
  await cached;
@@ -94,6 +94,13 @@ var concatArrayBuffers = (buffers) => {
94
94
  }
95
95
  return concatenated.buffer;
96
96
  };
97
+ var isStoryZip = (name) => /story-.*?\.zip/.test(name);
98
+ var isValidZipName = (name) => {
99
+ return /lecture-cp\.zip/.test(name) || isStoryZip(name);
100
+ };
101
+ var isValidS3Zip = (response) => {
102
+ return Number(response?.headers.get("Content-Length")) >= 1e4 || isStoryZip(response.url);
103
+ };
97
104
 
98
105
  // src/worker/wwApi.ts
99
106
  var STATE = {
@@ -917,6 +924,11 @@ var fetchZipFile = async (zipUrl, { forceRefresh } = {}) => {
917
924
  }
918
925
  const response = await fetch(zipUrl);
919
926
  const contentLength = +response.headers.get("Content-Length");
927
+ if (!isValidS3Zip(response)) {
928
+ const error = `likely ${zipUrl} was not fetched ${contentLength}`;
929
+ console.debug(error);
930
+ throw new Error(error);
931
+ }
920
932
  const reader = response.body.getReader();
921
933
  let position = 0;
922
934
  const arrayBuffer = new Uint8Array(contentLength);
@@ -934,11 +946,6 @@ var fetchZipFile = async (zipUrl, { forceRefresh } = {}) => {
934
946
  self.postMessage({ methodName: "opfsProgress", arg: { total: contentLength, bytes: position } });
935
947
  }
936
948
  }
937
- if (arrayBuffer.byteLength < 1e4) {
938
- const error = `likely ${zipUrl} was not fetched ${arrayBuffer.byteLength}`;
939
- console.debug(error);
940
- throw new Error(error);
941
- }
942
949
  if (STORAGE === "native") {
943
950
  await sender.nativeWriteFile({ fname: fileName, buffer: arrayBuffer });
944
951
  } else if (STORAGE === "opfs") {
@@ -1052,9 +1059,7 @@ var loadBooks = async ({ primaryOnly = false } = {}) => {
1052
1059
  } else {
1053
1060
  const cache = await openCache(CONF_ENV);
1054
1061
  const keys = await cache.keys();
1055
- const zips = keys.filter((key2) => {
1056
- return key2.url.match(/lecture-cp\.zip|story-.*?\.zip/);
1057
- });
1062
+ const zips = keys.filter((key2) => isValidZipName(key2.url));
1058
1063
  entries = zips.map((zip) => ({ name: String(zip.url.split("/").pop()) }));
1059
1064
  }
1060
1065
  for await (const entry of entries) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lls/offline",
3
- "version": "24.24.0-4afe3600",
3
+ "version": "24.24.0-4f552474",
4
4
  "description": "offline",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",
@@ -52,7 +52,7 @@
52
52
  "vite": "7.0.0",
53
53
  "vite-tsconfig-paths": "5.1.4",
54
54
  "zod": "3.25.50",
55
- "@lls/vitescripts": "24.24.0-4afe3600"
55
+ "@lls/vitescripts": "24.24.0-4f552474"
56
56
  },
57
57
  "dependencies": {
58
58
  "fflate": "0.8.2"