Show ExifTool WASM download progress on upload queue rows.
Stream progress from the worker via axios, expose percent in the exiftool store, and format it on initializing metadata lines.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import zeroperlWasmUrl from '@6over3/zeroperl-ts/zeroperl.wasm?url';
|
||||
import { parseMetadata, writeMetadata } from '@uswriting/exiftool';
|
||||
import axios from 'axios';
|
||||
import { EXIFTOOL_WORKER_INIT_JPEG } from '@/consts/exiftoolWorkerInitJpeg';
|
||||
import type { ExiftoolWorkerInMessage } from '@/types/workers/exiftoolWorkerInMessage';
|
||||
import type { ExiftoolWorkerJob } from '@/types/workers/exiftoolWorkerJob';
|
||||
@@ -14,13 +15,22 @@ let cachedZeroperlWasm: ArrayBuffer | null = null;
|
||||
*/
|
||||
const fetchZeroperlWasm = async (): Promise<Response> => {
|
||||
if (!cachedZeroperlWasm) {
|
||||
const response = await fetch(zeroperlWasmUrl);
|
||||
const { data } = await axios.get<ArrayBuffer>(zeroperlWasmUrl, {
|
||||
responseType: 'arraybuffer',
|
||||
onDownloadProgress: progressEvent => {
|
||||
if (!progressEvent.total) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to load zeroperl.wasm: HTTP ${response.status}`);
|
||||
}
|
||||
const percent = Math.min(100, (progressEvent.loaded / progressEvent.total) * 100);
|
||||
|
||||
cachedZeroperlWasm = await response.arrayBuffer();
|
||||
const rounded = parseFloat(percent.toFixed(2));
|
||||
|
||||
self.postMessage({ type: 'wasm-download-progress', percent: rounded });
|
||||
}
|
||||
});
|
||||
|
||||
cachedZeroperlWasm = data;
|
||||
}
|
||||
|
||||
return new Response(cachedZeroperlWasm, {
|
||||
|
||||
Reference in New Issue
Block a user