Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b5e50f786b | ||
|
|
2290040242 |
Vendored
+1
@@ -28,5 +28,6 @@ declare module 'vue' {
|
|||||||
UploadQueueList: typeof import('./components/upload/UploadQueueList.vue')['default']
|
UploadQueueList: typeof import('./components/upload/UploadQueueList.vue')['default']
|
||||||
UploadSettingsPanel: typeof import('./components/upload/UploadSettingsPanel.vue')['default']
|
UploadSettingsPanel: typeof import('./components/upload/UploadSettingsPanel.vue')['default']
|
||||||
UploadShareResults: typeof import('./components/upload/UploadShareResults.vue')['default']
|
UploadShareResults: typeof import('./components/upload/UploadShareResults.vue')['default']
|
||||||
|
ViewerImageDisplay: typeof import('./components/viewer/ViewerImageDisplay.vue')['default']
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@
|
|||||||
{{ formatMetadataPreviewMessage(row.metadata) }}
|
{{ formatMetadataPreviewMessage(row.metadata) }}
|
||||||
</span>
|
</span>
|
||||||
<span class="min-w-0 truncate" :class="uploadStatusClass(row.upload)">
|
<span class="min-w-0 truncate" :class="uploadStatusClass(row.upload)">
|
||||||
{{ row.upload.message }}
|
{{ formatUploadQueueMessage(row.upload) }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -97,10 +97,24 @@ const formatMetadataPreviewMessage = (entry: MetadataPreviewEntry): string => {
|
|||||||
const percent = wasmDownloadPercent.value;
|
const percent = wasmDownloadPercent.value;
|
||||||
|
|
||||||
if (percent === null) {
|
if (percent === null) {
|
||||||
return 'Downloading ExifTool…';
|
return entry.message;
|
||||||
}
|
}
|
||||||
|
|
||||||
return `Downloading ExifTool… ${percent}%`;
|
return `${entry.message} ${percent}%`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return entry.message;
|
||||||
|
};
|
||||||
|
|
||||||
|
const formatUploadQueueMessage = (entry: UploadQueueEntry): string => {
|
||||||
|
if (entry.status === 'uploading') {
|
||||||
|
const percent = entry.uploadPercent;
|
||||||
|
|
||||||
|
if (percent === null || percent === undefined) {
|
||||||
|
return entry.message;
|
||||||
|
}
|
||||||
|
|
||||||
|
return `${entry.message} ${percent}%`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return entry.message;
|
return entry.message;
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
<template>
|
||||||
|
<div class="flex w-full min-h-0 flex-col items-center justify-center gap-3 text-center">
|
||||||
|
<img
|
||||||
|
:src="src"
|
||||||
|
decoding="async"
|
||||||
|
class="mx-auto block h-auto w-auto max-h-[min(calc(100dvh-12rem),calc(100vh-12rem))] max-w-[min(100%,calc(100vw-2rem))] object-contain"
|
||||||
|
:class="{ hidden: visuallyHidden }"
|
||||||
|
@load="emit('load')"
|
||||||
|
@error="emit('error')"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<a
|
||||||
|
v-if="!visuallyHidden"
|
||||||
|
:href="src"
|
||||||
|
class="text-sm text-muted-foreground underline-offset-2 hover:text-foreground hover:underline"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
target="_blank"
|
||||||
|
>
|
||||||
|
Open full image
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
defineProps({
|
||||||
|
src: {
|
||||||
|
type: String,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
visuallyHidden: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
load: [];
|
||||||
|
error: [];
|
||||||
|
}>();
|
||||||
|
</script>
|
||||||
@@ -16,6 +16,8 @@ import { prepareHotlinkUploadRequest } from '@/utils/upload/prepareHotlinkUpload
|
|||||||
import { prepareZkUploadRequest } from '@/utils/upload/prepareZkUploadRequest';
|
import { prepareZkUploadRequest } from '@/utils/upload/prepareZkUploadRequest';
|
||||||
import type { PreparedZkUploadRequest } from '@/types/upload/PreparedZkUploadRequest';
|
import type { PreparedZkUploadRequest } from '@/types/upload/PreparedZkUploadRequest';
|
||||||
import type { PreparedHotlinkUploadRequest } from '@/types/upload/PreparedHotlinkUploadRequest';
|
import type { PreparedHotlinkUploadRequest } from '@/types/upload/PreparedHotlinkUploadRequest';
|
||||||
|
import { percentFromAxiosProgress } from '@/utils/percentFromAxiosProgress';
|
||||||
|
import type { AxiosProgressEvent } from 'axios';
|
||||||
|
|
||||||
const UPLOAD_IDLE_MESSAGE = 'Waiting to upload...';
|
const UPLOAD_IDLE_MESSAGE = 'Waiting to upload...';
|
||||||
const UPLOAD_QUEUED_MESSAGE = 'Upload queued';
|
const UPLOAD_QUEUED_MESSAGE = 'Upload queued';
|
||||||
@@ -39,10 +41,11 @@ const UPLOAD_QUEUED_ENTRY: UploadQueueEntry = {
|
|||||||
message: UPLOAD_QUEUED_MESSAGE
|
message: UPLOAD_QUEUED_MESSAGE
|
||||||
};
|
};
|
||||||
|
|
||||||
const UPLOAD_UPLOADING_ENTRY: UploadQueueEntry = {
|
const buildUploadingEntry = (uploadPercent: number | null = null): UploadQueueEntry => ({
|
||||||
status: 'uploading',
|
status: 'uploading',
|
||||||
message: UPLOAD_UPLOADING_MESSAGE
|
message: UPLOAD_UPLOADING_MESSAGE,
|
||||||
};
|
uploadPercent
|
||||||
|
});
|
||||||
|
|
||||||
const UPLOAD_FAILED_ENTRY: UploadQueueEntry = {
|
const UPLOAD_FAILED_ENTRY: UploadQueueEntry = {
|
||||||
status: 'failed',
|
status: 'failed',
|
||||||
@@ -80,17 +83,41 @@ export const useUploadStore = defineStore('upload', () => {
|
|||||||
uploadByKey.value = {};
|
uploadByKey.value = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
const uploadZk = async (body: CreateZkUploadRequest, altcha?: string): Promise<CreatedUploadResult> => {
|
const getUploadRequestHeaders = (altcha?: string) => (altcha ? { [ALTCHA_REQUEST_HEADER]: altcha } : undefined);
|
||||||
|
|
||||||
|
const onUploadProgress = (queueKey: string, progressEvent: AxiosProgressEvent): void => {
|
||||||
|
const percent = percentFromAxiosProgress(progressEvent);
|
||||||
|
|
||||||
|
if (percent !== null) {
|
||||||
|
const entry = buildUploadingEntry(percent);
|
||||||
|
|
||||||
|
setUploadEntry(queueKey, entry);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const uploadZk = async (
|
||||||
|
body: CreateZkUploadRequest,
|
||||||
|
altcha: string | undefined,
|
||||||
|
queueKey: string
|
||||||
|
): Promise<CreatedUploadResult> => {
|
||||||
const { data } = await api.post<CreatedUploadResult>('/uploads/zk', body, {
|
const { data } = await api.post<CreatedUploadResult>('/uploads/zk', body, {
|
||||||
headers: getUploadRequestHeaders(altcha)
|
headers: getUploadRequestHeaders(altcha),
|
||||||
|
onUploadProgress: progressEvent => onUploadProgress(queueKey, progressEvent)
|
||||||
});
|
});
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
const uploadHotlink = async (body: CreateHotlinkUploadRequest, altcha?: string): Promise<CreatedUploadResult> => {
|
const uploadHotlink = async (
|
||||||
|
body: CreateHotlinkUploadRequest,
|
||||||
|
altcha: string | undefined,
|
||||||
|
queueKey: string
|
||||||
|
): Promise<CreatedUploadResult> => {
|
||||||
const { data } = await api.post<CreatedUploadResult>('/uploads/hotlink', body, {
|
const { data } = await api.post<CreatedUploadResult>('/uploads/hotlink', body, {
|
||||||
headers: getUploadRequestHeaders(altcha)
|
headers: getUploadRequestHeaders(altcha),
|
||||||
|
onUploadProgress: progressEvent => {
|
||||||
|
onUploadProgress(queueKey, progressEvent);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
@@ -102,8 +129,6 @@ export const useUploadStore = defineStore('upload', () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const getUploadRequestHeaders = (altcha?: string) => (altcha ? { [ALTCHA_REQUEST_HEADER]: altcha } : undefined);
|
|
||||||
|
|
||||||
const uploadBatch = async (
|
const uploadBatch = async (
|
||||||
files: readonly File[],
|
files: readonly File[],
|
||||||
settings: UploadBatchSettingsForm,
|
settings: UploadBatchSettingsForm,
|
||||||
@@ -176,11 +201,14 @@ export const useUploadStore = defineStore('upload', () => {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
setUploadEntry(key, UPLOAD_UPLOADING_ENTRY);
|
const entry = buildUploadingEntry();
|
||||||
|
|
||||||
|
setUploadEntry(key, entry);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { request, fragmentKey } = prepared;
|
const { request, fragmentKey } = prepared;
|
||||||
|
|
||||||
const result = await uploadZk(request, altcha);
|
const result = await uploadZk(request, altcha, key);
|
||||||
|
|
||||||
setUploadEntry(key, {
|
setUploadEntry(key, {
|
||||||
status: 'uploaded',
|
status: 'uploaded',
|
||||||
@@ -209,11 +237,13 @@ export const useUploadStore = defineStore('upload', () => {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
setUploadEntry(key, UPLOAD_UPLOADING_ENTRY);
|
const entry = buildUploadingEntry();
|
||||||
|
|
||||||
|
setUploadEntry(key, entry);
|
||||||
try {
|
try {
|
||||||
const { request, secret } = prepared;
|
const { request, secret } = prepared;
|
||||||
|
|
||||||
const result = await uploadHotlink(request, altcha);
|
const result = await uploadHotlink(request, altcha, key);
|
||||||
|
|
||||||
setUploadEntry(key, {
|
setUploadEntry(key, {
|
||||||
status: 'uploaded',
|
status: 'uploaded',
|
||||||
@@ -253,7 +283,6 @@ export const useUploadStore = defineStore('upload', () => {
|
|||||||
} else {
|
} else {
|
||||||
setUploadEntry(key, { status: 'skipped', message: UPLOAD_SKIPPED_METADATA_MESSAGE });
|
setUploadEntry(key, { status: 'skipped', message: UPLOAD_SKIPPED_METADATA_MESSAGE });
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ export type UploadQueueEntry =
|
|||||||
| { status: 'idle'; message: string }
|
| { status: 'idle'; message: string }
|
||||||
| { status: 'queued'; message: string }
|
| { status: 'queued'; message: string }
|
||||||
| { status: 'preparing'; message: string }
|
| { status: 'preparing'; message: string }
|
||||||
| { status: 'uploading'; message: string }
|
| { status: 'uploading'; message: string; uploadPercent?: number | null }
|
||||||
| {
|
| {
|
||||||
status: 'uploaded';
|
status: 'uploaded';
|
||||||
message: string;
|
message: 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));
|
||||||
|
};
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<main
|
<main class="flex min-h-0 w-full flex-1 flex-col items-center justify-center px-4 py-4 sm:px-6">
|
||||||
class="mx-auto flex w-full max-w-lg flex-1 flex-col items-center justify-center gap-3 px-4 py-6 text-center sm:px-6 sm:py-8"
|
|
||||||
>
|
|
||||||
<p v-if="state === 'invalidLink'" class="text-sm text-muted-foreground">
|
<p v-if="state === 'invalidLink'" class="text-sm text-muted-foreground">
|
||||||
This viewing link is incomplete. Use the hotlink URL from your upload results.
|
This viewing link is incomplete. Use the hotlink URL from your upload results.
|
||||||
</p>
|
</p>
|
||||||
@@ -11,11 +9,10 @@
|
|||||||
<template v-else>
|
<template v-else>
|
||||||
<p v-if="state === 'loading'" class="text-sm text-muted-foreground sm:text-base">Loading image...</p>
|
<p v-if="state === 'loading'" class="text-sm text-muted-foreground sm:text-base">Loading image...</p>
|
||||||
|
|
||||||
<img
|
<ViewerImageDisplay
|
||||||
v-if="imageSrc"
|
v-if="imageSrc"
|
||||||
:src="imageSrc"
|
:src="imageSrc"
|
||||||
class="max-h-[min(80vh,100dvh)] w-full object-contain"
|
:visually-hidden="state === 'loading'"
|
||||||
:class="{ hidden: state === 'loading' }"
|
|
||||||
@load="onImageLoad"
|
@load="onImageLoad"
|
||||||
@error="onImageError"
|
@error="onImageError"
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<main
|
<main class="flex min-h-0 w-full flex-1 flex-col items-center justify-center px-4 py-4 sm:px-6">
|
||||||
class="mx-auto flex w-full max-w-lg flex-1 flex-col items-center justify-center gap-3 px-4 py-6 text-center sm:px-6 sm:py-8"
|
|
||||||
>
|
|
||||||
<p v-if="state === 'loading'" class="text-sm text-muted-foreground sm:text-base">Loading image...</p>
|
<p v-if="state === 'loading'" class="text-sm text-muted-foreground sm:text-base">Loading image...</p>
|
||||||
|
|
||||||
<p v-else-if="state === 'invalidLink'" class="text-sm text-muted-foreground">
|
<p v-else-if="state === 'invalidLink'" class="text-sm text-muted-foreground">
|
||||||
@@ -37,10 +35,9 @@
|
|||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<img
|
<ViewerImageDisplay
|
||||||
v-else-if="state === 'image' && imageObjectUrl"
|
v-else-if="state === 'image' && imageObjectUrl"
|
||||||
:src="imageObjectUrl"
|
:src="imageObjectUrl"
|
||||||
class="max-h-[min(80vh,100dvh)] w-full object-contain"
|
|
||||||
/>
|
/>
|
||||||
</main>
|
</main>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import axios from 'axios';
|
|||||||
import { EXIFTOOL_WORKER_INIT_JPEG } from '@/consts/exiftoolWorkerInitJpeg';
|
import { EXIFTOOL_WORKER_INIT_JPEG } from '@/consts/exiftoolWorkerInitJpeg';
|
||||||
import type { ExiftoolWorkerInMessage } from '@/types/workers/exiftoolWorkerInMessage';
|
import type { ExiftoolWorkerInMessage } from '@/types/workers/exiftoolWorkerInMessage';
|
||||||
import type { ExiftoolWorkerJob } from '@/types/workers/exiftoolWorkerJob';
|
import type { ExiftoolWorkerJob } from '@/types/workers/exiftoolWorkerJob';
|
||||||
|
import { percentFromAxiosProgress } from '@/utils/percentFromAxiosProgress';
|
||||||
import { resolveErrorMessage } from '@/utils/resolveErrorMessage';
|
import { resolveErrorMessage } from '@/utils/resolveErrorMessage';
|
||||||
import { toArrayBuffer } from '@/utils/toArrayBuffer';
|
import { toArrayBuffer } from '@/utils/toArrayBuffer';
|
||||||
|
|
||||||
@@ -18,15 +19,13 @@ const fetchZeroperlWasm = async (): Promise<Response> => {
|
|||||||
const { data } = await axios.get<ArrayBuffer>(zeroperlWasmUrl, {
|
const { data } = await axios.get<ArrayBuffer>(zeroperlWasmUrl, {
|
||||||
responseType: 'arraybuffer',
|
responseType: 'arraybuffer',
|
||||||
onDownloadProgress: progressEvent => {
|
onDownloadProgress: progressEvent => {
|
||||||
if (!progressEvent.total) {
|
const percent = percentFromAxiosProgress(progressEvent);
|
||||||
|
|
||||||
|
if (percent === null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const percent = Math.min(100, (progressEvent.loaded / progressEvent.total) * 100);
|
self.postMessage({ type: 'wasm-download-progress', percent });
|
||||||
|
|
||||||
const rounded = parseFloat(percent.toFixed(2));
|
|
||||||
|
|
||||||
self.postMessage({ type: 'wasm-download-progress', percent: rounded });
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user