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
feat(photos): 添加批量重新索引 EXIF 和单个照片重新索引功能
Timothy Yin88f96066ff4b
diff --git a/app/pages/dashboard/photos.vue b/app/pages/dashboard/photos.vueindex 636c18e0..3a41fd5f 100644--- a/app/pages/dashboard/photos.vue+++ b/app/pages/dashboard/photos.vue@@ -2,6 +2,7 @@import type { TableColumn } from '@nuxt/ui'import type { Photo } from '~~/server/utils/db'import { h, resolveComponent } from 'vue'+import { Icon, UBadge } from '#components'const UCheckbox = resolveComponent('UCheckbox')@@ -248,6 +249,20 @@ const columns: TableColumn<Photo>[] = ['aria-label': 'Select row',}),},+ {+ accessorKey: 'thumbnailUrl',+ header: '缩略图',+ cell: ({ row }) => {+ const url = row.original.thumbnailUrl+ return h('img', {+ src: url,+ alt: row.original.title || 'Photo Thumbnail',+ class: 'size-16 min-w-[100px] object-cover rounded-md shadow',+ onClick: () => openInNewTab(url || row.original.originalUrl || ''),+ style: { cursor: url ? 'pointer' : 'default' },+ })+ },+ },{accessorKey: 'id',header: 'Photo ID',@@ -256,6 +271,20 @@ const columns: TableColumn<Photo>[] = [accessorKey: 'title',header: '照片标题',},+ {+ accessorKey: 'tags',+ header: '关键词',+ cell: ({ row }) => {+ const tags = row.original.tags+ return h('div', { class: 'flex items-center gap-1' }, [+ tags?.map(tag => h(UBadge, {+ size: 'sm',+ variant: 'soft',+ color: 'neutral'+ }, () => tag)) || h('span', { class: 'text-neutral-400 text-xs' }, '无标签')+ ])+ },+ },{accessorKey: 'isLivePhoto',header: 'Live Photo',@@ -264,16 +293,17 @@ const columns: TableColumn<Photo>[] = [return h('div', { class: 'flex items-center gap-2' }, [isLivePhoto? h('div', { class: 'flex items-center gap-1' }, [- h('div', {- class: 'size-2 bg-blue-500 rounded-full animate-pulse'+ h(Icon , {+ name: 'tabler:live-photo',+ class: 'size-4 text-yellow-600 dark:text-yellow-400',}),h('span', {- class: 'text-blue-600 dark:text-blue-400 text-xs font-medium'- }, 'Live Photo')+ class: 'text-yellow-600 dark:text-yellow-400 text-xs font-medium'+ }, '实况')]): h('span', {- class: 'text-gray-400 text-xs'- }, '静态照片')+ class: 'text-neutral-400 text-xs'+ }, '一般照片')])},sortingFn: (rowA, rowB) => {@@ -282,9 +312,21 @@ const columns: TableColumn<Photo>[] = [return valueB - valueA // LivePhoto 优先排序}},+ {+ accessorKey: 'dateTaken',+ header: '拍摄日期',+ cell: (info) => {+ const date = info.getValue() as string+ return h('span', {class: 'font-mono text-xs'}, date ? dayjs(date).format('YYYY-MM-DD HH:mm:ss') : '未知')+ }+ },{accessorKey: 'lastModified',- header: '最后修改',+ header: '最后更新',+ cell: (info) => {+ const date = info.getValue() as string+ return h('span', {class: 'font-mono text-xs'}, date ? dayjs(date).format('YYYY-MM-DD HH:mm:ss') : '未知')+ }},{accessorKey: 'fileSize',@@ -570,34 +612,53 @@ const handleBatchDelete = async () => {}}-// 批量检测 LivePhoto 功能+// 批量检测 LivePhoto 功能(只对选中的照片)const handleBatchDetectLivePhoto = async () => {+ const selectedRowModel = table.value?.tableApi?.getFilteredSelectedRowModel()+ const selectedPhotos =+ selectedRowModel?.rows.map((row: any) => row.original) || []++ if (selectedPhotos.length === 0) {+ toast.add({+ title: '请选择照片',+ description: '请至少选择一张照片进行 LivePhoto 检测',+ color: 'warning',+ })+ return+ }+try {const detectToast = toast.add({- title: '正在批量检测 LivePhoto',- description: '正在检查所有照片的 LivePhoto 状态...',+ title: '正在检测 LivePhoto',+ description: `正在检查所选 ${selectedPhotos.length} 张照片的 LivePhoto 状态...`,color: 'info',})+ const photoIds = selectedPhotos.map((photo: any) => photo.id)+const result = await $fetch('/api/photos/livephoto-detect', {method: 'POST',body: {action: 'batch-detect',+ photoIds: photoIds, // 传递选中的照片ID列表},}) as anyconst foundCount = result.results?.found || 0- const totalCount = result.results?.total || 0+ const processedCount = result.results?.processed || 0toast.update(detectToast.id, {title: 'LivePhoto 检测完成',- description: `检测了 ${totalCount} 张照片,发现 ${foundCount} 个潜在的 LivePhoto`,+ description: `检测了 ${processedCount} 张照片,发现 ${foundCount} 个潜在的 LivePhoto`,color: foundCount > 0 ? 'success' : 'info',})if (foundCount > 0) {await refresh()}++ // 清空选中状态+ rowSelection.value = {}} catch (error: any) {console.error('批量检测 LivePhoto 失败:', error)toast.add({@@ -608,6 +669,95 @@ const handleBatchDetectLivePhoto = async () => {}}+// 批量重新索引 EXIF 功能(只对选中的照片)+const handleBatchReindexExif = async () => {+ const selectedRowModel = table.value?.tableApi?.getFilteredSelectedRowModel()+ const selectedPhotos =+ selectedRowModel?.rows.map((row: any) => row.original) || []++ if (selectedPhotos.length === 0) {+ toast.add({+ title: '请选择照片',+ description: '请至少选择一张照片进行 EXIF 重新索引',+ color: 'warning',+ })+ return+ }++ try {+ const reindexToast = toast.add({+ title: '正在重新索引 EXIF',+ description: `正在重新提取所选 ${selectedPhotos.length} 张照片的 EXIF 数据...`,+ color: 'info',+ })++ const photoIds = selectedPhotos.map((photo: any) => photo.id)++ const result = await $fetch('/api/photos/reindex-exif', {+ method: 'POST',+ body: {+ action: 'batch-reindex',+ photoIds: photoIds, // 传递选中的照片ID列表+ },+ }) as any++ const processedCount = result.results?.processed || 0+ const updatedCount = result.results?.updated || 0++ toast.update(reindexToast.id, {+ title: 'EXIF 重新索引完成',+ description: `处理了 ${processedCount} 张照片,更新了 ${updatedCount} 张照片的 EXIF 数据`,+ color: 'success',+ })++ await refresh()++ // 清空选中状态+ rowSelection.value = {}+ } catch (error: any) {+ console.error('批量重新索引 EXIF 失败:', error)+ toast.add({+ title: 'EXIF 重新索引失败',+ description: error.message || '重新索引过程中发生错误',+ color: 'error',+ })+ }+}++// 单个照片重新索引 EXIF 功能+const handleReindexSingleExif = async (photoId: string) => {+ try {+ const reindexToast = toast.add({+ title: '正在重新索引 EXIF',+ description: '正在重新提取照片的 EXIF 数据...',+ color: 'info',+ })++ const result = await $fetch('/api/photos/reindex-exif', {+ method: 'POST',+ body: {+ action: 'single-reindex',+ photoId: photoId,+ },+ }) as any++ toast.update(reindexToast.id, {+ title: 'EXIF 重新索引完成',+ description: result.message || '照片 EXIF 数据已更新',+ color: 'success',+ })++ await refresh()+ } catch (error: any) {+ console.error('重新索引 EXIF 失败:', error)+ toast.add({+ title: 'EXIF 重新索引失败',+ description: error.message || '重新索引过程中发生错误',+ color: 'error',+ })+ }+}+// 清理定时器onUnmounted(() => {if (statusInterval) {@@ -617,7 +767,7 @@ onUnmounted(() => {</script><template>- <div class="flex flex-col gap-4 h-full p-4">+ <div class="flex flex-col gap-3 sm:gap-4 h-full p-3 sm:p-4"><!-- 上传进度显示 --><divv-if="uploadingFiles.size > 0"@@ -628,10 +778,10 @@ onUnmounted(() => {<divv-for="[fileId, uploadingFile] of uploadingFiles":key="fileId"- class="p-4 border border-neutral-200 dark:border-neutral-700 rounded-lg"+ class="p-3 sm:p-4 border border-neutral-200 dark:border-neutral-700 rounded-lg">- <div class="flex items-center justify-between mb-2">- <span class="font-medium">{{ uploadingFile.fileName }}</span>+ <div class="flex flex-col sm:flex-row sm:items-center justify-between gap-2 sm:gap-0 mb-2">+ <span class="font-medium text-sm sm:text-base truncate">{{ uploadingFile.fileName }}</span><div class="flex items-center gap-2"><!-- 状态指示器 --><UBadge@@ -645,6 +795,7 @@ onUnmounted(() => {: 'warning'"variant="soft"+ size="sm">{{uploadingFile.status === 'preparing'@@ -670,7 +821,8 @@ onUnmounted(() => {icon="tabler:file-x"@click="uploadingFile.abortUpload?.()">- 中止上传+ <span class="hidden sm:inline">中止上传</span>+ <span class="sm:hidden">中止</span></UButton></div></div>@@ -684,10 +836,10 @@ onUnmounted(() => {class="mb-2"><div- class="flex justify-between text-sm text-neutral-600 dark:text-neutral-400 mb-1"+ class="flex justify-between text-xs sm:text-sm text-neutral-600 dark:text-neutral-400 mb-1"><span>{{ uploadingFile.progress }}%</span>- <span v-if="uploadingFile.uploadProgress?.speedText">+ <span v-if="uploadingFile.uploadProgress?.speedText" class="hidden sm:inline">{{ uploadingFile.uploadProgress.speedText }}</span></div>@@ -699,7 +851,7 @@ onUnmounted(() => {v-if="uploadingFile.uploadProgress?.timeRemainingText"class="text-xs text-neutral-500 mt-1">- ETA: {{ uploadingFile.uploadProgress.timeRemainingText }}+ <span class="hidden sm:inline">ETA: </span>{{ uploadingFile.uploadProgress.timeRemainingText }}</div></div>@@ -727,7 +879,7 @@ onUnmounted(() => {multiple/><UButton- class="absolute top-3.5 right-3.5"+ class="absolute top-3.5 right-3.5 hidden sm:flex"variant="soft"size="lg"icon="tabler:upload"@@ -736,39 +888,47 @@ onUnmounted(() => {>上传照片</UButton>+ <!-- 移动端上传按钮 -->+ <UButton+ v-if="selectedFiles.length > 0"+ class="mt-3 w-full sm:hidden"+ variant="soft"+ size="lg"+ icon="tabler:upload"+ @click="handleUpload"+ >+ 上传 {{ selectedFiles.length }} 张照片+ </UButton></div><!-- 工具栏 -->- <div class="flex items-center justify-between p-4 bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-lg">+ <div class="flex flex-row sm:items-center justify-between gap-3 sm:gap-0 p-3 sm:p-4 bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-lg"><div class="flex items-center gap-2"><UIconname="tabler:photo"class="text-gray-500"/>- <span class="font-medium text-gray-700 dark:text-gray-300">+ <span class="font-medium text-gray-700 dark:text-gray-300 hidden sm:inline">照片管理</span>- <div class="flex items-center gap-2">+ <div class="flex items-center gap-1 sm:gap-2"><UBadge- v-if="livePhotoStats.total > 0"+ v-if="livePhotoStats.staticPhotos > 0"variant="soft"- color="info"+ color="neutral"+ size="sm">- {{ livePhotoStats.total }} 张照片+ <span class="hidden sm:inline">{{ livePhotoStats.staticPhotos }} 照片</span>+ <span class="sm:hidden">{{ livePhotoStats.staticPhotos }}P</span></UBadge><UBadgev-if="livePhotoStats.livePhotos > 0"variant="soft"- color="success"- >- {{ livePhotoStats.livePhotos }} Live Photo- </UBadge>- <UBadge- v-if="livePhotoStats.staticPhotos > 0"- variant="soft"- color="neutral"+ color="warning"+ size="sm">- {{ livePhotoStats.staticPhotos }} 静态照片+ <span class="hidden sm:inline">{{ livePhotoStats.livePhotos }} Live Photo</span>+ <span class="sm:hidden">{{ livePhotoStats.livePhotos }}LP</span></UBadge></div></div>@@ -777,7 +937,7 @@ onUnmounted(() => {<!-- 过滤器 --><USelectMenuv-model="photoFilter"- class="w-48"+ class="w-full sm:w-48":items="[{ label: '全部照片', value: 'all', icon: 'tabler:photo-scan' },{ label: 'Live Photo', value: 'livephoto', icon: 'tabler:live-photo' },@@ -788,27 +948,16 @@ onUnmounted(() => {size="sm"></USelectMenu>-- <!-- LivePhoto 批量检测按钮 -->- <UButton- variant="soft"- color="info"- size="sm"- icon="tabler:scan"- @click="handleBatchDetectLivePhoto"- >- 批量检测 LivePhoto- </UButton><!-- 刷新按钮 --><UButton- variant="ghost"- color="neutral"+ variant="soft"+ color="info"size="sm"icon="tabler:refresh"@click="() => refresh()">- 刷新+ <span class="hidden sm:inline">刷新</span></UButton></div></div>@@ -816,7 +965,7 @@ onUnmounted(() => {<!-- 批量操作栏 --><divv-if="selectedRowsCount > 0"- class="flex items-center justify-between p-4 bg-blue-50 dark:bg-blue-950/20 border border-blue-200 dark:border-blue-800 rounded-lg"+ class="flex flex-col sm:flex-row sm:items-center justify-between gap-3 sm:gap-0 p-3 sm:p-4 bg-blue-50 dark:bg-blue-950/20 border border-blue-200 dark:border-blue-800 rounded-lg"><div class="flex items-center gap-2"><UIcon@@ -824,25 +973,54 @@ onUnmounted(() => {class="text-blue-500"/><span class="font-medium text-blue-700 dark:text-blue-300">- 已选择 {{ selectedRowsCount }} 张照片+ <span class="hidden sm:inline">已选择</span> {{ selectedRowsCount }} <span class="hidden sm:inline">张照片</span></span>- </div>- <div class="flex items-center gap-2"><UButtonvariant="ghost"size="sm"@click="rowSelection = {}">- 取消选择+ <span class="hidden sm:inline">取消选择</span>+ <span class="sm:hidden">取消</span></UButton>+ </div>+ <div class="flex flex-wrap sm:flex-nowrap items-center gap-1 sm:gap-2">+ <!-- 重新索引 EXIF 按钮 -->+ <UButton+ variant="soft"+ color="success"+ size="sm"+ icon="tabler:refresh"+ @click="handleBatchReindexExif"+ class="flex-1 sm:flex-none"+ >+ <span class="hidden sm:inline">重新索引 EXIF</span>+ <span class="sm:hidden">索引</span>+ </UButton>++ <!-- 实况配对按钮 -->+ <UButton+ variant="soft"+ color="info"+ size="sm"+ icon="tabler:live-photo"+ @click="handleBatchDetectLivePhoto"+ class="flex-1 sm:flex-none"+ >+ <span class="hidden sm:inline">实况配对</span>+ <span class="sm:hidden">配对</span>+ </UButton>+<UButtoncolor="error"variant="soft"size="sm"icon="tabler:trash"@click="handleBatchDelete"+ class="flex-1 sm:flex-none">- 批量删除+ <span class="hidden sm:inline">批量删除</span>+ <span class="sm:hidden">删除</span></UButton></div></div>@@ -858,48 +1036,55 @@ onUnmounted(() => {:columns="columns":loading="status === 'pending'"sticky- class="h-[600px]"+ class="h-[400px] sm:h-[600px]":ui="{separator:'bg-(--ui-color-neutral-200) dark:bg-(--ui-color-neutral-700)',}"><template #actions-cell="{ row }">- <div class="flex items-center gap-2">- <!-- LivePhoto 相关操作 -->- <template v-if="row.original.isLivePhoto">- <UButton- size="sm"- variant="soft"- color="info"- icon="tabler:live-photo"- @click="handleViewLivePhoto(row.original.id)"- >- Live Photo 预览- </UButton>- </template>- <template v-else>- <UButton- size="sm"- variant="ghost"- color="neutral"- icon="tabler:refresh"- @click="handleUpdateLivePhoto(row.original.id)"- >- 检测 LivePhoto- </UButton>- </template>-- <!-- 删除按钮 -->- <UButton+ <div class="flex justify-end">+ <UDropdownMenusize="sm"- variant="soft"- color="error"- icon="tabler:trash"- @click="handleDelete(row.original.id)"+ :content="{+ align: 'end'+ }"+ :items="[+ [+ {+ color: row.original.isLivePhoto ? 'warning' : 'info',+ label: row.original.isLivePhoto ? '实况预览' : '实况配对',+ icon: row.original.isLivePhoto ? 'tabler:live-photo' : 'tabler:refresh',+ onSelect() {+ row.original.isLivePhoto+ ? handleViewLivePhoto(row.original.id)+ : handleUpdateLivePhoto(row.original.id)+ }+ },+ {+ color: 'success',+ label: '重新索引 EXIF',+ icon: 'tabler:refresh',+ onSelect: () => handleReindexSingleExif(row.original.id)+ }+ ],+ [+ {+ color: 'error',+ label: '删除',+ icon: 'tabler:trash',+ onSelect: () => handleDelete(row.original.id)+ }+ ]+ ]">- 删除- </UButton>+ <UButton+ variant="outline"+ color="neutral"+ size="sm"+ icon="tabler:dots-vertical"+ />+ </UDropdownMenu></div></template></UTable>diff --git a/server/api/photos/livephoto-detect.post.ts b/server/api/photos/livephoto-detect.post.tsindex 36755d2a..69f927d6 100644--- a/server/api/photos/livephoto-detect.post.ts+++ b/server/api/photos/livephoto-detect.post.ts@@ -4,7 +4,7 @@ export default eventHandler(async (event) => {await requireUserSession(event)const body = await readBody(event)- const { action } = body+ const { action, photoIds } = bodyif (!action) {throw createError({@@ -17,7 +17,7 @@ export default eventHandler(async (event) => {switch (action) {case 'batch-detect':// 批量检测现有照片的 LivePhoto 视频- const results = await batchTestLivePhotoDetection()+ const results = await batchTestLivePhotoDetection(photoIds)return {message: 'Batch LivePhoto detection completed',resultsdiff --git a/server/api/photos/reindex-exif.post.ts b/server/api/photos/reindex-exif.post.tsnew file mode 100644index 00000000..e970f47f--- /dev/null+++ b/server/api/photos/reindex-exif.post.ts@@ -0,0 +1,200 @@+import { eq, isNotNull, inArray, and } from 'drizzle-orm'+import { extractExifData, extractPhotoInfo } from '~~/server/services/image/exif'++export default eventHandler(async (event) => {+ await requireUserSession(event)++ const body = await readBody(event)+ const { action, photoId } = body++ try {+ if (action === 'single-reindex' && photoId) {+ // 处理单个照片的 EXIF 重新索引+ const photo = await useDB()+ .select()+ .from(tables.photos)+ .where(eq(tables.photos.id, photoId))+ .limit(1)+ .then(rows => rows[0])++ if (!photo) {+ throw createError({+ statusCode: 404,+ statusMessage: 'Photo not found',+ })+ }++ logger.chrono.info(`Reindexing EXIF for photo ${photoId}`)++ // 重新提取文件的元数据+ const { storageProvider } = useStorageProvider(event)+ const fileBuffer = await storageProvider.get(photo.storageKey!)++ if (!fileBuffer) {+ throw createError({+ statusCode: 404,+ statusMessage: 'File not found in storage',+ })+ }++ // 提取新的 EXIF 数据+ const exifData = await extractExifData(fileBuffer, undefined, logger.chrono)+ const photoInfo = extractPhotoInfo(photo.storageKey!, exifData)++ // 更新数据库中的 EXIF 数据+ await useDB()+ .update(tables.photos)+ .set({+ exif: exifData,+ title: photoInfo.title,+ dateTaken: photoInfo.dateTaken,+ tags: photoInfo.tags,+ lastModified: new Date().toISOString(),+ })+ .where(eq(tables.photos.id, photoId))++ logger.chrono.success(`Successfully reindexed EXIF for photo ${photoId}`)++ return {+ success: true,+ message: 'EXIF 数据已成功重新索引',+ photoId,+ }+ } else if (action === 'batch-reindex') {+ // 批量重新索引所有照片的 EXIF+ const { photoIds } = body+ let photos++ if (photoIds && Array.isArray(photoIds) && photoIds.length > 0) {+ // 只处理指定的照片+ photos = await useDB()+ .select({+ id: tables.photos.id,+ storageKey: tables.photos.storageKey,+ })+ .from(tables.photos)+ .where(+ and(+ isNotNull(tables.photos.storageKey),+ inArray(tables.photos.id, photoIds)+ )+ )+ } else {+ // 处理所有照片+ photos = await useDB()+ .select({+ id: tables.photos.id,+ storageKey: tables.photos.storageKey,+ })+ .from(tables.photos)+ .where(isNotNull(tables.photos.storageKey))+ }++ if (photos.length === 0) {+ return {+ message: '没有找到需要重新索引的照片',+ results: {+ total: 0,+ processed: 0,+ updated: 0,+ errors: [],+ },+ }+ }++ logger.chrono.info(`Starting batch EXIF reindexing for ${photos.length} photos`)++ let processed = 0+ let updated = 0+ const errors: Array<{ photoId: string; error: string }> = []+ const { storageProvider } = useStorageProvider(event)++ for (const photo of photos) {+ try {+ processed++++ logger.chrono.info(+ `Processing photo ${photo.id} (${processed}/${photos.length})`+ )++ // 获取文件+ const fileBuffer = await storageProvider.get(photo.storageKey!)++ if (!fileBuffer) {+ errors.push({+ photoId: photo.id,+ error: 'File not found in storage',+ })+ continue+ }++ // 提取元数据和照片信息+ const exifData = await extractExifData(fileBuffer, undefined, logger.chrono)+ const photoInfo = extractPhotoInfo(photo.storageKey!, exifData)++ // 更新数据库+ await useDB()+ .update(tables.photos)+ .set({+ exif: exifData,+ title: photoInfo.title,+ dateTaken: photoInfo.dateTaken,+ tags: photoInfo.tags,+ lastModified: new Date().toISOString(),+ })+ .where(eq(tables.photos.id, photo.id))++ updated++++ logger.chrono.success(+ `Updated EXIF for photo ${photo.id} (${updated}/${processed})`+ )++ // 添加小延迟以避免过度负载+ if (processed % 10 === 0) {+ await new Promise(resolve => setTimeout(resolve, 100))+ }+ } catch (error) {+ const errorMessage = error instanceof Error ? error.message : 'Unknown error'+ logger.chrono.error(`Failed to process photo ${photo.id}:`, error)+ errors.push({+ photoId: photo.id,+ error: errorMessage,+ })+ }+ }++ const result = {+ message: `EXIF 重新索引完成`,+ results: {+ total: photos.length,+ processed,+ updated,+ errors: errors.length > 0 ? errors : undefined,+ statistics: {+ successRate: processed > 0+ ? (((processed - errors.length) / processed) * 100).toFixed(1) + '%'+ : '0%',+ },+ },+ }++ logger.chrono.success(+ `EXIF batch reindexing completed: ${updated} photos updated out of ${processed} processed`+ )++ return result+ } else {+ throw createError({+ statusCode: 400,+ statusMessage: 'Invalid action parameter',+ })+ }+ } catch (error) {+ logger.chrono.error('Failed to reindex EXIF data:', error)+ throw createError({+ statusCode: 500,+ statusMessage: 'Failed to reindex EXIF data',+ })+ }+})diff --git a/server/services/video/test-utils.ts b/server/services/video/test-utils.tsindex ded857df..b588ca6d 100644--- a/server/services/video/test-utils.ts+++ b/server/services/video/test-utils.ts@@ -1,4 +1,4 @@-import { eq } from 'drizzle-orm'+import { eq, and, inArray } from 'drizzle-orm'import { findLivePhotoVideoForImage } from '../video/livephoto'/**@@ -39,15 +39,30 @@ export const testLivePhotoDetection = async (imageKey: string) => {/*** 批量测试现有照片的 LivePhoto 检测*/-export const batchTestLivePhotoDetection = async () => {+export const batchTestLivePhotoDetection = async (photoIds?: string[]) => {const db = useDB()try {- // 获取所有还不是 LivePhoto 的照片- const photos = await db- .select()- .from(tables.photos)- .where(eq(tables.photos.isLivePhoto, 0))+ let photos++ if (photoIds && Array.isArray(photoIds) && photoIds.length > 0) {+ // 只处理指定的照片+ photos = await db+ .select()+ .from(tables.photos)+ .where(+ and(+ eq(tables.photos.isLivePhoto, 0),+ inArray(tables.photos.id, photoIds)+ )+ )+ } else {+ // 获取所有还不是 LivePhoto 的照片+ photos = await db+ .select()+ .from(tables.photos)+ .where(eq(tables.photos.isLivePhoto, 0))+ }logger.chrono.info(`Testing ${photos.length} photos for LivePhoto detection`)@@ -70,6 +85,7 @@ export const batchTestLivePhotoDetection = async () => {return {total: photos.length,+ processed: photos.length,found: foundCount,results: results.filter(r => r.found) // 只返回找到的}