Skip to content

Self-hosted personal gallery application with online photo management and albums, supporting Live/Motion Photos, EXIF parsing, geolocation recognition, and an explore map.

fix: retain shared MOV companions for unfinished uploads

Timothy Yin1b5f17e34c45
diff --git a/apps/cloud/app/utils/upload-selection.ts b/apps/cloud/app/utils/upload-selection.ts
index c887b251..b766c279 100644
--- a/apps/cloud/app/utils/upload-selection.ts
+++ b/apps/cloud/app/utils/upload-selection.ts
@@ -17,16 +17,15 @@ export function remainingUploadFiles<T extends UploadFile>(
completed: number,
): T[] {
const isVideo = (file: T) => file.name.toLowerCase().endsWith('.mov')
- const completedPhotos = files
- .filter((file) => !isVideo(file))
- .slice(0, completed)
+ const photos = files.filter((file) => !isVideo(file))
+ const completedPhotos = photos.slice(0, completed)
+ const stem = (file: T) => file.name.replace(/\.[^.]+$/, '').toLowerCase()
+ const unfinishedStems = new Set(photos.slice(completed).map(stem))
const removed = new Set(completedPhotos)
for (const photo of completedPhotos) {
+ if (unfinishedStems.has(stem(photo))) continue
const companion = files.find(
- (file) =>
- isVideo(file) &&
- file.name.replace(/\.[^.]+$/, '').toLowerCase() ===
- photo.name.replace(/\.[^.]+$/, '').toLowerCase(),
+ (file) => isVideo(file) && stem(file) === stem(photo),
)
if (companion) removed.add(companion)
}
diff --git a/tests/portal-review-regressions.test.ts b/tests/portal-review-regressions.test.ts
index 742a416e..5a461c33 100644
--- a/tests/portal-review-regressions.test.ts
+++ b/tests/portal-review-regressions.test.ts
@@ -1103,3 +1103,20 @@ test('file selection and dropping only stage files; explicit start uploads once
await state.startUpload()
assert.equal(batches.length, count)
})
+
+test('partial upload cleanup retains shared MOV companions until every matching photo completes', () => {
+ const heic = new File(['heic'], 'One.HEIC', { lastModified: 1 })
+ const video = new File(['video'], 'one.MOV', { lastModified: 1 })
+ const jpeg = new File(['jpeg'], 'ONE.jpg', { lastModified: 1 })
+ const orphan = new File(['orphan'], 'other.MOV', { lastModified: 1 })
+ const selected = [heic, video, jpeg, orphan]
+ assert.deepEqual(remainingUploadFiles(selected, 0), selected)
+ const remaining = remainingUploadFiles(selected, 1)
+ assert.deepEqual(remaining, [video, jpeg, orphan])
+ assert.equal(
+ remaining.find((file) => file.name.toLowerCase().endsWith('.mov')),
+ video,
+ )
+ assert.deepEqual(remainingUploadFiles(remaining, 1), [orphan])
+ assert.deepEqual(remainingUploadFiles(selected, 2), [orphan])
+})