jpegxl 8.4.0 → 8.4.1
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.
- package/README.md +294 -229
- package/dist/animation.browser.mjs +2 -2
- package/dist/animation.mjs +2 -2
- package/dist/capture-complete.browser.mjs +2 -2
- package/dist/capture-complete.mjs +2 -2
- package/dist/capture-groups.mjs +2 -2
- package/dist/capture.browser.mjs +2 -2
- package/dist/capture.mjs +2 -2
- package/dist/cli-add.mjs +2 -2
- package/dist/cli-astro.mjs +2 -2
- package/dist/cli-cloudflare.mjs +2 -2
- package/dist/cli-emdash.mjs +2 -2
- package/dist/cli-places.mjs +2 -2
- package/dist/cli-selftest.mjs +2 -2
- package/dist/cli-workers.mjs +2 -2
- package/dist/cli.mjs +2 -2
- package/dist/decode.browser.mjs +2 -2
- package/dist/decode.mjs +2 -2
- package/dist/decode.node.mjs +2 -2
- package/dist/format.browser.mjs +2 -2
- package/dist/format.mjs +2 -2
- package/dist/hdr.mjs +2 -2
- package/dist/helpers.mjs +2 -2
- package/dist/index.browser.mjs +2 -2
- package/dist/index.mjs +2 -2
- package/dist/jpeg.browser.mjs +2 -2
- package/dist/jpeg.mjs +2 -2
- package/dist/jpeg.node.mjs +2 -2
- package/dist/metadata.mjs +2 -2
- package/dist/polyfill.mjs +2 -2
- package/dist/resumable.mjs +2 -2
- package/dist/resumable.node.mjs +2 -2
- package/dist/serve.mjs +2 -2
- package/dist/serve.node.mjs +2 -2
- package/dist/upload.browser.mjs +2 -2
- package/dist/upload.mjs +2 -2
- package/dist/verify.mjs +2 -2
- package/dist/verify.node.mjs +2 -2
- package/dist/wasm-modules.mjs +2 -2
- package/examples/agents/jxl-tools.mjs +8 -8
- package/examples/android/prepare-assets.mjs +2 -2
- package/examples/capacitor/prepare-assets.mjs +2 -2
- package/examples/emdash/admin-work.mjs +1 -1
- package/examples/emdash/backfill.mjs +4 -4
- package/examples/emdash/background.mjs +5 -5
- package/examples/emdash/browser-candidate.mjs +1 -1
- package/examples/emdash/deliver.mjs +2 -2
- package/examples/emdash/host-policy.mjs +6 -6
- package/examples/emdash/index.mjs +3 -3
- package/examples/emdash/job-runner.mjs +31 -31
- package/examples/emdash/job-store.mjs +21 -21
- package/examples/emdash/jpeg-source.mjs +2 -2
- package/examples/emdash/library-jobs.mjs +21 -21
- package/examples/emdash/local-store.mjs +16 -16
- package/examples/emdash/media-admin.mjs +9 -9
- package/examples/emdash/media-plugin.mjs +62 -62
- package/examples/emdash/media-storage.mjs +55 -55
- package/examples/emdash/media-words.mjs +89 -89
- package/examples/emdash/media-worker.mjs +1 -1
- package/examples/emdash/original-envelope.mjs +2 -2
- package/examples/emdash/originals.mjs +77 -77
- package/examples/emdash/r2-store.mjs +3 -3
- package/examples/emdash/read-all.mjs +14 -14
- package/examples/emdash/server-only.mjs +1 -1
- package/examples/emdash/storage.mjs +1 -1
- package/examples/emdash/structural-delivery.mjs +42 -42
- package/examples/emdash/thread-driver.mjs +15 -15
- package/examples/emdash/thread-worker.mjs +3 -3
- package/examples/emdash/work-queue.mjs +11 -11
- package/examples/flutter/prepare-assets.mjs +3 -3
- package/examples/ios/prepare-assets.mjs +3 -3
- package/examples/page-rects.js +14 -14
- package/examples/react-native/src/JXLProvider.tsx +19 -9
- package/examples/snapdom/jxl.js +3 -2
- package/examples/svg-jxl.js +10 -10
- package/package.json +1 -1
- package/types/animation.d.mts +2 -2
- package/types/capture-complete.d.mts +5 -5
- package/types/capture.d.mts +1 -1
- package/types/format.d.mts +2 -2
- package/types/index.d.mts +6 -6
- package/types/jpeg.d.mts +1 -1
- package/types/result.d.mts +5 -4
- package/types/resumable.d.mts +7 -7
- package/types/serve.d.mts +1 -1
- package/types/types.d.mts +19 -18
- package/types/upload.d.mts +1 -1
- package/types/verify.d.mts +4 -4
|
@@ -8,7 +8,7 @@ import {COLOR_HEADER_BYTES, colorOf, isColor, sameColor, checkable} from './colo
|
|
|
8
8
|
|
|
9
9
|
const ACTIVE = Symbol.for('rapier-jxl.emdash.storage');
|
|
10
10
|
export function registerStorage(storage, scope) {
|
|
11
|
-
if (typeof scope !== 'string' || !scope.length) throw new TypeError('
|
|
11
|
+
if (typeof scope !== 'string' || !scope.length) throw new TypeError('storage: backend scope');
|
|
12
12
|
globalThis[ACTIVE] = {storage, scope};
|
|
13
13
|
return storage;
|
|
14
14
|
}
|
|
@@ -30,7 +30,7 @@ const failure = (code, message, cause) => Object.assign(new Error(message, cause
|
|
|
30
30
|
function publicKey(key) {
|
|
31
31
|
if (typeof key !== 'string' || !key || key.includes('\\') || key.includes('\0') ||
|
|
32
32
|
key.split('/').some(part => !part || part === '.' || part === '..') || key.startsWith(ROOT))
|
|
33
|
-
throw failure('JXL_INPUT', "
|
|
33
|
+
throw failure('JXL_INPUT', "media key: public storage");
|
|
34
34
|
return key;
|
|
35
35
|
}
|
|
36
36
|
|
|
@@ -47,10 +47,10 @@ function meetsFloor(fidelity, floor) {
|
|
|
47
47
|
export function withMediaCopies(inner, {maxPixels, maxInputBytes = 32 * 1024 * 1024, create, compareAndSet, originalBackend,
|
|
48
48
|
cpuLimitMs, memoryLimitBytes} = {}) {
|
|
49
49
|
if (maxPixels !== undefined && (!Number.isSafeInteger(maxPixels) || maxPixels < 1))
|
|
50
|
-
throw failure('JXL_OPTIONS', "
|
|
51
|
-
if (create !== undefined && typeof create !== 'function') throw failure('JXL_OPTIONS', "
|
|
50
|
+
throw failure('JXL_OPTIONS', "maxPixels: positive safe integer");
|
|
51
|
+
if (create !== undefined && typeof create !== 'function') throw failure('JXL_OPTIONS', "create: atomic create-only function");
|
|
52
52
|
if (compareAndSet !== undefined && typeof compareAndSet !== 'function')
|
|
53
|
-
throw failure('JXL_OPTIONS', "
|
|
53
|
+
throw failure('JXL_OPTIONS', "compareAndSet: conditional write function");
|
|
54
54
|
let originals;
|
|
55
55
|
const physicalStore = inner;
|
|
56
56
|
const host = hostLimits(originalBackend?.platform ?? 'node', {cpuLimitMs, memoryLimitBytes});
|
|
@@ -72,7 +72,7 @@ export function withMediaCopies(inner, {maxPixels, maxInputBytes = 32 * 1024 * 1
|
|
|
72
72
|
catch (error) {
|
|
73
73
|
signal?.throwIfAborted();
|
|
74
74
|
if (error?.code === 'NOT_FOUND' || error?.code?.startsWith('JXL_')) throw error;
|
|
75
|
-
throw failure('JXL_INTERNAL', "
|
|
75
|
+
throw failure('JXL_INTERNAL', "media-storage:handler", error);
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
async function files(prefix, signal, call = direct) {
|
|
@@ -81,7 +81,7 @@ export function withMediaCopies(inner, {maxPixels, maxInputBytes = 32 * 1024 * 1
|
|
|
81
81
|
const page = await io(() => call(() => inner.list({prefix, limit: 100, signal, ...(cursor ? {cursor} : {})})), signal);
|
|
82
82
|
all.push(...page.files.filter(file => file.key.startsWith(prefix)));
|
|
83
83
|
if (!page.nextCursor) return all;
|
|
84
|
-
if (seen.has(page.nextCursor)) throw failure('JXL_INTERNAL', "
|
|
84
|
+
if (seen.has(page.nextCursor)) throw failure('JXL_INTERNAL', "media-storage:page-cursor");
|
|
85
85
|
seen.add(page.nextCursor); cursor = page.nextCursor;
|
|
86
86
|
}
|
|
87
87
|
}
|
|
@@ -91,7 +91,7 @@ export function withMediaCopies(inner, {maxPixels, maxInputBytes = 32 * 1024 * 1
|
|
|
91
91
|
catch (error) { if (error?.code === 'NOT_FOUND') return null; throw error; }
|
|
92
92
|
const bytes = await io(() => readAll(file.body, {maxBytes, signal}), signal);
|
|
93
93
|
if (Number.isSafeInteger(file.size) && file.size !== bytes.length)
|
|
94
|
-
throw failure('JXL_INPUT', "
|
|
94
|
+
throw failure('JXL_INPUT', "copy length: reload record");
|
|
95
95
|
return {...file, bytes, size: bytes.length};
|
|
96
96
|
}
|
|
97
97
|
const base = async key => ROOT + await digest(utf8(key)) + '.';
|
|
@@ -129,9 +129,9 @@ export function withMediaCopies(inner, {maxPixels, maxInputBytes = 32 * 1024 * 1
|
|
|
129
129
|
if (!file) return null;
|
|
130
130
|
signal?.throwIfAborted();
|
|
131
131
|
if (range && !headed && (file?.range?.offset !== range.offset || file.range.length !== range.length))
|
|
132
|
-
throw failure('JXL_UNSUPPORTED', "
|
|
132
|
+
throw failure('JXL_UNSUPPORTED', "source range: backend range reads");
|
|
133
133
|
const version = await versionOf(file);
|
|
134
|
-
if (range && !version) throw failure('JXL_UNSUPPORTED', "
|
|
134
|
+
if (range && !version) throw failure('JXL_UNSUPPORTED', "generation: captured source generation");
|
|
135
135
|
return {generation: version, size: file.size};
|
|
136
136
|
} catch (error) {
|
|
137
137
|
failed = true;
|
|
@@ -149,7 +149,7 @@ export function withMediaCopies(inner, {maxPixels, maxInputBytes = 32 * 1024 * 1
|
|
|
149
149
|
// an existing archive on a host whose allowance changed must not trigger a cold restore inside a 10 ms request.
|
|
150
150
|
async function physicalHead(key, {signal, call = direct} = {}) {
|
|
151
151
|
if (!deliveryOnly(host) || typeof originalBackend?.head !== 'function')
|
|
152
|
-
throw failure('JXL_UNSUPPORTED', "
|
|
152
|
+
throw failure('JXL_UNSUPPORTED', "reader: Free Worker storage head()");
|
|
153
153
|
const file = await io(() => call(() => originalBackend.head(key, {signal})), signal);
|
|
154
154
|
return file ? {generation: await versionOf(file), size: file.size} : null;
|
|
155
155
|
}
|
|
@@ -159,17 +159,17 @@ export function withMediaCopies(inner, {maxPixels, maxInputBytes = 32 * 1024 * 1
|
|
|
159
159
|
const file = await io(() => call(() => physicalStore.download(key, {range: {offset: 0, length}, signal})), signal);
|
|
160
160
|
try {
|
|
161
161
|
if (file?.range?.offset !== 0 || file.range.length !== length)
|
|
162
|
-
throw failure('JXL_UNSUPPORTED', "
|
|
162
|
+
throw failure('JXL_UNSUPPORTED', "header range: backend range reads");
|
|
163
163
|
if (file.size !== before.size || await versionOf(file) !== before.generation)
|
|
164
|
-
throw failure('JXL_INPUT', "
|
|
164
|
+
throw failure('JXL_INPUT', "original: changed; reload record");
|
|
165
165
|
const bytes = await io(() => readAll(file.body, {maxBytes: length, signal}), signal);
|
|
166
|
-
if (bytes.length !== length) throw failure('JXL_INPUT', "
|
|
166
|
+
if (bytes.length !== length) throw failure('JXL_INPUT', "header length: reread range");
|
|
167
167
|
return bytes;
|
|
168
168
|
} finally { try { await file?.body?.cancel?.(); } catch {} }
|
|
169
169
|
}
|
|
170
170
|
async function originalHeader(key, before, {signal, call = direct} = {}) {
|
|
171
171
|
if (!Number.isSafeInteger(before?.size) || before.size < 8 || before.size > maxInputBytes || !before.generation)
|
|
172
|
-
throw failure('JXL_LIMIT', "
|
|
172
|
+
throw failure('JXL_LIMIT', "source: size and generation");
|
|
173
173
|
const mimeType = sourceMimeType(key);
|
|
174
174
|
let bytes = await readPhysicalHeader(key, before, SOURCE_HEADER_BYTES, {signal, call});
|
|
175
175
|
try { return {geometry: originalGeometry(bytes, {mimeType, maxPixels}), bytes}; }
|
|
@@ -205,7 +205,7 @@ export function withMediaCopies(inner, {maxPixels, maxInputBytes = 32 * 1024 * 1
|
|
|
205
205
|
}
|
|
206
206
|
async function snapshot(key, {signal, call = direct} = {}) {
|
|
207
207
|
publicKey(key);
|
|
208
|
-
if (typeof call !== 'function') throw failure('JXL_OPTIONS', "
|
|
208
|
+
if (typeof call !== 'function') throw failure('JXL_OPTIONS', "dispatcher: function");
|
|
209
209
|
const file = await read(key, maxInputBytes, signal, call);
|
|
210
210
|
if (!file) return null;
|
|
211
211
|
const sha256 = await digest(file.bytes);
|
|
@@ -223,13 +223,13 @@ export function withMediaCopies(inner, {maxPixels, maxInputBytes = 32 * 1024 * 1
|
|
|
223
223
|
async function selectDelivery(key, mode, {expectedGeneration, expectedRevision, signal, call = direct} = {}) {
|
|
224
224
|
publicKey(key);
|
|
225
225
|
if (!HASH.test(expectedGeneration ?? '') || !COPY_ID.test(expectedRevision ?? '') || typeof call !== 'function')
|
|
226
|
-
throw failure('JXL_OPTIONS', "
|
|
227
|
-
if (!compareAndSet) throw failure('JXL_UNSUPPORTED', "
|
|
226
|
+
throw failure('JXL_OPTIONS', "revision: refresh library");
|
|
227
|
+
if (!compareAndSet) throw failure('JXL_UNSUPPORTED', "writes: compare-and-set required");
|
|
228
228
|
if (await generation(key, {signal, call}) !== expectedGeneration)
|
|
229
|
-
throw failure('JXL_INPUT', "
|
|
229
|
+
throw failure('JXL_INPUT', "picture: changed; refresh library");
|
|
230
230
|
const prior = await delivery(key, expectedGeneration, signal, call);
|
|
231
231
|
if (prior.revision !== expectedRevision || prior.etag === undefined)
|
|
232
|
-
throw failure('JXL_INPUT', "
|
|
232
|
+
throw failure('JXL_INPUT', "delivery: changed; refresh library");
|
|
233
233
|
const revision = crypto.randomUUID().replaceAll('-', ''), policyKey = await deliveryKey(key, expectedGeneration);
|
|
234
234
|
const value = {owner: OWNER, kind: 'delivery', source: key, generation: expectedGeneration, revision, mode};
|
|
235
235
|
let written, uncertain;
|
|
@@ -240,41 +240,41 @@ export function withMediaCopies(inner, {maxPixels, maxInputBytes = 32 * 1024 * 1
|
|
|
240
240
|
if (uncertain) {
|
|
241
241
|
const observed = await delivery(key, expectedGeneration, signal, call);
|
|
242
242
|
if (observed.revision !== revision || observed.mode !== mode) throw uncertain;
|
|
243
|
-
} else if (written !== true) throw failure('JXL_INPUT', "
|
|
243
|
+
} else if (written !== true) throw failure('JXL_INPUT', "delivery: changed; refresh library");
|
|
244
244
|
if (await generation(key, {signal, call}) !== expectedGeneration)
|
|
245
|
-
throw failure('JXL_INPUT', "
|
|
245
|
+
throw failure('JXL_INPUT', "picture: changed; refresh library");
|
|
246
246
|
return {generation: expectedGeneration, revision, mode};
|
|
247
247
|
}
|
|
248
248
|
async function readSource(key, offset, length, {generation: expectedGeneration, signal, call = direct} = {}) {
|
|
249
249
|
publicKey(key); signal?.throwIfAborted();
|
|
250
|
-
if (typeof call !== 'function') throw failure('JXL_OPTIONS', "
|
|
250
|
+
if (typeof call !== 'function') throw failure('JXL_OPTIONS', "dispatcher: function");
|
|
251
251
|
if (typeof expectedGeneration !== 'string' || !HASH.test(expectedGeneration))
|
|
252
|
-
throw failure('JXL_OPTIONS', "
|
|
252
|
+
throw failure('JXL_OPTIONS', "generation: captured source generation");
|
|
253
253
|
if (!Number.isSafeInteger(offset) || offset < 0 || !Number.isSafeInteger(length) || length < 1 || offset > maxInputBytes - length)
|
|
254
|
-
throw failure('JXL_LIMIT', "
|
|
254
|
+
throw failure('JXL_LIMIT', "range: maxInputBytes limit");
|
|
255
255
|
let file;
|
|
256
256
|
try {
|
|
257
257
|
// Keep the returned body reachable if cancellation arrives during the download.
|
|
258
258
|
file = await io(() => call(() => inner.download(key, {range: {offset, length}, signal})));
|
|
259
259
|
signal?.throwIfAborted();
|
|
260
260
|
if (!Number.isSafeInteger(file?.size) || file.size < 1)
|
|
261
|
-
throw failure('JXL_INPUT', "
|
|
261
|
+
throw failure('JXL_INPUT', "source size: byte length");
|
|
262
262
|
if (file.size > maxInputBytes || offset > file.size - length)
|
|
263
|
-
throw failure('JXL_LIMIT', "
|
|
263
|
+
throw failure('JXL_LIMIT', "range: within source and maxInputBytes");
|
|
264
264
|
if (file.range?.offset !== offset || file.range.length !== length)
|
|
265
|
-
throw failure('JXL_UNSUPPORTED', "
|
|
265
|
+
throw failure('JXL_UNSUPPORTED', "source range: backend range reads");
|
|
266
266
|
const version = await versionOf(file);
|
|
267
|
-
if (!version) throw failure('JXL_UNSUPPORTED', "
|
|
268
|
-
if (version !== expectedGeneration) throw failure('JXL_INPUT', "
|
|
267
|
+
if (!version) throw failure('JXL_UNSUPPORTED', "generation: captured source generation");
|
|
268
|
+
if (version !== expectedGeneration) throw failure('JXL_INPUT', "source: changed; reload record");
|
|
269
269
|
const bytes = await io(() => readAll(file.body, {maxBytes: length, signal}), signal);
|
|
270
|
-
if (bytes.length !== length) throw failure('JXL_INPUT', "
|
|
270
|
+
if (bytes.length !== length) throw failure('JXL_INPUT', "source length: reread range");
|
|
271
271
|
// A one-byte check also stays bounded for adapters that buffer downloads.
|
|
272
272
|
if (await generation(key, {signal, range: {offset: 0, length: 1}, call}) !== expectedGeneration)
|
|
273
|
-
throw failure('JXL_INPUT', "
|
|
273
|
+
throw failure('JXL_INPUT', "source: changed; reload record");
|
|
274
274
|
return bytes;
|
|
275
275
|
} catch (error) {
|
|
276
276
|
signal?.throwIfAborted();
|
|
277
|
-
if (error?.code === 'NOT_FOUND') throw failure('JXL_INPUT', "
|
|
277
|
+
if (error?.code === 'NOT_FOUND') throw failure('JXL_INPUT', "source: changed; reload record");
|
|
278
278
|
throw error;
|
|
279
279
|
} finally {
|
|
280
280
|
try { Promise.resolve(file?.body?.cancel?.(signal?.aborted ? signal.reason : undefined)).catch(() => {}); } catch {}
|
|
@@ -446,21 +446,21 @@ export function withMediaCopies(inner, {maxPixels, maxInputBytes = 32 * 1024 * 1
|
|
|
446
446
|
const {width, height} = result ?? {};
|
|
447
447
|
const refused = reason => ({key, ...(variant ? {width} : {}), stored: null, reason});
|
|
448
448
|
signal?.throwIfAborted();
|
|
449
|
-
if (typeof call !== 'function') throw failure('JXL_OPTIONS', "
|
|
450
|
-
if (fence !== undefined && typeof fence !== 'function') throw failure('JXL_OPTIONS', "
|
|
449
|
+
if (typeof call !== 'function') throw failure('JXL_OPTIONS', "dispatcher: function");
|
|
450
|
+
if (fence !== undefined && typeof fence !== 'function') throw failure('JXL_OPTIONS', "publication guard: server function");
|
|
451
451
|
if (structural && (!deliveryOnly(host) || !HASH.test(expectedGeneration ?? '') || verified !== undefined || jobIdentity !== undefined))
|
|
452
|
-
throw failure('JXL_UNSUPPORTED', "
|
|
452
|
+
throw failure('JXL_UNSUPPORTED', "delivery: Free Worker or server verify");
|
|
453
453
|
if (structural && replace)
|
|
454
|
-
throw failure('JXL_UNSUPPORTED', "
|
|
454
|
+
throw failure('JXL_UNSUPPORTED', "delivery: clear copy history");
|
|
455
455
|
if (!IMAGE.test(key) || (!variant && !hasSidecar(key))) return refused('not_image_key');
|
|
456
456
|
if (!structural && !HASH.test(source ?? '')) return refused('source_required');
|
|
457
457
|
if (expectedGeneration !== undefined && !HASH.test(expectedGeneration))
|
|
458
|
-
throw failure('JXL_OPTIONS', "
|
|
458
|
+
throw failure('JXL_OPTIONS', "generation: source version digest");
|
|
459
459
|
if (!COPY_ID.test(expectedDeliveryRevision ?? ''))
|
|
460
|
-
throw failure('JXL_OPTIONS', "
|
|
460
|
+
throw failure('JXL_OPTIONS', "revision: pre-conversion revision");
|
|
461
461
|
if (jobIdentity !== undefined && (typeof jobIdentity !== 'string' || !COPY_ID.test(jobIdentity) || expectedGeneration === undefined))
|
|
462
|
-
throw failure('JXL_OPTIONS', "
|
|
463
|
-
if (typeof replace !== 'boolean') throw failure('JXL_OPTIONS', "
|
|
462
|
+
throw failure('JXL_OPTIONS', "rendition: server ID and generation");
|
|
463
|
+
if (typeof replace !== 'boolean') throw failure('JXL_OPTIONS', "replace: boolean");
|
|
464
464
|
if (result?.meetsTarget !== true) return refused(result?.reason?.code ?? 'JXL_TARGET');
|
|
465
465
|
if (result.format !== 'jxl' || !['jpeg-bytes', 'pixels', 'lossy'].includes(result.kept)) return refused('JXL_INPUT');
|
|
466
466
|
const value = result.bytes;
|
|
@@ -478,7 +478,7 @@ export function withMediaCopies(inner, {maxPixels, maxInputBytes = 32 * 1024 * 1
|
|
|
478
478
|
: verified.source?.kind === 'bytes' && verified.source.digest === 'sha256:' + source) || !/^sha256:[a-f0-9]{64}$/.test(verified.outputDigest ?? '') ||
|
|
479
479
|
verified.width !== width || verified.height !== height || verified.format !== savedResult.format ||
|
|
480
480
|
verified.kept !== savedResult.kept || JSON.stringify(verified.fidelity) !== JSON.stringify(savedResult.fidelity))
|
|
481
|
-
throw failure('JXL_INPUT', "
|
|
481
|
+
throw failure('JXL_INPUT', "receipt: verify original/candidate");
|
|
482
482
|
} else if (!structural) {
|
|
483
483
|
let info;
|
|
484
484
|
try { info = await inspect(bytes, {details: ['layout'], maxInputBytes: maxCopyBytes, maxPixels, maxBoxes: 4096}); }
|
|
@@ -517,7 +517,7 @@ export function withMediaCopies(inner, {maxPixels, maxInputBytes = 32 * 1024 * 1
|
|
|
517
517
|
catch (error) { signal?.throwIfAborted(); if (replace || !error?.verification) throw error; receipt = error.verification; }
|
|
518
518
|
}
|
|
519
519
|
if (!structural && receipt?.verified !== true) {
|
|
520
|
-
if (replace) throw failure('JXL_INPUT', "
|
|
520
|
+
if (replace) throw failure('JXL_INPUT', "replacement: verify original");
|
|
521
521
|
return refused('not_verified');
|
|
522
522
|
}
|
|
523
523
|
// Ruling 91: the copy's color and its source's, both read from headers, ride in its ownership record.
|
|
@@ -526,7 +526,7 @@ export function withMediaCopies(inner, {maxPixels, maxInputBytes = 32 * 1024 * 1
|
|
|
526
526
|
const slot = variant ? `w${width}` : 'main', previous = replace ? await records(key, before.generation, signal, slot, false, call) : [];
|
|
527
527
|
// A persisted job reuses its identity; ordinary admissions are independent.
|
|
528
528
|
const identity = jobIdentity ?? crypto.randomUUID().replaceAll('-', '');
|
|
529
|
-
if (!COPY_ID.test(identity)) throw failure('JXL_INTERNAL', "
|
|
529
|
+
if (!COPY_ID.test(identity)) throw failure('JXL_INTERNAL', "media-storage:copy-id");
|
|
530
530
|
const sha256 = verified ? verified.outputDigest.slice(7) : await digest(bytes), prefix = await base(key), stem =
|
|
531
531
|
`${prefix}${before.generation}.${slot}.${identity}.${sha256}`;
|
|
532
532
|
const copyKey = stem + '.jxl', recordKey = stem + '.json';
|
|
@@ -535,7 +535,7 @@ export function withMediaCopies(inner, {maxPixels, maxInputBytes = 32 * 1024 * 1
|
|
|
535
535
|
...(preservedFor && {preservedFor}), ...(color && {color, sourceColor}), state: 'active'};
|
|
536
536
|
const recordBytes = utf8(JSON.stringify(valueRecord));
|
|
537
537
|
// The terminal state "retired" adds one byte to the serialized active record.
|
|
538
|
-
if (recordBytes.length + 1 > MAX_RECORD_BYTES) throw failure('JXL_LIMIT', "
|
|
538
|
+
if (recordBytes.length + 1 > MAX_RECORD_BYTES) throw failure('JXL_LIMIT', "ownership record: too large");
|
|
539
539
|
const owned = {...valueRecord, width, height, key: copyKey, recordKey, recordBytes, recordSize: recordBytes.length, size: bytes.length};
|
|
540
540
|
const changed = fence && await fence();
|
|
541
541
|
if (changed) return refused(changed);
|
|
@@ -589,7 +589,7 @@ export function withMediaCopies(inner, {maxPixels, maxInputBytes = 32 * 1024 * 1
|
|
|
589
589
|
// then the create-only record. A run stopped before the record leaves the copy unchecked; no key is overwritten.
|
|
590
590
|
async function checkColor(key, {signal, call = direct} = {}) {
|
|
591
591
|
publicKey(key);
|
|
592
|
-
if (typeof call !== 'function') throw failure('JXL_OPTIONS', "
|
|
592
|
+
if (typeof call !== 'function') throw failure('JXL_OPTIONS', "dispatcher: function");
|
|
593
593
|
if (!create) return {checked: 0, differs: 0, reason: 'conditional_write_required'};
|
|
594
594
|
if (!checkable(key)) return {checked: 0, differs: 0, reason: 'color_unread'};
|
|
595
595
|
const head = await sourceHead(key, {signal, call});
|
|
@@ -621,7 +621,7 @@ export function withMediaCopies(inner, {maxPixels, maxInputBytes = 32 * 1024 * 1
|
|
|
621
621
|
({source, generation, identity, sha256, bytes, result, kind, deliveryRevision, ...(color && {color, sourceColor}), key, recordKey});
|
|
622
622
|
// Retire a refused copy and remove its payload (attach's `collect`); only its own bytes are deleted.
|
|
623
623
|
async function collect(copy, {signal, call = direct} = {}) {
|
|
624
|
-
if (typeof call !== 'function') throw failure('JXL_OPTIONS', "
|
|
624
|
+
if (typeof call !== 'function') throw failure('JXL_OPTIONS', "dispatcher: function");
|
|
625
625
|
const prefix = typeof copy?.source === 'string' && IMAGE.test(copy.source) ? await base(copy.source) : null;
|
|
626
626
|
if (!prefix || !HASH.test(copy.generation ?? '') || !COPY_ID.test(copy.identity ?? '') || !HASH.test(copy.sha256 ?? '') ||
|
|
627
627
|
!COPY_ID.test(copy.deliveryRevision ?? '') ||
|
|
@@ -629,7 +629,7 @@ export function withMediaCopies(inner, {maxPixels, maxInputBytes = 32 * 1024 * 1
|
|
|
629
629
|
!copy.key.startsWith(prefix + copy.generation + '.') || !copy.key.endsWith(`.${copy.identity}.${copy.sha256}.jxl`) ||
|
|
630
630
|
copy.recordKey !== copy.key.slice(0, -4) + '.json' ||
|
|
631
631
|
((copy.color !== undefined || copy.sourceColor !== undefined) && !(isColor(copy.color) && isColor(copy.sourceColor))))
|
|
632
|
-
throw failure('JXL_INPUT', "
|
|
632
|
+
throw failure('JXL_INPUT', "retired copy: attach result");
|
|
633
633
|
return remove({...copy, owner: OWNER}, signal, call);
|
|
634
634
|
}
|
|
635
635
|
|
|
@@ -639,20 +639,20 @@ export function withMediaCopies(inner, {maxPixels, maxInputBytes = 32 * 1024 * 1
|
|
|
639
639
|
async function preserveArchiveDelivery(key, result, options = {}) {
|
|
640
640
|
const {signal, call = direct, source, expectedGeneration, expectedDeliveryRevision, receipt, jobIdentity, preservationId} = options;
|
|
641
641
|
if (!COPY_ID.test(preservationId ?? ''))
|
|
642
|
-
throw failure('JXL_INPUT', "
|
|
642
|
+
throw failure('JXL_INPUT', "restore record: reload");
|
|
643
643
|
const eligible = async () => {
|
|
644
644
|
const current = await deliveryState(key, {signal, call});
|
|
645
645
|
return current?.generation === expectedGeneration && current.mode === 'copies' && current.revision === expectedDeliveryRevision;
|
|
646
646
|
};
|
|
647
647
|
if (!await eligible()) return {preserved: true, reason: 'no_longer_selected'};
|
|
648
648
|
if (!(result?.bytes instanceof Uint8Array) || result.bytes.length < 2 || result.bytes.length > maxCopyBytes)
|
|
649
|
-
throw failure('JXL_LIMIT', "
|
|
649
|
+
throw failure('JXL_LIMIT', "archive copy: too large; retain delivery");
|
|
650
650
|
if (result.kept !== 'jpeg-bytes' || result.fidelity !== 'exact' || receipt?.verified !== true ||
|
|
651
651
|
receipt.kind !== 'jpeg-restore' || receipt.format !== 'jxl' || receipt.kept !== 'jpeg-bytes' || receipt.fidelity !== 'exact' ||
|
|
652
652
|
receipt.source?.kind !== 'bytes' || receipt.source.digest !== 'sha256:' + source ||
|
|
653
653
|
receipt.referenceDigest !== 'sha256:' + source || receipt.restoredDigest !== 'sha256:' + source ||
|
|
654
654
|
receipt.outputDigest !== 'sha256:' + await digest(result.bytes))
|
|
655
|
-
throw failure('JXL_INPUT', "
|
|
655
|
+
throw failure('JXL_INPUT', "archive receipt: verify original/candidate");
|
|
656
656
|
const published = await attach(key, result, {source, expectedGeneration, expectedDeliveryRevision, receipt,
|
|
657
657
|
jobIdentity, signal, call}, false, undefined, preservationId);
|
|
658
658
|
if (published?.stored === 'sidecar') return {preserved: true, publication: published};
|
|
@@ -662,7 +662,7 @@ export function withMediaCopies(inner, {maxPixels, maxInputBytes = 32 * 1024 * 1
|
|
|
662
662
|
if (published.collect) await collect(published.collect, {signal, call});
|
|
663
663
|
return {preserved: true, reason: 'no_longer_selected'};
|
|
664
664
|
}
|
|
665
|
-
throw failure('JXL_IO', "
|
|
665
|
+
throw failure('JXL_IO', "archive delivery: reconcile publication");
|
|
666
666
|
}
|
|
667
667
|
|
|
668
668
|
const extra = {
|
|
@@ -680,7 +680,7 @@ export function withMediaCopies(inner, {maxPixels, maxInputBytes = 32 * 1024 * 1
|
|
|
680
680
|
async sourceSnapshot(key, options) {
|
|
681
681
|
const file = await snapshot(key, options);
|
|
682
682
|
if (!file) return null;
|
|
683
|
-
if (!file.generation) throw failure('JXL_INPUT', "
|
|
683
|
+
if (!file.generation) throw failure('JXL_INPUT', "generation: source generation");
|
|
684
684
|
const selected = await delivery(key, file.generation, options?.signal, options?.call);
|
|
685
685
|
// Bind verification admission to the actual original, never a browser's smaller output or a plugin default.
|
|
686
686
|
// The public reader supplies geometry without decoding pixels. An unreadable header supplies no bound.
|
|
@@ -791,11 +791,11 @@ export function withMediaCopies(inner, {maxPixels, maxInputBytes = 32 * 1024 * 1
|
|
|
791
791
|
// removes the copy of each whose source is gone (remove() above). A source that is there, a record that is not
|
|
792
792
|
// ours and every other object are left as they are. Returns the cursor for the next step, null after the last page.
|
|
793
793
|
async sweepCopies({cursor, limit = 25, signal, call = direct} = {}) {
|
|
794
|
-
if (!Number.isSafeInteger(limit) || limit < 1 || limit > 100) throw failure('JXL_OPTIONS', "
|
|
794
|
+
if (!Number.isSafeInteger(limit) || limit < 1 || limit > 100) throw failure('JXL_OPTIONS', "limit: integer 1-100");
|
|
795
795
|
// One listing per first hex digit of a record's name: EmDash's local storage lists only the names that start with
|
|
796
796
|
// the prefix's last segment, so the whole folder cannot be listed at once. The cursor is "<digit>:<listing cursor>".
|
|
797
797
|
const at = /^([0-9a-f]):(.*)$/.exec(cursor ?? '0:');
|
|
798
|
-
if (!at) throw failure('JXL_OPTIONS', "
|
|
798
|
+
if (!at) throw failure('JXL_OPTIONS', "cursor: preceding step");
|
|
799
799
|
const page = await io(() => call(() => inner.list({prefix: ROOT + at[1], limit, signal, ...(at[2] ? {cursor: at[2]} : {})})), signal);
|
|
800
800
|
const next = page.nextCursor ? at[1] + ':' + page.nextCursor : at[1] === 'f' ? null : (parseInt(at[1], 16) + 1).toString(16) + ':';
|
|
801
801
|
const result = {examined: 0, removed: 0, cursor: next};
|
|
@@ -112,7 +112,7 @@ export const WORDS = {
|
|
|
112
112
|
setupAgentTab: 'Coding agent',
|
|
113
113
|
setupManualTab: 'By hand',
|
|
114
114
|
setupCommand: 'npx jpegxl add emdash',
|
|
115
|
-
setupAgent: 'Add
|
|
115
|
+
setupAgent: 'Add jpegxl to my EmDash site with npx jpegxl add emdash.',
|
|
116
116
|
setupInstall: 'npm install jpegxl \\\n @cloudflare/kumo@2.6.0',
|
|
117
117
|
setupManual: "import {jxl}\n from 'jpegxl/emdash';\n\njxl(emdash, {\n // Your existing EmDash options.\n})",
|
|
118
118
|
setupOpen: 'open the optimizer',
|
|
@@ -211,90 +211,90 @@ Options:
|
|
|
211
211
|
|
|
212
212
|
Uses EMDASH_TOKEN or the matching EmDash login.
|
|
213
213
|
`,
|
|
214
|
-
manual: "import {jxl} from 'jpegxl/emdash'
|
|
215
|
-
removeFix: `
|
|
216
|
-
addOption: '
|
|
217
|
-
addHelpFix: `run npx ${CLI} add emdash --help`,
|
|
214
|
+
manual: "import {jxl} from 'jpegxl/emdash'; use jxl(emdash, {...})",
|
|
215
|
+
removeFix: `restore JPEGs before disable; run npx ${CLI} remove emdash`,
|
|
216
|
+
addOption: 'unknown option: {option}',
|
|
217
|
+
addHelpFix: `run: npx ${CLI} add emdash --help`,
|
|
218
218
|
workersQuestion: 'Workers Paid?',
|
|
219
|
-
workersChoice: '
|
|
220
|
-
workersChoiceFix: `
|
|
221
|
-
workersAnswer: '
|
|
222
|
-
workersDowngrade: '
|
|
223
|
-
workersDowngradeFix: `run npx ${CLI} remove emdash
|
|
224
|
-
workersHost: '
|
|
225
|
-
workersHostFix: '
|
|
226
|
-
workersSource: '
|
|
227
|
-
workersSourceFix: '
|
|
228
|
-
workersEnvironment: '
|
|
229
|
-
workersEnvironmentFix: 'configure
|
|
230
|
-
workersJson: '
|
|
231
|
-
workersChanged: '
|
|
232
|
-
workersChangedFix: '
|
|
219
|
+
workersChoice: 'workers: --workers-paid or --workers-free',
|
|
220
|
+
workersChoiceFix: `flags: --workers-paid or --workers-free; Node: omit flags`,
|
|
221
|
+
workersAnswer: 'workers: yes or no',
|
|
222
|
+
workersDowngrade: 'workers-free: restore JPEGs first',
|
|
223
|
+
workersDowngradeFix: `run: npx ${CLI} remove emdash; then npx ${CLI} add emdash --workers-free`,
|
|
224
|
+
workersHost: 'cpuLimitMs: explicit number',
|
|
225
|
+
workersHostFix: 'cpuLimitMs: set third jxl() argument',
|
|
226
|
+
workersSource: 'wrangler: one source json/jsonc',
|
|
227
|
+
workersSourceFix: 'Paid: cpuLimitMs 30000, limits.cpu_ms 30000; Free: cpuLimitMs 10, no limits.cpu_ms',
|
|
228
|
+
workersEnvironment: 'worker environment: explicit selection',
|
|
229
|
+
workersEnvironmentFix: 'worker: configure matching environment and CPU allowance',
|
|
230
|
+
workersJson: 'wrangler: single JSON/JSONC object',
|
|
231
|
+
workersChanged: 'wrangler: changed during setup',
|
|
232
|
+
workersChangedFix: 'finish config edit; rerun setup',
|
|
233
233
|
updatedWrangler: 'Updated {file}.',
|
|
234
|
-
removeOption: '
|
|
235
|
-
removeHelpFix: `run npx ${CLI} remove emdash --help`,
|
|
236
|
-
explicitObject: '
|
|
237
|
-
explicitProperty: '
|
|
238
|
-
laterProperty: '
|
|
239
|
-
configSyntax: '
|
|
240
|
-
configSyntaxFix: 'fix
|
|
241
|
-
emdashImport: '
|
|
242
|
-
configDynamic: '
|
|
243
|
-
explicitIntegrations: '
|
|
244
|
-
reactMissing: '
|
|
245
|
-
reactFix: `add
|
|
246
|
-
oneIntegration: '
|
|
247
|
-
explicitOptions: '
|
|
248
|
-
explicitStorage: "
|
|
249
|
-
directWrapper: '
|
|
250
|
-
explicitWrapperImport: '
|
|
251
|
-
directEmdash: '
|
|
252
|
-
manifest: '
|
|
253
|
-
manifestFix: 'fix
|
|
254
|
-
ambiguousPackage: '
|
|
255
|
-
ambiguousPackageFix: `run ${CLI} add emdash --package <jpegxl.tgz
|
|
256
|
-
localPackage: '--package
|
|
257
|
-
localPackageFix: '
|
|
258
|
-
packageRead: '
|
|
259
|
-
packageReadFix: '
|
|
260
|
-
packageMissing: '
|
|
261
|
-
packageMissingFix: 'pack
|
|
262
|
-
managerType: 'packageManager
|
|
263
|
-
managerTypeFix: 'set
|
|
264
|
-
managerUnsupported: "
|
|
265
|
-
managerUnsupportedFix: 'install jpegxl and @cloudflare/kumo with
|
|
266
|
-
managerAmbiguous: '
|
|
267
|
-
managerAmbiguousFix: 'set packageManager in package.json
|
|
268
|
-
managerRun: '
|
|
269
|
-
managerRunFix: 'install jpegxl and @cloudflare/kumo with {manager}
|
|
270
|
-
managerExit: '{manager} install
|
|
271
|
-
managerExitCode: 'exit {code}',
|
|
272
|
-
managerExitFix: `
|
|
273
|
-
configFile: '
|
|
274
|
-
configFileFix: 'run
|
|
275
|
-
siteMissing: '
|
|
276
|
-
siteMissingFix: 'run
|
|
277
|
-
adminMissing: '
|
|
278
|
-
adminMissingFix: `install
|
|
279
|
-
kumoMismatch: '
|
|
280
|
-
kumoMismatchFix: `
|
|
281
|
-
dependencyOld: '{dependency} {minimum}
|
|
282
|
-
dependencyOldFix: `update {dependency}
|
|
234
|
+
removeOption: 'unknown option: {option}',
|
|
235
|
+
removeHelpFix: `run: npx ${CLI} remove emdash --help`,
|
|
236
|
+
explicitObject: '{property}: explicit object',
|
|
237
|
+
explicitProperty: '{property}: one explicit property',
|
|
238
|
+
laterProperty: '{property}: later spread/computed key',
|
|
239
|
+
configSyntax: 'astro.config.mjs: unreadable',
|
|
240
|
+
configSyntaxFix: 'fix JavaScript syntax; rerun',
|
|
241
|
+
emdashImport: 'import: one emdash/astro',
|
|
242
|
+
configDynamic: 'config: static object or defineConfig({...})',
|
|
243
|
+
explicitIntegrations: 'integrations: array without spreads',
|
|
244
|
+
reactMissing: 'integrations: react() needed',
|
|
245
|
+
reactFix: `add @astrojs/react; run npx ${CLI} add emdash`,
|
|
246
|
+
oneIntegration: 'integrations: one EmDash',
|
|
247
|
+
explicitOptions: 'EmDash options: explicit object',
|
|
248
|
+
explicitStorage: "storage: local() or r2()",
|
|
249
|
+
directWrapper: 'wrapper: direct call',
|
|
250
|
+
explicitWrapperImport: 'wrapper: explicit import',
|
|
251
|
+
directEmdash: 'EmDash: direct call',
|
|
252
|
+
manifest: '{file}: unreadable',
|
|
253
|
+
manifestFix: 'fix {file}; rerun',
|
|
254
|
+
ambiguousPackage: 'package: ambiguous npx source',
|
|
255
|
+
ambiguousPackageFix: `run: ${CLI} add emdash --package <jpegxl.tgz>`,
|
|
256
|
+
localPackage: '--package: local .tgz',
|
|
257
|
+
localPackageFix: 'use npm pack tarball',
|
|
258
|
+
packageRead: 'tarball: unreadable',
|
|
259
|
+
packageReadFix: 'use intact npm pack tarball',
|
|
260
|
+
packageMissing: 'tarball: missing jpegxl/emdash',
|
|
261
|
+
packageMissingFix: 'pack build with jpegxl/emdash',
|
|
262
|
+
managerType: 'packageManager: string',
|
|
263
|
+
managerTypeFix: 'set packageManager in package.json',
|
|
264
|
+
managerUnsupported: "package manager: {manager} unsupported",
|
|
265
|
+
managerUnsupportedFix: 'install jpegxl and @cloudflare/kumo with {manager}',
|
|
266
|
+
managerAmbiguous: 'lockfiles: multiple package managers',
|
|
267
|
+
managerAmbiguousFix: 'set packageManager in package.json',
|
|
268
|
+
managerRun: '{manager}: run failed',
|
|
269
|
+
managerRunFix: 'install jpegxl and @cloudflare/kumo with {manager}',
|
|
270
|
+
managerExit: '{manager}: install failed ({reason})',
|
|
271
|
+
managerExitCode: 'exit: {code}',
|
|
272
|
+
managerExitFix: `fix install; run npx ${CLI} add emdash`,
|
|
273
|
+
configFile: 'astro.config.mjs: regular unlinked file',
|
|
274
|
+
configFileFix: 'run in EmDash site; otherwise configure jxl() manually',
|
|
275
|
+
siteMissing: 'site: EmDash and Astro dependencies',
|
|
276
|
+
siteMissingFix: 'run in EmDash site folder',
|
|
277
|
+
adminMissing: '@cloudflare/kumo: >=2.6.0',
|
|
278
|
+
adminMissingFix: `install EmDash dependencies; run npx ${CLI} add emdash`,
|
|
279
|
+
kumoMismatch: '@cloudflare/kumo: {siteVersion} vs {hostVersion}',
|
|
280
|
+
kumoMismatchFix: `install @cloudflare/kumo@{hostVersion}; run npx ${CLI} add emdash`,
|
|
281
|
+
dependencyOld: '{dependency}: >= {minimum}, got {version}',
|
|
282
|
+
dependencyOldFix: `update {dependency}; run npx ${CLI} add emdash`,
|
|
283
283
|
installing: 'Installing {packages} with {manager}…',
|
|
284
284
|
dryRun: 'Dry run, nothing changed. Would install: {packages}. Would update: {files}.',
|
|
285
285
|
dryRunNone: 'nothing',
|
|
286
286
|
tarball: 'the jpegxl tarball',
|
|
287
287
|
packageSeparator: ' and ',
|
|
288
|
-
installedMissing: '
|
|
289
|
-
installedMissingFix: 'reinstall jpegxl
|
|
290
|
-
packageChanged: '
|
|
291
|
-
packageChangedFix: 'finish packing
|
|
292
|
-
dependencyMissing: '{dependency} {minimum}
|
|
293
|
-
dependencyMissingFix: "install {dependency}
|
|
294
|
-
kumoInstalledMismatch: '
|
|
295
|
-
kumoInstalledFix: "install @cloudflare/kumo@{hostVersion}
|
|
296
|
-
configChanged: 'astro.config.mjs changed during {action}
|
|
297
|
-
configChangedFix: 'review
|
|
288
|
+
installedMissing: 'package: missing jpegxl/emdash',
|
|
289
|
+
installedMissingFix: 'reinstall jpegxl; rerun',
|
|
290
|
+
packageChanged: 'package: changed during setup',
|
|
291
|
+
packageChangedFix: 'finish packing; rerun setup',
|
|
292
|
+
dependencyMissing: '{dependency}: >= {minimum} required',
|
|
293
|
+
dependencyMissingFix: "install {dependency}; rerun",
|
|
294
|
+
kumoInstalledMismatch: '@cloudflare/kumo: admin mismatch',
|
|
295
|
+
kumoInstalledFix: "install @cloudflare/kumo@{hostVersion}; rerun",
|
|
296
|
+
configChanged: 'astro.config.mjs: changed during {action}',
|
|
297
|
+
configChangedFix: 'review config; rerun',
|
|
298
298
|
setup: 'setup',
|
|
299
299
|
removal: 'removal',
|
|
300
300
|
updated: 'Updated astro.config.mjs. The site keeps its existing storage and plugins.',
|
|
@@ -304,16 +304,16 @@ Uses EMDASH_TOKEN or the matching EmDash login.
|
|
|
304
304
|
alreadyRemoved: '{name} is not enabled in astro.config.mjs.',
|
|
305
305
|
removed: CLI_REMOVAL + ' Removed {name} from astro.config.mjs.',
|
|
306
306
|
restartRemoved: 'Rebuild and redeploy the site to finish removal.',
|
|
307
|
-
removalUrl: '
|
|
308
|
-
removalUrlFix: '
|
|
309
|
-
removalClient: '
|
|
310
|
-
removalClientFix: "install
|
|
311
|
-
credentials: '
|
|
312
|
-
loginFix: 'run npx emdash login --url {url}
|
|
313
|
-
credentialHeader: '
|
|
314
|
-
requestFailed: '
|
|
315
|
-
responseInvalid: '
|
|
316
|
-
restorationMismatch: '
|
|
317
|
-
restorationFailed: 'JPEG restoration
|
|
307
|
+
removalUrl: 'url: HTTPS or localhost HTTP',
|
|
308
|
+
removalUrlFix: '--url: origin only; no credentials/path/query/fragment',
|
|
309
|
+
removalClient: 'EmDash transport: unavailable',
|
|
310
|
+
removalClientFix: "install EmDash dependencies; rerun",
|
|
311
|
+
credentials: 'login: expired or missing',
|
|
312
|
+
loginFix: 'run: npx emdash login --url {url}; or EMDASH_TOKEN',
|
|
313
|
+
credentialHeader: 'login: invalid custom headers',
|
|
314
|
+
requestFailed: 'restoration request: {status}',
|
|
315
|
+
responseInvalid: 'restoration response: invalid',
|
|
316
|
+
restorationMismatch: 'restoration response: wrong site/backend/operation',
|
|
317
|
+
restorationFailed: 'JPEG restoration: incomplete',
|
|
318
318
|
restoring: 'Restoring JPEGs: {count}',
|
|
319
319
|
};
|
|
@@ -25,7 +25,7 @@ async function browserVerified(file, result, progress) {
|
|
|
25
25
|
configureDecoder(decode, restore);
|
|
26
26
|
const browserVerification = await verify(file, result, {onProgress: progress});
|
|
27
27
|
if (browserVerification?.verified !== true)
|
|
28
|
-
throw Object.assign(new Error("
|
|
28
|
+
throw Object.assign(new Error("delivery: verify original/candidate"), {code: 'JXL_INPUT'});
|
|
29
29
|
// Informational browser assurance is deliberately separate from the private server receipt.
|
|
30
30
|
const {verification: ignored, ...candidate} = result;
|
|
31
31
|
return {...candidate, browserVerification};
|
|
@@ -6,7 +6,7 @@ const UUID = Uint8Array.of(0x65, 0x6d, 0x64, 0x61, 0x73, 0x68, 0x4a, 0x58, 0x8c,
|
|
|
6
6
|
export const ENVELOPE_BYTES = 40;
|
|
7
7
|
export const ENVELOPE_PREFIX_BYTES = 4096;
|
|
8
8
|
const equal = (a, b) => a.length === b.length && a.every((value, i) => value === b[i]);
|
|
9
|
-
const fail = () => Object.assign(new Error("
|
|
9
|
+
const fail = () => Object.assign(new Error("archive: unwrapped JXL; ID: 32 hex"), {code: 'JXL_INPUT'});
|
|
10
10
|
function insertion(bytes) {
|
|
11
11
|
if (!(bytes instanceof Uint8Array) || bytes.length < 20 || !equal(bytes.subarray(0, 12), SIGNATURE) ||
|
|
12
12
|
String.fromCharCode(...bytes.subarray(16, 20)) !== 'ftyp') throw fail();
|
|
@@ -36,7 +36,7 @@ export function wrapOriginal(payload, id) {
|
|
|
36
36
|
export function unwrapOriginal(bytes, id, payloadBytes) {
|
|
37
37
|
const marker = envelopeIdentity(bytes);
|
|
38
38
|
if (!marker || marker.id !== id || bytes.length !== payloadBytes + ENVELOPE_BYTES)
|
|
39
|
-
throw Object.assign(new Error("
|
|
39
|
+
throw Object.assign(new Error("archive owner: restore matching original"), {code: 'JXL_INPUT'});
|
|
40
40
|
const payload = new Uint8Array(payloadBytes);
|
|
41
41
|
payload.set(bytes.subarray(0, marker.offset));
|
|
42
42
|
payload.set(bytes.subarray(marker.offset + ENVELOPE_BYTES), marker.offset);
|