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: update motion photo storage path and add video file type checks

Timothy Yine62354b67fdb
diff --git a/app/pages/dashboard/photos.vue b/app/pages/dashboard/photos.vue
index 83b25ba5..72b0885c 100644
--- a/app/pages/dashboard/photos.vue
+++ b/app/pages/dashboard/photos.vue
@@ -181,7 +181,7 @@ const uploadImage = async (file: File, existingFileId?: string) => {
type: isMovFile ? 'live-photo-video' : 'photo',
storageKey: signedUrlResponse.fileKey,
},
- priority: 0,
+ priority: isMovFile ? 0 : 1, // Live Photo 视频优先级更低,确保图片优先处理
maxAttempts: 3,
},
})
diff --git a/server/api/photos/index.post.ts b/server/api/photos/index.post.ts
index 313d9276..b584b022 100644
--- a/server/api/photos/index.post.ts
+++ b/server/api/photos/index.post.ts
@@ -1,7 +1,45 @@
+import path from 'path'
import { useStorageProvider } from '~~/server/utils/useStorageProvider'
import { eq } from 'drizzle-orm'
import { generateSafePhotoId } from '~~/server/utils/file-utils'
+const VIDEO_EXTENSIONS = new Set([
+ '.mov',
+ '.mp4',
+])
+
+const IMAGE_EXTENSIONS = new Set([
+ '.avif',
+ '.bmp',
+ '.gif',
+ '.heic',
+ '.heif',
+ '.jpeg',
+ '.jpg',
+ '.png',
+ '.tif',
+ '.tiff',
+ '.webp',
+])
+
+const isVideoFile = (fileName: string, contentType?: string | null): boolean => {
+ if (contentType?.toLowerCase().startsWith('video/')) {
+ return true
+ }
+
+ const ext = path.extname(fileName).toLowerCase()
+ return ext !== '' && VIDEO_EXTENSIONS.has(ext)
+}
+
+const isLikelyImageKey = (storageKey?: string | null): boolean => {
+ if (!storageKey) {
+ return false
+ }
+
+ const ext = path.extname(storageKey).toLowerCase()
+ return ext !== '' && IMAGE_EXTENSIONS.has(ext)
+}
+
export default eventHandler(async (event) => {
await requireUserSession(event)
const { storageProvider } = useStorageProvider(event)
@@ -10,6 +48,7 @@ export default eventHandler(async (event) => {
const body = await readBody(event)
const { fileName, contentType, skipDuplicateCheck } = body
+ const isVideoUpload = fileName ? isVideoFile(fileName, contentType) : false
if (!fileName) {
throw createError({
@@ -43,6 +82,10 @@ export default eventHandler(async (event) => {
.where(eq(tables.photos.id, photoId))
.get()
+ if (existingPhoto && isVideoUpload && isLikelyImageKey(existingPhoto.storageKey)) {
+ existingPhoto = null
+ }
+
if (existingPhoto) {
const checkMode = config.upload.duplicateCheck.mode || 'skip'
diff --git a/server/services/video/motion-photo.ts b/server/services/video/motion-photo.ts
index 8ef568b2..b5c1597d 100644
--- a/server/services/video/motion-photo.ts
+++ b/server/services/video/motion-photo.ts
@@ -270,7 +270,9 @@ export const processMotionPhotoFromXmp = async ({
return null
}
- const targetKey = `motion-videos/${photoId}.mp4`
+ // todo: consider storing in a dedicated subfolder
+ // const targetKey = `motion-videos/${photoId}.mp4`
+ const targetKey = `${photoId}.mp4`
let storedObject
try {
storedObject = await storageProvider.create(