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(dashboard): add batch download functionality for selected photos
Timothy Yinbfb52a969146
diff --git a/app/pages/dashboard/photos.vue b/app/pages/dashboard/photos.vueindex de5827d2..a1dcdfe1 100644--- a/app/pages/dashboard/photos.vue+++ b/app/pages/dashboard/photos.vue@@ -1663,6 +1663,122 @@ const handleBatchReprocess = async () => {}}+// 批量下载照片+const handleBatchDownload = async () => {+ const selectedRowModel = table.value?.tableApi?.getFilteredSelectedRowModel()+ const selectedPhotos =+ selectedRowModel?.rows.map((row: any) => row.original) || []++ if (selectedPhotos.length === 0) {+ toast.add({+ title: $t('dashboard.photos.messages.batchSelectRequired'),+ description: '',+ color: 'warning',+ })+ return+ }++ // 检查所有选中照片是否都有 originalUrl+ const photosWithUrl = selectedPhotos.filter(+ (photo: Photo) => photo.originalUrl,+ )+ if (photosWithUrl.length === 0) {+ toast.add({+ title: $t('dashboard.photos.messages.error'),+ description: $t('dashboard.photos.messages.batchNoUrl'),+ color: 'error',+ })+ return+ }++ if (photosWithUrl.length !== selectedPhotos.length) {+ toast.add({+ title: $t('dashboard.photos.messages.warning'),+ description: $t('dashboard.photos.messages.batchPartialUrl', {+ count: photosWithUrl.length,+ total: selectedPhotos.length,+ }),+ color: 'warning',+ })+ }++ const downloadToast = toast.add({+ title: $t('dashboard.photos.messages.downloadStarted'),+ description: $t('dashboard.photos.messages.downloadingCount', {+ count: photosWithUrl.length,+ }),+ color: 'info',+ })++ let successCount = 0+ let failureCount = 0++ try {+ for (const photo of photosWithUrl) {+ try {+ const response = await fetch(photo.originalUrl!)+ if (!response.ok) {+ failureCount+++ continue+ }++ const blob = await response.blob()+ const url = window.URL.createObjectURL(blob)+ const link = document.createElement('a')+ link.href = url+ const extension = photo.originalUrl!.split('.').pop() || 'jpg'+ link.download = `${photo.title || `photo-${photo.id}`}.${extension}`+ document.body.appendChild(link)+ link.click()+ document.body.removeChild(link)+ window.URL.revokeObjectURL(url)+ successCount++++ // 为了避免浏览器限制,每个下载之间加入短延迟+ await new Promise((resolve) => setTimeout(resolve, 200))+ } catch (error) {+ console.error(`Failed to download photo ${photo.id}:`, error)+ failureCount+++ }+ }++ // 更新提示信息+ if (successCount === photosWithUrl.length) {+ toast.update(downloadToast.id, {+ title: $t('dashboard.photos.messages.batchDownloadSuccess'),+ description: $t('dashboard.photos.messages.downloadedCount', {+ count: successCount,+ }),+ color: 'success',+ })+ } else if (failureCount === photosWithUrl.length) {+ toast.update(downloadToast.id, {+ title: $t('dashboard.photos.messages.batchDownloadFailed'),+ description: $t('dashboard.photos.messages.downloadFailedCount', {+ count: failureCount,+ }),+ color: 'error',+ })+ } else {+ toast.update(downloadToast.id, {+ title: $t('dashboard.photos.messages.batchDownloadPartial'),+ description: $t('dashboard.photos.messages.downloadPartialCount', {+ success: successCount,+ failed: failureCount,+ }),+ color: 'warning',+ })+ }+ } catch (error: any) {+ console.error('批量下载出错:', error)+ toast.update(downloadToast.id, {+ title: $t('dashboard.photos.messages.error'),+ description: error.message || $t('dashboard.photos.messages.error'),+ color: 'error',+ })+ }+}+watch(isImagePreviewOpen, (open) => {if (!open) {previewingPhoto.value = null@@ -2108,6 +2224,17 @@ onUnmounted(() => {<span>{{ $t('dashboard.photos.selection.batchReprocess') }}</span></UButton>+ <UButton+ variant="soft"+ color="primary"+ size="xs"+ icon="tabler:download"+ class="flex-1 sm:flex-none"+ @click="handleBatchDownload"+ >+ <span>{{ $t('dashboard.photos.selection.batchDownload') }}</span>+ </UButton>+<UButtoncolor="error"variant="soft"diff --git a/i18n/locales/en.json b/i18n/locales/en.jsonindex 53bc55b4..15d4693f 100644--- a/i18n/locales/en.json+++ b/i18n/locales/en.json@@ -538,6 +538,7 @@"selection": {"selected": "{count} / {total} rows selected","batchReprocess": "Reprocess",+ "batchDownload": "Download","batchDelete": "Batch Delete"},"slideover": {@@ -588,6 +589,17 @@"batchSelectRequired": "Please select at least one photo for this operation","noStorageKey": "Unable to process: missing storage information","batchNoStorageKey": "{count} photos are missing storage information and cannot be processed",+ "batchNoUrl": "No photos with download URLs available",+ "batchPartialUrl": "Only {count} out of {total} photos have download URLs available",+ "downloadStarted": "Download started",+ "downloadingCount": "Downloading {count} photo(s)...",+ "batchDownloadSuccess": "Batch download completed successfully",+ "batchDownloadFailed": "Batch download failed",+ "batchDownloadPartial": "Batch download completed with some failures",+ "downloadedCount": "Downloaded {count} photo(s)",+ "downloadFailedCount": "Failed to download {count} photo(s)",+ "downloadPartialCount": "Downloaded {success} photo(s), {failed} failed",+ "warning": "Warning","error": "An error occurred","deleteFailed": "Failed to delete photo","batchDeleteFailed": "Batch delete failed",diff --git a/i18n/locales/ja.json b/i18n/locales/ja.jsonindex af4bb67b..46801b2c 100644--- a/i18n/locales/ja.json+++ b/i18n/locales/ja.json@@ -481,6 +481,7 @@"selection": {"selected": "{count} / {total}行選択済み","batchReprocess": "一括再処理",+ "batchDownload": "一括ダウンロード","batchDelete": "一括削除"},"slideover": {@@ -531,6 +532,17 @@"batchSelectRequired": "この操作を実行するには、少なくとも1枚の写真を選択してください","noStorageKey": "処理できません:ストレージ情報がありません","batchNoStorageKey": "{count}枚の写真のストレージ情報がなく、処理できません",+ "batchNoUrl": "ダウンロードURLが利用可能な写真がありません",+ "batchPartialUrl": "{count}枚の写真(合計{total}枚)のみダウンロードURLが利用可能です",+ "downloadStarted": "ダウンロード開始",+ "downloadingCount": "{count}枚の写真をダウンロード中...",+ "batchDownloadSuccess": "一括ダウンロード完了",+ "batchDownloadFailed": "一括ダウンロードに失敗しました",+ "batchDownloadPartial": "一括ダウンロードが完了しましたが、一部失敗しました",+ "downloadedCount": "{count}枚の写真をダウンロードしました",+ "downloadFailedCount": "{count}枚の写真のダウンロードに失敗しました",+ "downloadPartialCount": "{success}枚の写真をダウンロードしました。{failed}枚失敗しました",+ "warning": "警告","error": "エラーが発生しました","deleteFailed": "写真の削除に失敗しました","batchDeleteFailed": "一括削除に失敗しました",diff --git a/i18n/locales/zh-Hans.json b/i18n/locales/zh-Hans.jsonindex fbd0364e..d63682a9 100644--- a/i18n/locales/zh-Hans.json+++ b/i18n/locales/zh-Hans.json@@ -538,6 +538,7 @@"selection": {"selected": "{count} / {total} 行已选择","batchReprocess": "重新处理",+ "batchDownload": "批量下载","batchDelete": "批量删除"},"slideover": {@@ -588,6 +589,17 @@"batchSelectRequired": "请至少选择一张照片进行此操作","noStorageKey": "无法处理:缺少存储信息","batchNoStorageKey": "{count} 张照片缺少存储信息,无法处理",+ "batchNoUrl": "没有可用的下载链接照片",+ "batchPartialUrl": "仅有 {count} 张照片(共 {total} 张)具有可用的下载链接",+ "downloadStarted": "开始下载",+ "downloadingCount": "正在下载 {count} 张照片...",+ "batchDownloadSuccess": "批量下载完成",+ "batchDownloadFailed": "批量下载失败",+ "batchDownloadPartial": "批量下载已完成,部分失败",+ "downloadedCount": "已下载 {count} 张照片",+ "downloadFailedCount": "下载失败 {count} 张照片",+ "downloadPartialCount": "已下载 {success} 张照片,{failed} 张失败",+ "warning": "警告","error": "发生错误","deleteFailed": "删除照片失败","batchDeleteFailed": "批量删除失败",diff --git a/i18n/locales/zh-Hant-HK.json b/i18n/locales/zh-Hant-HK.jsonindex 42398b78..3e950ad2 100644--- a/i18n/locales/zh-Hant-HK.json+++ b/i18n/locales/zh-Hant-HK.json@@ -481,6 +481,7 @@"selection": {"selected": "已選擇 {count} / {total} 列","batchReprocess": "批量重新處理",+ "batchDownload": "批量下載","batchDelete": "批量刪除"},"slideover": {@@ -531,6 +532,17 @@"batchSelectRequired": "請選擇至少一張相片進行此操作","noStorageKey": "無法處理:缺少儲存資料","batchNoStorageKey": "{count} 張相片缺少儲存資料,無法處理",+ "batchNoUrl": "沒有可用下載連結的相片",+ "batchPartialUrl": "僅有 {count} 張相片(共 {total} 張)具有可用的下載連結",+ "downloadStarted": "開始下載",+ "downloadingCount": "正在下載 {count} 張相片...",+ "batchDownloadSuccess": "批量下載完成",+ "batchDownloadFailed": "批量下載失敗",+ "batchDownloadPartial": "批量下載已完成,部分失敗",+ "downloadedCount": "已下載 {count} 張相片",+ "downloadFailedCount": "下載失敗 {count} 張相片",+ "downloadPartialCount": "已下載 {success} 張相片,{failed} 張失敗",+ "warning": "警告","error": "發生錯誤","deleteFailed": "刪除相片失敗","batchDeleteFailed": "批量刪除失敗",diff --git a/i18n/locales/zh-Hant-TW.json b/i18n/locales/zh-Hant-TW.jsonindex 9356892c..6f3da128 100644--- a/i18n/locales/zh-Hant-TW.json+++ b/i18n/locales/zh-Hant-TW.json@@ -481,6 +481,7 @@"selection": {"selected": "已選擇 {count} / {total} 列","batchReprocess": "批量重新處理",+ "batchDownload": "批量下載","batchDelete": "批量刪除"},"slideover": {@@ -531,6 +532,17 @@"batchSelectRequired": "請選擇至少一張照片進行此操作","noStorageKey": "無法處理:缺少儲存資訊","batchNoStorageKey": "{count} 張照片缺少儲存資訊,無法處理",+ "batchNoUrl": "沒有可用下載連結的照片",+ "batchPartialUrl": "僅有 {count} 張照片(共 {total} 張)具有可用的下載連結",+ "downloadStarted": "開始下載",+ "downloadingCount": "正在下載 {count} 張照片...",+ "batchDownloadSuccess": "批量下載完成",+ "batchDownloadFailed": "批量下載失敗",+ "batchDownloadPartial": "批量下載已完成,部分失敗",+ "downloadedCount": "已下載 {count} 張照片",+ "downloadFailedCount": "下載失敗 {count} 張照片",+ "downloadPartialCount": "已下載 {success} 張照片,{failed} 張失敗",+ "warning": "警告","error": "發生錯誤","deleteFailed": "刪除照片失敗","batchDeleteFailed": "批量刪除失敗",