Self-hosted personal gallery application with online photo management and albums, supporting Live/Motion Photos, EXIF parsing, geolocation recognition, and an explore map.
TypeScript albumsexif-extractiongeocodinglive-photomotion-photophoto-galleryphoto-sharingwebgl-viewer
fix(upload): address review feedback on the shared upload flow
Timothy Yin217759599440
diff --git a/apps/cloud/app/components/CloudTransferPanel.vue b/apps/cloud/app/components/CloudTransferPanel.vueindex 9f27423f..88d1941d 100644--- a/apps/cloud/app/components/CloudTransferPanel.vue+++ b/apps/cloud/app/components/CloudTransferPanel.vue@@ -50,10 +50,10 @@ async function jobAction(fileId: string, operation: 'retry' | 'delete') {<Teleport to="body"><UploadQueuePanel:uploading-files="uploadingFiles"+ :show-queue-link="false"@remove-file="remove"@clear-completed="clearCompleted"@clear-all="clearAll"- @go-to-queue="navigateTo('/sites')"><template #file-details="{ fileId }"><NuxtLinkdiff --git a/apps/cloud/app/composables/useCloudSiteMedia.ts b/apps/cloud/app/composables/useCloudSiteMedia.tsindex 9ba38b0f..48dd4e8e 100644--- a/apps/cloud/app/composables/useCloudSiteMedia.ts+++ b/apps/cloud/app/composables/useCloudSiteMedia.ts@@ -356,7 +356,14 @@ export function useCloudMediaWorkspace(props: {!isVideo(file) &&file.size + (companionFor(file)?.size ?? 0) > fileLimit.value,) ||- files.every(isVideo)+ files.every(isVideo) ||+ files.some(+ (video) =>+ isVideo(video) &&+ !files.some(+ (photo) => !isVideo(photo) && companionFor(photo) === video,+ ),+ )) {failed.value = truemessage.value = t(diff --git a/apps/cloud/app/composables/useCloudUploads.ts b/apps/cloud/app/composables/useCloudUploads.tsindex 0f5fd2c8..50e65e48 100644--- a/apps/cloud/app/composables/useCloudUploads.ts+++ b/apps/cloud/app/composables/useCloudUploads.ts@@ -75,6 +75,7 @@ function createCloudUploads() {context: CloudUploadContext,path: string,body?: Record<string, unknown>,+ signal?: AbortSignal,): Promise<T> {// Navigation changes the active Site, not the authority of an admitted upload.if (disposed || userId.value !== context.userId)@@ -84,6 +85,7 @@ function createCloudUploads() {{method: body ? 'POST' : 'GET',...(body ? { body } : {}),+ ...(signal ? { signal } : {}),},)if (disposed || userId.value !== context.userId)@@ -127,8 +129,6 @@ function createCloudUploads() {}for (const job of jobs) {const key = `${context.scope}:${job.id}`- if (['queued', 'running', 'retry_wait'].includes(job.state))- dismissed.delete(key)const existing = [...tracked].filter(([, item]) =>item.context.scope === context.scope && item.jobId === job.id,@@ -184,6 +184,7 @@ function createCloudUploads() {return}const id = localStorage.getItem(cache) || crypto.randomUUID()+ dismissed.delete(`${context.scope}:${id}`)activeReservations.add(cache)let reserved = falselet cancellation: Promise<unknown> | undefined@@ -202,16 +203,21 @@ function createCloudUploads() {queue.notify()try {signal.throwIfAborted()- await api(context, '/uploads', {- requestId: id,- connectionId: connection,- fileName: file.name,- bytes: file.size,- albumIds,- ...(liveVideo- ? { liveVideo: { fileName: liveVideo.name, bytes: liveVideo.size } }- : {}),- })+ await api(+ context,+ '/uploads',+ {+ requestId: id,+ connectionId: connection,+ fileName: file.name,+ bytes: file.size,+ albumIds,+ ...(liveVideo+ ? { liveVideo: { fileName: liveVideo.name, bytes: liveVideo.size } }+ : {}),+ },+ signal,+ )reserved = truelocalStorage.setItem(cache, id)signal.throwIfAborted()@@ -219,6 +225,7 @@ function createCloudUploads() {context,`/uploads/${id}/plan`,{},+ signal,)signal.throwIfAborted()if (plan.state !== 'completed') {diff --git a/apps/cloud/server/api/sites/[siteId]/media/[...operation].ts b/apps/cloud/server/api/sites/[siteId]/media/[...operation].tsindex fb356a61..698e4f76 100644--- a/apps/cloud/server/api/sites/[siteId]/media/[...operation].ts+++ b/apps/cloud/server/api/sites/[siteId]/media/[...operation].ts@@ -492,11 +492,18 @@ export default definePlatformHandler(async (event) => {.bind(token, now + 30000, siteId, id, now).first()if (!lock) throw createError({ statusCode: 409 })+ let initiating = falsetry {const recovered = await s3.recoverMultipart(upload.object_key)- providerId =- recovered[0] ??- (await s3.multipart(upload.object_key, detail.content_type))+ if (recovered[0]) providerId = recovered[0]+ else {+ initiating = true+ providerId = await s3.multipart(+ upload.object_key,+ detail.content_type,+ )+ initiating = false+ }for (const abandoned of recovered.slice(1))await s3.abort(upload.object_key, abandoned)const updated = await raw@@ -510,7 +517,8 @@ export default definePlatformHandler(async (event) => {throw createError({ statusCode: 409 })}} catch (error) {- if (!providerId && canFallbackToSingleUpload(error)) {+ // Recovery failures must surface: an unlisted session could be orphaned.+ if (initiating && canFallbackToSingleUpload(error)) {console.warn('[upload] s3.multipart.fallback.single', {siteId,uploadId: id,diff --git a/packages/console/app/components/ui/UploadQueuePanel.vue b/packages/console/app/components/ui/UploadQueuePanel.vueindex 34174c4a..37edc70c 100644--- a/packages/console/app/components/ui/UploadQueuePanel.vue+++ b/packages/console/app/components/ui/UploadQueuePanel.vue@@ -9,10 +9,14 @@ import {isSkippedOrBlockedUploadStatus,} from '@chronoframe/gallery/shared/utils/upload-status'-const props = defineProps<{- uploadingFiles: Map<string, UploadingFile>- collapsed?: boolean-}>()+const props = withDefaults(+ defineProps<{+ uploadingFiles: Map<string, UploadingFile>+ collapsed?: boolean+ showQueueLink?: boolean+ }>(),+ { showQueueLink: true },+)const emit = defineEmits<{removeFile: [fileId: string]@@ -335,6 +339,7 @@ const clearAllFiles = () => {</UButton><UButton+ v-if="showQueueLink"size="xs"variant="soft"color="info"diff --git a/packages/console/app/composables/useUpload.ts b/packages/console/app/composables/useUpload.tsindex 20e524b1..803092ef 100644--- a/packages/console/app/composables/useUpload.ts+++ b/packages/console/app/composables/useUpload.ts@@ -497,8 +497,21 @@ export function useUpload(options: UseUploadOptions = {}) {callbacks.onError?.(message, (failureXHR || currentXHR)!)if (managedSession && (cancelled || !multipart?.preserveOnError)) {try {- if (multipart?.abort) await multipart.abort()- else await $fetch(signedUrl, { method: 'DELETE' })+ // A stalled cleanup request must not hold a queue slot.+ const cleanup = multipart?.abort+ ? multipart.abort()+ : $fetch(signedUrl, { method: 'DELETE', timeout: 10000 })+ let deadline: ReturnType<typeof setTimeout> | undefined+ try {+ await Promise.race([+ cleanup,+ new Promise<void>((resolve) => {+ deadline = setTimeout(resolve, 10000)+ }),+ ])+ } finally {+ clearTimeout(deadline)+ }} catch (cleanupError) {console.error('Failed to abort upload session:', cleanupError)}diff --git a/tests/shared-upload.test.ts b/tests/shared-upload.test.tsindex 83dfacdb..b4b982f9 100644--- a/tests/shared-upload.test.ts+++ b/tests/shared-upload.test.ts@@ -443,9 +443,12 @@ test('shared floating queue tracks processing, retry and deletion without resurrqueue.trackJobs(context, [job])assert.equal(queue.uploadingFiles.value.size, 0)queue.trackJobs(context, [{ ...job, state: 'retry_wait' }])+ assert.equal(queue.uploadingFiles.value.size, 0)+ const other = { ...job, id: 'k', photo_id: 'photo-2' }+ queue.trackJobs(context, [{ ...other, state: 'retry_wait' }])assert.equal(queue.uploadingFiles.value.size, 1)queue.trackJobs(context, [- { ...job, state: 'failed', error_code: 'processing_failed' },+ { ...other, state: 'failed', error_code: 'processing_failed' },])assert.equal([...queue.uploadingFiles.value.values()][0].status, 'error')queue.trackJobs(context, [])@@ -463,6 +466,7 @@ test('Self-hosted and edge use the same narrow multipart fallback policy', () =>'AccessDenied',])assert.equal(canFallbackToSingleUpload({ name }), true)+ assert.equal(canFallbackToSingleUpload({ Code: 'NotImplemented' }), true)for (const status of [405, 501])assert.equal(canFallbackToSingleUpload({ $metadata: { httpStatusCode: status } }),@@ -489,6 +493,7 @@ test('Self-hosted and edge use the same narrow multipart fallback policy', () =>test('Cloud plan falls back only before a multipart session exists and always releases its initialization lease', async () => {for (const failure of [{ name: 'AccessDenied' },+ { name: 'AccessDenied', at: 'recover' },{ name: 'NotImplemented' },{ name: 'ServiceUnavailable', $metadata: { httpStatusCode: 503 } },]) {@@ -552,7 +557,10 @@ test('Cloud plan falls back only before a multipart session exists and always re],storage: async () => ({s3: {- recoverMultipart: async () => [],+ recoverMultipart: async () => {+ if (failure.at === 'recover') throw failure+ return []+ },multipart: async () => {throw failure},@@ -567,7 +575,7 @@ test('Cloud plan falls back only before a multipart session exists and always re},)- if (failure.name === 'ServiceUnavailable') {+ if (failure.name === 'ServiceUnavailable' || failure.at === 'recover') {await assert.rejects(module.default({ method: 'POST' }))assert.equal(signed, 0)} else {