Compare commits
2
Commits
b5e50f786b
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1b36fbaeba | ||
|
|
0de7a87938 |
@@ -10,7 +10,7 @@
|
||||
<p v-if="!fileName" class="text-sm text-muted-foreground">Select an image to view its metadata.</p>
|
||||
|
||||
<template v-else-if="entry.status === 'error' && !entry.output">
|
||||
<p class="text-sm text-destructive">{{ entry.message }}</p>
|
||||
<p class="whitespace-pre-wrap text-sm text-destructive">{{ entry.detailMessage ?? entry.message }}</p>
|
||||
</template>
|
||||
|
||||
<template v-else-if="showMetadataTabs">
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
<MetadataOutputPanel v-if="tabBody?.kind === 'output'">{{ tabBody.text }}</MetadataOutputPanel>
|
||||
|
||||
<p v-else-if="tabBody?.kind === 'error'" class="text-sm text-destructive">{{ tabBody.text }}</p>
|
||||
<p v-else-if="tabBody?.kind === 'error'" class="whitespace-pre-wrap text-sm text-destructive">{{ tabBody.text }}</p>
|
||||
</template>
|
||||
|
||||
<p v-else class="text-sm text-muted-foreground">{{ entry.message }}</p>
|
||||
@@ -83,7 +83,7 @@ const tabBody = computed((): MetadataTabBody | null => {
|
||||
}
|
||||
|
||||
if (entry.status === 'error') {
|
||||
return { kind: 'error', text: entry.message };
|
||||
return { kind: 'error', text: entry.detailMessage ?? entry.message };
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -97,10 +97,10 @@ const formatMetadataPreviewMessage = (entry: MetadataPreviewEntry): string => {
|
||||
const percent = wasmDownloadPercent.value;
|
||||
|
||||
if (percent === null) {
|
||||
return 'Downloading ExifTool…';
|
||||
return entry.message;
|
||||
}
|
||||
|
||||
return `Downloading ExifTool… ${percent}%`;
|
||||
return `${entry.message} ${percent}%`;
|
||||
}
|
||||
|
||||
return entry.message;
|
||||
|
||||
@@ -3,6 +3,7 @@ import { ref } from 'vue';
|
||||
import { useExiftoolStore } from '@/stores/exiftool';
|
||||
import type { MetadataPreviewEntry } from '@/types/metadata/MetadataPreview';
|
||||
import { makeKeyFromFile } from '@/utils/file/makeKeyFromFile';
|
||||
import { resolveErrorMessage } from '@/utils/resolveErrorMessage';
|
||||
|
||||
const METADATA_IDLE_MESSAGE = 'Waiting to load metadata...';
|
||||
const EXIFTOOL_INITIALIZING_MESSAGE = 'Downloading ExifTool…';
|
||||
@@ -17,11 +18,6 @@ const METADATA_IDLE_PREVIEW: MetadataPreviewEntry = {
|
||||
message: METADATA_IDLE_MESSAGE
|
||||
};
|
||||
|
||||
const METADATA_LOAD_ERROR_PREVIEW: MetadataPreviewEntry = {
|
||||
status: 'error',
|
||||
message: METADATA_LOAD_ERROR_MESSAGE
|
||||
};
|
||||
|
||||
const EXIFTOOL_PREPARE_ERROR_PREVIEW: MetadataPreviewEntry = {
|
||||
status: 'error',
|
||||
message: EXIFTOOL_PREPARE_ERROR_MESSAGE
|
||||
@@ -96,9 +92,15 @@ export const useMetadataStore = defineStore('metadata', () => {
|
||||
} catch (error) {
|
||||
console.error('[metadata] read failed', { file: file.name, error });
|
||||
|
||||
setPreviewEntry(key, METADATA_LOAD_ERROR_PREVIEW);
|
||||
const entry: MetadataPreviewEntry = {
|
||||
status: 'error',
|
||||
message: METADATA_LOAD_ERROR_MESSAGE,
|
||||
detailMessage: resolveErrorMessage(error, METADATA_LOAD_ERROR_MESSAGE)
|
||||
};
|
||||
|
||||
return METADATA_LOAD_ERROR_PREVIEW;
|
||||
setPreviewEntry(key, entry);
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
let strippedBlob: Blob;
|
||||
@@ -116,6 +118,7 @@ export const useMetadataStore = defineStore('metadata', () => {
|
||||
const entry: MetadataPreviewEntry = {
|
||||
status: 'error',
|
||||
message: METADATA_STRIP_ERROR_MESSAGE,
|
||||
detailMessage: resolveErrorMessage(error, METADATA_STRIP_ERROR_MESSAGE),
|
||||
output
|
||||
};
|
||||
|
||||
@@ -136,9 +139,16 @@ export const useMetadataStore = defineStore('metadata', () => {
|
||||
} catch (error) {
|
||||
console.error('[metadata] read after strip failed', { file: file.name, error });
|
||||
|
||||
setPreviewEntry(key, METADATA_LOAD_ERROR_PREVIEW);
|
||||
const entry: MetadataPreviewEntry = {
|
||||
status: 'error',
|
||||
message: METADATA_LOAD_ERROR_MESSAGE,
|
||||
detailMessage: resolveErrorMessage(error, METADATA_LOAD_ERROR_MESSAGE),
|
||||
output
|
||||
};
|
||||
|
||||
return METADATA_LOAD_ERROR_PREVIEW;
|
||||
setPreviewEntry(key, entry);
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
setStrippedBlob(key, strippedBlob);
|
||||
|
||||
@@ -3,4 +3,4 @@ export type MetadataPreviewEntry =
|
||||
| { status: 'initializing'; message: string }
|
||||
| { status: 'processing'; message: string }
|
||||
| { status: 'ready'; message: string; output: string; afterStripOutput: string }
|
||||
| { status: 'error'; message: string; output?: string };
|
||||
| { status: 'error'; message: string; output?: string; detailMessage?: string };
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import type { AxiosProgressEvent } from 'axios';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { percentFromAxiosProgress } from '@/utils/percentFromAxiosProgress';
|
||||
|
||||
const progress = (loaded: number, total?: number): AxiosProgressEvent =>
|
||||
({
|
||||
loaded,
|
||||
total,
|
||||
bytes: 0,
|
||||
lengthComputable: total !== undefined
|
||||
}) as AxiosProgressEvent;
|
||||
|
||||
describe('percentFromAxiosProgress', () => {
|
||||
it('returns null when total is missing', () => {
|
||||
expect(percentFromAxiosProgress(progress(50))).toBeNull();
|
||||
});
|
||||
|
||||
it('returns rounded percent from loaded and total', () => {
|
||||
expect(percentFromAxiosProgress(progress(250, 1000))).toBe(25);
|
||||
expect(percentFromAxiosProgress(progress(1, 3))).toBe(33.33);
|
||||
});
|
||||
|
||||
it('caps at 100', () => {
|
||||
expect(percentFromAxiosProgress(progress(200, 100))).toBe(100);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
import type { AxiosProgressEvent } from 'axios';
|
||||
|
||||
export const percentFromAxiosProgress = (progressEvent: AxiosProgressEvent): number | null => {
|
||||
if (!progressEvent.total) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const percent = Math.min(100, (progressEvent.loaded / progressEvent.total) * 100);
|
||||
|
||||
return parseFloat(percent.toFixed(2));
|
||||
};
|
||||
@@ -4,6 +4,7 @@ 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';
|
||||
import { percentFromAxiosProgress } from '@/utils/percentFromAxiosProgress';
|
||||
import { resolveErrorMessage } from '@/utils/resolveErrorMessage';
|
||||
import { toArrayBuffer } from '@/utils/toArrayBuffer';
|
||||
|
||||
@@ -18,15 +19,13 @@ const fetchZeroperlWasm = async (): Promise<Response> => {
|
||||
const { data } = await axios.get<ArrayBuffer>(zeroperlWasmUrl, {
|
||||
responseType: 'arraybuffer',
|
||||
onDownloadProgress: progressEvent => {
|
||||
if (!progressEvent.total) {
|
||||
const percent = percentFromAxiosProgress(progressEvent);
|
||||
|
||||
if (percent === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
const percent = Math.min(100, (progressEvent.loaded / progressEvent.total) * 100);
|
||||
|
||||
const rounded = parseFloat(percent.toFixed(2));
|
||||
|
||||
self.postMessage({ type: 'wasm-download-progress', percent: rounded });
|
||||
self.postMessage({ type: 'wasm-download-progress', percent });
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user