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
refactor: 重新组织 API 端点
Timothy Yindf68d4ce254e
diff --git a/app/pages/dashboard/location.vue b/app/pages/dashboard/location.vueindex bcc13905..57616d16 100644--- a/app/pages/dashboard/location.vue+++ b/app/pages/dashboard/location.vue@@ -37,7 +37,7 @@ const isReindexing = ref(false)const reindexResult = ref<ReindexResult | null>(null)const { data: locationStats, refresh: refreshStats } =- await useFetch<LocationStats>('/api/photos/reindex-city', {+ await useFetch<LocationStats>('/api/photos/locations/geocode', {server: false,})@@ -57,7 +57,7 @@ const startReindex = async (force = false) => {reindexResult.value = nulltry {- const data = await $fetch<ReindexResult>('/api/photos/reindex-city', {+ const data = await $fetch<ReindexResult>('/api/photos/locations/geocode', {method: 'POST',body: { force },})diff --git a/app/pages/dashboard/photos.vue b/app/pages/dashboard/photos.vueindex c76c49a7..b5c00f61 100644--- a/app/pages/dashboard/photos.vue+++ b/app/pages/dashboard/photos.vue@@ -587,7 +587,7 @@ const handleUpdateLivePhoto = async (photoId: string) => {color: 'info',})- const result = (await $fetch('/api/photos/livephoto-manage', {+ const result = (await $fetch('/api/photos/livephoto/manage', {method: 'POST',body: {action: 'update-photo',@@ -691,10 +691,10 @@ const handleBatchDetectLivePhoto = async () => {const photoIds = selectedPhotos.map((photo: any) => photo.id)- const result = (await $fetch('/api/photos/livephoto-detect', {+ const result = (await $fetch('/api/photos/livephoto/manage', {method: 'POST',body: {- action: 'batch-detect',+ action: 'detect',photoIds: photoIds, // 传递选中的照片ID列表},})) as any@@ -748,7 +748,7 @@ const handleBatchReindexExif = async () => {const photoIds = selectedPhotos.map((photo: any) => photo.id)- const result = (await $fetch('/api/photos/reindex-exif', {+ const result = (await $fetch('/api/photos/exif/reindex', {method: 'POST',body: {action: 'batch-reindex',@@ -788,7 +788,7 @@ const handleReindexSingleExif = async (photoId: string) => {color: 'info',})- const result = (await $fetch('/api/photos/reindex-exif', {+ const result = (await $fetch('/api/photos/exif/reindex', {method: 'POST',body: {action: 'single-reindex',diff --git a/server/api/photos/[photoId].delete.ts b/server/api/photos/[photoId]/index.delete.tssimilarity index 100%rename from server/api/photos/[photoId].delete.tsrename to server/api/photos/[photoId]/index.delete.tsdiff --git a/server/api/photos/reindex-exif.post.ts b/server/api/photos/exif/reindex.post.tssimilarity index 100%rename from server/api/photos/reindex-exif.post.tsrename to server/api/photos/exif/reindex.post.tsdiff --git a/server/api/photos/index.put.ts b/server/api/photos/index.put.tsdeleted file mode 100644index 0d4b4f92..00000000--- a/server/api/photos/index.put.ts+++ /dev/null@@ -1,53 +0,0 @@-import { execPhotoPipelineAsync } from '~~/server/services/photo/pipeline-async'-import { useStorageProvider } from '~~/server/utils/useStorageProvider'--export default eventHandler(async (event) => {- await requireUserSession(event)- const { storageProvider } = useStorageProvider(event)- const formData = await readFormData(event)-- // 尝试从两个可能的字段名获取文件- const file = (formData.get('file') || formData.get('files')) as File | null-- if (!file || Array.isArray(file)) {- throw createError({- statusCode: 400,- statusMessage: 'File field is required',- })- }-- const originalObject = await storageProvider.create(- `${file.name}`,- Buffer.from(await file.arrayBuffer()),- )-- // 立即返回响应,不等待处理完成- processPhotoInBackground(originalObject.key, originalObject)-- // 返回处理中的响应- return {- message: 'Photo upload successful, processing in background',- fileKey: originalObject.key,- fileName: file.name,- status: 'processing'- }-})--// 后台处理函数-async function processPhotoInBackground(s3key: string, originalObject: any) {- try {- logger.chrono.info('Starting background photo processing for', s3key)-- const photo = await execPhotoPipelineAsync(s3key, originalObject)-- if (!photo) {- logger.chrono.error('Photo processing failed for', s3key)- return- }-- await useDB().insert(tables.photos).values(photo).execute()- logger.chrono.success('Background photo processing completed for', photo.title || photo.storageKey)- } catch (error) {- logger.chrono.error('Background photo processing error for', s3key, error)- }-}diff --git a/server/api/photos/livephoto-detect.post.ts b/server/api/photos/livephoto-detect.post.tsdeleted file mode 100644index f3b59326..00000000--- a/server/api/photos/livephoto-detect.post.ts+++ /dev/null@@ -1,40 +0,0 @@-import { batchTestLivePhotoDetection } from '~~/server/services/video/test-utils'--export default eventHandler(async (event) => {- await requireUserSession(event)-- const body = await readBody(event)- const { action, photoIds } = body-- if (!action) {- throw createError({- statusCode: 400,- statusMessage: 'Action is required',- })- }-- try {- switch (action) {- case 'batch-detect': // 批量检测现有照片的 LivePhoto 视频- {- const results = await batchTestLivePhotoDetection(photoIds)- return {- message: 'Batch LivePhoto detection completed',- results,- }- }-- default:- throw createError({- statusCode: 400,- statusMessage: 'Invalid action. Use "batch-detect"',- })- }- } catch (error) {- logger.chrono.error('LivePhoto detection error:', error)- throw createError({- statusCode: 500,- statusMessage: 'Failed to perform LivePhoto detection',- })- }-})diff --git a/server/api/photos/livephoto-manage.post.ts b/server/api/photos/livephoto/manage.post.tssimilarity index 87%rename from server/api/photos/livephoto-manage.post.tsrename to server/api/photos/livephoto/manage.post.tsindex 3ced8971..faea2849 100644--- a/server/api/photos/livephoto-manage.post.ts+++ b/server/api/photos/livephoto/manage.post.ts@@ -5,12 +5,13 @@ import {import { eq } from 'drizzle-orm'import { findLivePhotoVideoForImage } from '~~/server/services/video/livephoto'import { getStorageManager } from '~~/server/plugins/storage'+import { batchTestLivePhotoDetection } from '~~/server/services/video/test-utils'export default eventHandler(async (event) => {await requireUserSession(event)const body = await readBody(event)- const { action, videoKey, photoId } = body+ const { action, videoKey, photoId, photoIds } = bodyif (!action) {throw createError({@@ -29,6 +30,14 @@ export default eventHandler(async (event) => {}}+ case 'detect': { // 批量检测现有照片的 LivePhoto 视频+ const results = await batchTestLivePhotoDetection(photoIds)+ return {+ message: 'Batch LivePhoto detection completed',+ results,+ }+ }+case 'process': { // 处理特定文件if (!videoKey) {throw createError({@@ -108,7 +117,7 @@ export default eventHandler(async (event) => {throw createError({statusCode: 400,statusMessage:- 'Invalid action. Use "scan", "process", or "update-photo"',+ 'Invalid action. Use "scan", "detect", "process", or "update-photo"',})}} catch (error) {diff --git a/server/api/photos/reindex-city.get.ts b/server/api/photos/locations/geocode.get.tssimilarity index 100%rename from server/api/photos/reindex-city.get.tsrename to server/api/photos/locations/geocode.get.tsdiff --git a/server/api/photos/reindex-city.post.ts b/server/api/photos/locations/geocode.post.tssimilarity index 100%rename from server/api/photos/reindex-city.post.tsrename to server/api/photos/locations/geocode.post.tsdiff --git a/server/api/photos/locations.get.ts b/server/api/photos/locations/index.get.tssimilarity index 100%rename from server/api/photos/locations.get.tsrename to server/api/photos/locations/index.get.tsdiff --git a/server/api/photos/location-stats.get.ts b/server/api/photos/locations/stats.get.tssimilarity index 100%rename from server/api/photos/location-stats.get.tsrename to server/api/photos/locations/stats.get.tsdiff --git a/server/api/photos/status.ts b/server/api/photos/status.get.tssimilarity index 100%rename from server/api/photos/status.tsrename to server/api/photos/status.get.ts