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
fix(queue): correct retry scheduling and control worker concurrency
Timothy Yinb73001c177f1
diff --git a/app/components/setting/SettingField.vue b/app/components/setting/SettingField.vueindex d162d62b..3aa8e261 100644--- a/app/components/setting/SettingField.vue+++ b/app/components/setting/SettingField.vue@@ -76,8 +76,12 @@ const getComponentProps = (): Record<string, any> => {switch (type) {case 'password':case 'url':+ propsMap.type = type+ breakcase 'number':propsMap.type = type+ propsMap.min = props.field.ui.min+ propsMap.max = props.field.ui.maxbreakcase 'select':propsMap.items = props.field.ui.options@@ -114,7 +118,12 @@ const getComponentProps = (): Record<string, any> => {const componentProps = computed(() => getComponentProps())const handleChange = (value: any) => {- emit('update:modelValue', value)+ emit(+ 'update:modelValue',+ props.field.ui.type === 'number' && value !== '' && value !== null+ ? Number(value)+ : value,+ )}const labelKey = computed(() => {diff --git a/app/pages/dashboard/settings/system.vue b/app/pages/dashboard/settings/system.vueindex ab91a229..3921e9cb 100644--- a/app/pages/dashboard/settings/system.vue+++ b/app/pages/dashboard/settings/system.vue@@ -45,6 +45,7 @@ const SYSTEM_SECTION_ORDER: SystemSection[] = [titleKey: 'settings.system.sections.fileProcessing',keys: ['upload.maxFileSize',+ 'queue.workerCount','upload.duplicateCheck.enabled','upload.duplicateCheck.mode',],diff --git a/i18n/locales/en.json b/i18n/locales/en.jsonindex 8abd589f..22f846ed 100644--- a/i18n/locales/en.json+++ b/i18n/locales/en.json@@ -1253,7 +1253,14 @@}}},- "sectionDescription": "Configure system-level behavior parameters. Changes here will affect global upload and service behavior."+ "sectionDescription": "Configure system-level behavior parameters. Changes here will affect global upload and service behavior.",+ "queue": {+ "workerCount": {+ "label": "Queue concurrency",+ "description": "Number of queue tasks processed simultaneously.",+ "help": "1–8, default 5. Changes apply immediately. Lower values use fewer resources; running tasks finish when concurrency is reduced."+ }+ }},"map": {"provider": {diff --git a/i18n/locales/ja.json b/i18n/locales/ja.jsonindex 76326d7d..711e7911 100644--- a/i18n/locales/ja.json+++ b/i18n/locales/ja.json@@ -1178,7 +1178,14 @@}}},- "sectionDescription": "システムレベルの動作パラメーターを設定します。ここでの変更はグローバルなアップロードとサービスの動作に影響します。"+ "sectionDescription": "システムレベルの動作パラメーターを設定します。ここでの変更はグローバルなアップロードとサービスの動作に影響します。",+ "queue": {+ "workerCount": {+ "label": "キューの同時実行数",+ "description": "同時に処理するキュータスクの数。",+ "help": "1〜8、初期値は5。保存後すぐに反映されます。小さい値ほどリソース使用量が減ります。減らした場合も実行中のタスクは完了まで続行します。"+ }+ }},"map": {"provider": {diff --git a/i18n/locales/ru.json b/i18n/locales/ru.jsonindex a7f6db2d..3ab8ea0b 100644--- a/i18n/locales/ru.json+++ b/i18n/locales/ru.json@@ -1253,7 +1253,14 @@}}},- "sectionDescription": "Настройте поведение системы. Изменения повлияют на общие правила загрузки и работу сервисов."+ "sectionDescription": "Настройте поведение системы. Изменения повлияют на общие правила загрузки и работу сервисов.",+ "queue": {+ "workerCount": {+ "label": "Параллельность очереди",+ "description": "Количество одновременно обрабатываемых задач очереди.",+ "help": "От 1 до 8, по умолчанию 5. Изменения применяются сразу. Меньшие значения снижают нагрузку; при уменьшении уже запущенные задачи завершаются."+ }+ }},"map": {"provider": {diff --git a/i18n/locales/zh-Hans.json b/i18n/locales/zh-Hans.jsonindex 7f946443..b4318160 100644--- a/i18n/locales/zh-Hans.json+++ b/i18n/locales/zh-Hans.json@@ -1253,7 +1253,14 @@}}},- "sectionDescription": "配置系统级行为参数。这里的修改会影响全局上传和服务行为。"+ "sectionDescription": "配置系统级行为参数。这里的修改会影响全局上传和服务行为。",+ "queue": {+ "workerCount": {+ "label": "队列并发数",+ "description": "同时处理的队列任务数量。",+ "help": "范围 1–8,默认 5。保存后立即生效;较低值可降低资源占用,减少并发时已开始的任务会继续完成。"+ }+ }},"map": {"provider": {diff --git a/i18n/locales/zh-Hant-HK.json b/i18n/locales/zh-Hant-HK.jsonindex 10810e1d..99e0f465 100644--- a/i18n/locales/zh-Hant-HK.json+++ b/i18n/locales/zh-Hant-HK.json@@ -1178,7 +1178,14 @@}}},- "sectionDescription": "設定系統級行為參數。這裡的修改會影響全域上傳和服務行為。"+ "sectionDescription": "設定系統級行為參數。這裡的修改會影響全域上傳和服務行為。",+ "queue": {+ "workerCount": {+ "label": "佇列並行數",+ "description": "同時處理的佇列工作數量。",+ "help": "範圍 1–8,預設 5。儲存後立即生效;較低值可降低資源使用,減少並行數時已開始的工作會繼續完成。"+ }+ }},"map": {"provider": {diff --git a/i18n/locales/zh-Hant-TW.json b/i18n/locales/zh-Hant-TW.jsonindex a1598b98..818be567 100644--- a/i18n/locales/zh-Hant-TW.json+++ b/i18n/locales/zh-Hant-TW.json@@ -1178,7 +1178,14 @@}}},- "sectionDescription": "設定系統級行為參數。這裡的修改會影響全域上傳和服務行為。"+ "sectionDescription": "設定系統級行為參數。這裡的修改會影響全域上傳和服務行為。",+ "queue": {+ "workerCount": {+ "label": "佇列並行數",+ "description": "同時處理的佇列工作數量。",+ "help": "範圍 1–8,預設 5。儲存後立即生效;較低值可降低資源使用,減少並行數時已開始的工作會繼續完成。"+ }+ }},"map": {"provider": {diff --git a/server/api/queue/task/retry-batch.post.ts b/server/api/queue/task/retry-batch.post.tsindex 64a5ec3b..34fc956a 100644--- a/server/api/queue/task/retry-batch.post.ts+++ b/server/api/queue/task/retry-batch.post.ts@@ -63,7 +63,7 @@ export default defineEventHandler(async (event) => {statusStage: null,errorMessage: null,attempts: 0, // 重置尝试次数- createdAt: new Date(), // 更新创建时间以便重新调度+ availableAt: new Date(),}).where(inArray(tables.pipelineQueue.id, failedTaskIds))diff --git a/server/api/queue/task/retry.post.ts b/server/api/queue/task/retry.post.tsindex f4478b87..67e6e0a9 100644--- a/server/api/queue/task/retry.post.ts+++ b/server/api/queue/task/retry.post.ts@@ -46,7 +46,7 @@ export default defineEventHandler(async (event) => {statusStage: null,errorMessage: null,attempts: 0, // 重置尝试次数- createdAt: new Date(), // 更新创建时间以便重新调度+ availableAt: new Date(),}).where(eq(tables.pipelineQueue.id, taskId))diff --git a/server/database/migrations/0015_smart_titanium_man.sql b/server/database/migrations/0015_smart_titanium_man.sqlnew file mode 100644index 00000000..975a7456--- /dev/null+++ b/server/database/migrations/0015_smart_titanium_man.sql@@ -0,0 +1,2 @@+ALTER TABLE `pipeline_queue` ADD `available_at` integer DEFAULT 0 NOT NULL;--> statement-breakpoint+CREATE INDEX `idx_pipeline_queue_pending` ON `pipeline_queue` ("priority" DESC,`created_at`,`id`) WHERE "pipeline_queue"."status" = 'pending';diff --git a/server/database/migrations/meta/0015_snapshot.json b/server/database/migrations/meta/0015_snapshot.jsonnew file mode 100644index 00000000..6c139707--- /dev/null+++ b/server/database/migrations/meta/0015_snapshot.json@@ -0,0 +1,884 @@+{+ "version": "6",+ "dialect": "sqlite",+ "id": "606e2e14-6684-430a-bdeb-ef753e664f47",+ "prevId": "aafdad2d-343f-49bc-964b-7c914f3877f3",+ "tables": {+ "album_photos": {+ "name": "album_photos",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": true+ },+ "album_id": {+ "name": "album_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "photo_id": {+ "name": "photo_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "position": {+ "name": "position",+ "type": "real",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": 1000000+ },+ "added_at": {+ "name": "added_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "(unixepoch())"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "album_photos_album_id_albums_id_fk": {+ "name": "album_photos_album_id_albums_id_fk",+ "tableFrom": "album_photos",+ "tableTo": "albums",+ "columnsFrom": [+ "album_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "album_photos_photo_id_photos_id_fk": {+ "name": "album_photos_photo_id_photos_id_fk",+ "tableFrom": "album_photos",+ "tableTo": "photos",+ "columnsFrom": [+ "photo_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "albums": {+ "name": "albums",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": true+ },+ "title": {+ "name": "title",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "description": {+ "name": "description",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "cover_photo_id": {+ "name": "cover_photo_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "is_hidden": {+ "name": "is_hidden",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": false+ },+ "password_hash": {+ "name": "password_hash",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "position": {+ "name": "position",+ "type": "real",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": 0+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "(unixepoch())"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "(unixepoch())"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "albums_cover_photo_id_photos_id_fk": {+ "name": "albums_cover_photo_id_photos_id_fk",+ "tableFrom": "albums",+ "tableTo": "photos",+ "columnsFrom": [+ "cover_photo_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "photo_access_keys": {+ "name": "photo_access_keys",+ "columns": {+ "access_key": {+ "name": "access_key",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "photo_id": {+ "name": "photo_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ }+ },+ "indexes": {+ "idx_photo_access_keys_photo_id": {+ "name": "idx_photo_access_keys_photo_id",+ "columns": [+ "photo_id"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "photo_access_keys_photo_id_photos_id_fk": {+ "name": "photo_access_keys_photo_id_photos_id_fk",+ "tableFrom": "photo_access_keys",+ "tableTo": "photos",+ "columnsFrom": [+ "photo_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "photo_access_keys_access_key_photo_id_pk": {+ "columns": [+ "access_key",+ "photo_id"+ ],+ "name": "photo_access_keys_access_key_photo_id_pk"+ }+ },+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "photo_reactions": {+ "name": "photo_reactions",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": true+ },+ "photo_id": {+ "name": "photo_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "reaction_type": {+ "name": "reaction_type",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "fingerprint": {+ "name": "fingerprint",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "ip_address": {+ "name": "ip_address",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "user_agent": {+ "name": "user_agent",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "(unixepoch())"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "(unixepoch())"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "photo_reactions_photo_id_photos_id_fk": {+ "name": "photo_reactions_photo_id_photos_id_fk",+ "tableFrom": "photo_reactions",+ "tableTo": "photos",+ "columnsFrom": [+ "photo_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "photos": {+ "name": "photos",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "title": {+ "name": "title",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "description": {+ "name": "description",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "width": {+ "name": "width",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "height": {+ "name": "height",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "aspect_ratio": {+ "name": "aspect_ratio",+ "type": "real",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "date_taken": {+ "name": "date_taken",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "storage_key": {+ "name": "storage_key",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "thumbnail_key": {+ "name": "thumbnail_key",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "file_size": {+ "name": "file_size",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "last_modified": {+ "name": "last_modified",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "original_url": {+ "name": "original_url",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "thumbnail_url": {+ "name": "thumbnail_url",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "thumbnail_hash": {+ "name": "thumbnail_hash",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "tags": {+ "name": "tags",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "exif": {+ "name": "exif",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "latitude": {+ "name": "latitude",+ "type": "real",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "longitude": {+ "name": "longitude",+ "type": "real",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "country": {+ "name": "country",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "city": {+ "name": "city",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "location_name": {+ "name": "location_name",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "is_live_photo": {+ "name": "is_live_photo",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": 0+ },+ "live_photo_video_url": {+ "name": "live_photo_video_url",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "live_photo_video_key": {+ "name": "live_photo_video_key",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {+ "photos_id_unique": {+ "name": "photos_id_unique",+ "columns": [+ "id"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "pipeline_queue": {+ "name": "pipeline_queue",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": true+ },+ "payload": {+ "name": "payload",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'{\"type\":\"photo\",\"storageKey\":\"\"}'"+ },+ "priority": {+ "name": "priority",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": 0+ },+ "available_at": {+ "name": "available_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "0"+ },+ "attempts": {+ "name": "attempts",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": 0+ },+ "max_attempts": {+ "name": "max_attempts",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": 3+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'pending'"+ },+ "status_stage": {+ "name": "status_stage",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "error_message": {+ "name": "error_message",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "(unixepoch())"+ },+ "completed_at": {+ "name": "completed_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {+ "idx_pipeline_queue_pending": {+ "name": "idx_pipeline_queue_pending",+ "columns": [+ "\"priority\" DESC",+ "created_at",+ "id"+ ],+ "isUnique": false,+ "where": "\"pipeline_queue\".\"status\" = 'pending'"+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "settings": {+ "name": "settings",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": true+ },+ "namespace": {+ "name": "namespace",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'common'"+ },+ "key": {+ "name": "key",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "type": {+ "name": "type",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "value": {+ "name": "value",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "default_value": {+ "name": "default_value",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "label": {+ "name": "label",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "description": {+ "name": "description",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "is_public": {+ "name": "is_public",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": false+ },+ "is_readonly": {+ "name": "is_readonly",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": false+ },+ "is_secret": {+ "name": "is_secret",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": false+ },+ "enum": {+ "name": "enum",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "(unixepoch())"+ },+ "updated_by": {+ "name": "updated_by",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {+ "idx_namespace_key": {+ "name": "idx_namespace_key",+ "columns": [+ "namespace",+ "key"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {+ "settings_updated_by_users_id_fk": {+ "name": "settings_updated_by_users_id_fk",+ "tableFrom": "settings",+ "tableTo": "users",+ "columnsFrom": [+ "updated_by"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "settings_storage_providers": {+ "name": "settings_storage_providers",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": true+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "provider": {+ "name": "provider",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "config": {+ "name": "config",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "(unixepoch())"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "(unixepoch())"+ }+ },+ "indexes": {},+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "users": {+ "name": "users",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": true+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "email": {+ "name": "email",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "password": {+ "name": "password",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "avatar": {+ "name": "avatar",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "is_admin": {+ "name": "is_admin",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": 0+ }+ },+ "indexes": {+ "users_name_unique": {+ "name": "users_name_unique",+ "columns": [+ "name"+ ],+ "isUnique": true+ },+ "users_email_unique": {+ "name": "users_email_unique",+ "columns": [+ "email"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ }+ },+ "views": {},+ "enums": {},+ "_meta": {+ "schemas": {},+ "tables": {},+ "columns": {}+ },+ "internal": {+ "indexes": {+ "idx_pipeline_queue_pending": {+ "columns": {+ "\"priority\" DESC": {+ "isExpression": true+ }+ }+ }+ }+ }+}diff --git a/server/database/migrations/meta/_journal.json b/server/database/migrations/meta/_journal.jsonindex e17a7b1e..7103d90c 100644--- a/server/database/migrations/meta/_journal.json+++ b/server/database/migrations/meta/_journal.json@@ -106,6 +106,13 @@"when": 1791384033370,"tag": "0014_photo_access_keys","breakpoints": true+ },+ {+ "idx": 15,+ "version": "6",+ "when": 1791717320179,+ "tag": "0015_smart_titanium_man",+ "breakpoints": true}]}\ No newline at end of filediff --git a/server/database/schema.ts b/server/database/schema.tsindex 9edf6bfe..41b3a652 100644--- a/server/database/schema.ts+++ b/server/database/schema.ts@@ -89,46 +89,57 @@ export const photoAccessKeys = sqliteTable(],)-export const pipelineQueue = sqliteTable('pipeline_queue', {- id: integer('id').primaryKey({ autoIncrement: true }),- payload: text('payload', { mode: 'json' })- .$type<PipelineQueuePayload>()- .notNull()- .default({- type: 'photo',- storageKey: '',- } satisfies PipelineQueuePayload),- priority: integer('priority').default(0).notNull(),- attempts: integer('attempts').default(0).notNull(),- maxAttempts: integer('max_attempts').default(3).notNull(),- status: text('status', {- enum: [- 'pending', // Waiting to be processed- 'in-stages', // Currently being processed- 'completed', // Successfully processed- 'failed', // Processing failed- ],- })- .notNull()- .default('pending'),- statusStage: text('status_stage', {- enum: [- 'preprocessing',- 'metadata',- 'thumbnail',- 'exif',- 'motion-photo',- 'reverse-geocoding',- 'live-photo',- 'location-erase',- ],- }),- errorMessage: text('error_message'),- createdAt: integer('created_at', { mode: 'timestamp' })- .notNull()- .default(sql`(unixepoch())`),- completedAt: integer('completed_at', { mode: 'timestamp' }),-})+export const pipelineQueue = sqliteTable(+ 'pipeline_queue',+ {+ id: integer('id').primaryKey({ autoIncrement: true }),+ payload: text('payload', { mode: 'json' })+ .$type<PipelineQueuePayload>()+ .notNull()+ .default({+ type: 'photo',+ storageKey: '',+ } satisfies PipelineQueuePayload),+ priority: integer('priority').default(0).notNull(),+ availableAt: integer('available_at', { mode: 'timestamp_ms' })+ .notNull()+ .default(sql`0`),+ attempts: integer('attempts').default(0).notNull(),+ maxAttempts: integer('max_attempts').default(3).notNull(),+ status: text('status', {+ enum: [+ 'pending', // Waiting to be processed+ 'in-stages', // Currently being processed+ 'completed', // Successfully processed+ 'failed', // Processing failed+ ],+ })+ .notNull()+ .default('pending'),+ statusStage: text('status_stage', {+ enum: [+ 'preprocessing',+ 'metadata',+ 'thumbnail',+ 'exif',+ 'motion-photo',+ 'reverse-geocoding',+ 'live-photo',+ 'location-erase',+ ],+ }),+ errorMessage: text('error_message'),+ createdAt: integer('created_at', { mode: 'timestamp' })+ .notNull()+ .default(sql`(unixepoch())`),+ completedAt: integer('completed_at', { mode: 'timestamp' }),+ },+ (t) => [+ index('idx_pipeline_queue_pending')+ .on(sql`${t.priority} DESC`, t.createdAt, t.id)+ .where(sql`${t.status} = 'pending'`),+ ],+)// 照片表态表export const photoReactions = sqliteTable('photo_reactions', {diff --git a/server/plugins/4.pipeline-queue.ts b/server/plugins/4.pipeline-queue.tsindex abaed8db..3b20366a 100644--- a/server/plugins/4.pipeline-queue.ts+++ b/server/plugins/4.pipeline-queue.ts@@ -1,40 +1,48 @@import { WorkerPool } from '../services/pipeline-queue'+import { settingsManager } from '../services/settings/settingsManager'+import { DEFAULT_QUEUE_WORKER_COUNT } from '~~/shared/utils/queue-config'-export default defineNitroPlugin(async (_nitroApp) => {+export default defineNitroPlugin(async (nitroApp) => {const _logger = logger.dynamic('queue')-+ const shutdownTimeoutMs = 30_000const workerPool = new WorkerPool({- workerCount: 5,+ workerCount:+ (await settingsManager.get<number>('system', 'queue.workerCount')) ??+ DEFAULT_QUEUE_WORKER_COUNT,intervalMs: 1500,intervalOffset: 300,- enableLoadBalancing: true,+ enableLoadBalancing: false,statsReportInterval: 60000 * 10,},_logger,)await workerPool.start()-globalThis.__workerPool = workerPool- const exitHandler = async () => {+ let shutdown: Promise<void> | undefined+ const stop = () => (shutdown ||= workerPool.stop())+ nitroApp.hooks.hook('close', stop)++ const exitHandler = () => {_logger.info('Shutting down worker pool...')- await workerPool.stop()- process.exit(0)+ const deadline = setTimeout(() => {+ _logger.warn(+ 'Queue shutdown deadline exceeded; unfinished tasks will recover on startup',+ )+ process.exit(1)+ }, shutdownTimeoutMs)+ void stop()+ .then(() => {+ clearTimeout(deadline)+ process.exit(0)+ })+ .catch((error) => {+ clearTimeout(deadline)+ _logger.error('Queue shutdown failed', error)+ process.exit(1)+ })}-- process.on('SIGINT', exitHandler)- process.on('SIGTERM', exitHandler)-- // 每 5 分钟进行一次负载均衡检查- setInterval(- async () => {- try {- await workerPool.rebalance()- } catch (error) {- _logger.error('Rebalance failed:', error)- }- },- 5 * 60 * 1000,- )+ process.once('SIGINT', exitHandler)+ process.once('SIGTERM', exitHandler)})diff --git a/server/services/location/geocoding.ts b/server/services/location/geocoding.tsindex a178e850..24a98e4b 100644--- a/server/services/location/geocoding.ts+++ b/server/services/location/geocoding.ts@@ -30,7 +30,7 @@ export class MapboxGeocodingProvider implements GeocodingProvider {async reverseGeocode(lat: number, lon: number): Promise<LocationInfo | null> {try {return await withRetry(- async () => {+ async (signal) => {// 应用速率限制await this.applyRateLimit()@@ -55,7 +55,7 @@ export class MapboxGeocodingProvider implements GeocodingProvider {logger.location.info(`Mapbox API URL: ${url.toString()}`)- const response = await fetch(url.toString())+ const response = await fetch(url.toString(), { signal })if (!response.ok) {throw new Error(@@ -146,7 +146,7 @@ export class NominatimGeocodingProvider implements GeocodingProvider {async reverseGeocode(lat: number, lon: number): Promise<LocationInfo | null> {try {return await withRetry(- async () => {+ async (signal) => {// 应用速率限制await this.applyRateLimit()@@ -162,6 +162,7 @@ export class NominatimGeocodingProvider implements GeocodingProvider {url.searchParams.set('accept-language', `${language},en`)const response = await fetch(url.toString(), {+ signal,headers: {'User-Agent': this.userAgent,},diff --git a/server/services/pipeline-queue/manager.ts b/server/services/pipeline-queue/manager.tsindex d2202213..4ccc08f5 100644--- a/server/services/pipeline-queue/manager.ts+++ b/server/services/pipeline-queue/manager.ts@@ -2,7 +2,7 @@ import type { ConsolaInstance } from 'consola'import { mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises'import { tmpdir } from 'node:os'import path from 'path'-import { asc, desc, eq, sql } from 'drizzle-orm'+import { and, asc, desc, eq, lte, sql } from 'drizzle-orm'import { exiftool } from 'exiftool-vendored'import type {NewPipelineQueueItem,@@ -41,6 +41,8 @@ const EXIF_LOCATION_KEYS = ['GPSDestBearingRef',] as const+class PermanentTaskError extends Error {}+const stripLocationFromExif = <T extends Record<string, any> | null | undefined,>(@@ -64,6 +66,7 @@ export class QueueManager {private logger: ConsolaInstanceprivate isProcessing: boolean = falseprivate processingInterval: NodeJS.Timeout | null = null+ private activeTask: Promise<void> | null = nullprivate processedCount: number = 0private errorCount: number = 0private startTime: Date@@ -159,11 +162,17 @@ export class QueueManager {const highestPriorityPendingTask = tx.select().from(tables.pipelineQueue)- .where(eq(tables.pipelineQueue.status, 'pending'))+ .where(+ and(+ eq(tables.pipelineQueue.status, 'pending'),+ lte(tables.pipelineQueue.availableAt, new Date()),+ ),+ )// 优先处理高优先级和较早创建的任务.orderBy(desc(tables.pipelineQueue.priority),asc(tables.pipelineQueue.createdAt),+ asc(tables.pipelineQueue.id),).limit(1).get()@@ -218,7 +227,11 @@ export class QueueManager {* @param taskId 任务ID* @param errorMessage 错误信息*/- async markTaskFailed(taskId: number, errorMessage?: string): Promise<void> {+ async markTaskFailed(+ taskId: number,+ errorMessage?: string,+ retryable = true,+ ): Promise<void> {const db = useDB()const task = await db.select()@@ -229,7 +242,7 @@ export class QueueManager {if (!task) returnconst newAttempts = task.attempts + 1- const shouldRetry = newAttempts < task.maxAttempts+ const shouldRetry = retryable && newAttempts < task.maxAttempts// 计算重试延迟(指数退避)const retryDelay = shouldRetry@@ -243,9 +256,12 @@ export class QueueManager {attempts: newAttempts,errorMessage: errorMessage || 'Unknown error',// 如果重试,设置延迟重试时间- ...(shouldRetry && retryDelay > 0+ statusStage: null,+ ...(shouldRetry? {- createdAt: new Date(Date.now() + retryDelay),+ availableAt: new Date(+ Date.now() + retryDelay + Math.floor(Math.random() * 500),+ ),}: {}),})@@ -292,7 +308,7 @@ export class QueueManager {}}if (!storageObject) {- throw new Error(`Storage object not found`)+ throw new PermanentTaskError(`Storage object not found`)}// STEP 1: 预处理 - 转换 HEIC 到 JPEG 并上传@@ -530,7 +546,7 @@ export class QueueManager {this.logger.warn(`[${taskId}:reverse-geocoding] photo ${photoId} not found`,)- throw new Error(`Photo ${photoId} not found`)+ throw new PermanentTaskError(`Photo ${photoId} not found`)}let latitude = payload.latitude ?? photo.latitude ?? undefined@@ -570,7 +586,9 @@ export class QueueManager {locationName: null,}).where(eq(tables.photos.id, photoId))- throw new Error(`Missing coordinates for photo ${photoId}`)+ throw new PermanentTaskError(+ `Missing coordinates for photo ${photoId}`,+ )}const locationInfo = await extractLocationFromGPS(@@ -629,16 +647,20 @@ export class QueueManager {.get()if (!photo) {- throw new Error(`Photo ${payload.photoId} not found`)+ throw new PermanentTaskError(`Photo ${payload.photoId} not found`)}if (!photo.storageKey) {- throw new Error(`Photo ${payload.photoId} has no storage key`)+ throw new PermanentTaskError(+ `Photo ${payload.photoId} has no storage key`,+ )}const originalBuffer = await storageProvider.get(photo.storageKey)if (!originalBuffer) {- throw new Error(`Photo file ${photo.storageKey} not found in storage`)+ throw new PermanentTaskError(+ `Photo file ${photo.storageKey} not found in storage`,+ )}const tempRoot = tmpdir()@@ -728,7 +750,7 @@ export class QueueManager {}}if (!storageObject) {- throw new Error(`Storage object not found`)+ throw new PermanentTaskError(`Storage object not found`)}// 寻找是否有同名的照片文件@@ -830,7 +852,7 @@ export class QueueManager {await this.processors.eraseLocation(task)breakdefault:- throw new Error(`Unknown task type: ${type}`)+ throw new PermanentTaskError(`Unknown task type: ${type}`)}await this.markTaskCompleted(task.id)@@ -853,7 +875,11 @@ export class QueueManager {} catch (error) {const errorMessage =error instanceof Error ? error.message : String(error)- await this.markTaskFailed(task.id, errorMessage)+ await this.markTaskFailed(+ task.id,+ errorMessage,+ !(error instanceof PermanentTaskError),+ )this.errorCount++this.logger.error(`[${this.workerId}] Task ${task.id} processing failed (Error: ${this.errorCount}):`,@@ -875,29 +901,35 @@ export class QueueManager {if (this.processingInterval) returnthis.processingInterval = setInterval(() => {- this.processNextTask().catch((error) => {- this.logger.error('Error occurred while processing the queue:', error)- })+ this.runTask()}, intervalMs)this.logger.success(`Queue processing started with interval: ${intervalMs}ms`,)- this.processNextTask().catch((error) => {- this.logger.error('Error occurred while processing the queue:', error)- })+ this.runTask()+ }++ private runTask(): void {+ if (this.activeTask) return+ this.activeTask = this.processNextTask()+ .catch((error) => this.logger.error('Error processing queue:', error))+ .finally(() => {+ this.activeTask = null+ })}/*** 停止处理队列*/- stopProcessing(): void {+ async stopProcessing(): Promise<void> {if (this.processingInterval) {clearInterval(this.processingInterval)this.processingInterval = nullthis.logger.warn('Queue processing stopped')}+ await this.activeTask}/**diff --git a/server/services/pipeline-queue/worker-pool.ts b/server/services/pipeline-queue/worker-pool.tsindex 1a776c07..0b343797 100644--- a/server/services/pipeline-queue/worker-pool.ts+++ b/server/services/pipeline-queue/worker-pool.ts@@ -3,6 +3,10 @@ import { consola } from 'consola'import { eq } from 'drizzle-orm'import { useDB, tables } from '~~/server/utils/db'import { QueueManager } from './manager'+import {+ DEFAULT_QUEUE_WORKER_COUNT,+ validateQueueWorkerCount,+} from '~~/shared/utils/queue-config'export interface WorkerPoolConfig {/** 工作器数量 */@@ -44,17 +48,19 @@ export class WorkerPool {private config: WorkerPoolConfigprivate statsInterval: NodeJS.Timeout | null = nullprivate isRunning: boolean = false+ private resizing: Promise<void> = Promise.resolve()constructor(config: Partial<WorkerPoolConfig>, logger?: ConsolaInstance) {this.config = {- workerCount: 3,+ workerCount: DEFAULT_QUEUE_WORKER_COUNT,intervalMs: 2000,intervalOffset: 300,- enableLoadBalancing: true,+ enableLoadBalancing: false,statsReportInterval: 30000,...config,}this.logger = logger || consola.withTag('worker-pool')+ validateQueueWorkerCount(this.config.workerCount)}/**@@ -108,6 +114,7 @@ export class WorkerPool {}this.logger.info('Stopping WorkerPool...')+ this.isRunning = false// 停止统计报告if (this.statsInterval) {@@ -118,7 +125,7 @@ export class WorkerPool {// 停止所有工作器const stopPromises = this.workers.map(async (worker, _index) => {try {- worker.stopProcessing()+ await worker.stopProcessing()this.logger.info(`worker [${worker.getWorkerId()}] stopped`)} catch (error) {this.logger.error(@@ -129,6 +136,7 @@ export class WorkerPool {})await Promise.allSettled(stopPromises)+ await this.resizingthis.workers = []this.isRunning = false@@ -217,12 +225,8 @@ export class WorkerPool {(w) => w.getWorkerId() === workerStat.workerId,)if (worker) {- worker.stopProcessing()-- setTimeout(() => {- worker.startProcessing(this.config.intervalMs)- this.logger.info(`Worker ${workerStat.workerId} has been restarted`)- }, 5000)+ await worker.stopProcessing()+ if (this.isRunning) worker.startProcessing(this.config.intervalMs)}}}@@ -235,7 +239,7 @@ export class WorkerPool {return {}}- return await this.workers[0].getQueueStats()+ return await this.workers[0]!.getQueueStats()}/**@@ -292,11 +296,38 @@ export class WorkerPool {return this.workers.length}+ /** Apply settings changes serially; draining workers cannot be restarted early. */+ setWorkerCount(workerCount: number): Promise<void> {+ validateQueueWorkerCount(workerCount)+ const resize = this.resizing.then(async () => {+ this.config.workerCount = workerCount+ if (!this.isRunning) return+ if (workerCount < this.workers.length) {+ const removed = this.workers.splice(workerCount)+ await Promise.all(removed.map((worker) => worker.stopProcessing()))+ }+ while (this.isRunning && this.workers.length < workerCount) {+ const index = this.workers.length+ const worker = QueueManager.getInstance(+ `worker-${index + 1}`,+ this.logger,+ )+ this.workers.push(worker)+ worker.startProcessing(+ this.config.intervalMs + index * this.config.intervalOffset,+ )+ }+ this.logger.info(`Queue concurrency updated to ${workerCount}`)+ })+ this.resizing = resize.catch(() => {})+ return resize+ }+/*** 获取第一个工作器(用于添加任务)*/getFirstWorker(): QueueManager | null {- return this.workers.length > 0 ? this.workers[0] : null+ return this.workers[0] ?? null}/**diff --git a/server/services/settings/contants.ts b/server/services/settings/contants.tsindex e3848095..49f2fe72 100644--- a/server/services/settings/contants.ts+++ b/server/services/settings/contants.ts@@ -7,6 +7,14 @@ export type StorageProvider = (typeof STORAGE_PROVIDERS)[number]export const DEFAULT_SETTINGS = [// NAMESPACE: system+ {+ namespace: 'system',+ key: 'queue.workerCount',+ type: 'number',+ defaultValue: 5,+ label: 'settings.system.queue.workerCount.label',+ description: 'settings.system.queue.workerCount.description',+ },{namespace: 'system',key: 'firstLaunch',diff --git a/server/services/settings/settingsManager.ts b/server/services/settings/settingsManager.tsindex 67eb2bdd..3067edcc 100644--- a/server/services/settings/settingsManager.ts+++ b/server/services/settings/settingsManager.ts@@ -6,6 +6,7 @@ import type {SettingValue,} from '~~/shared/types/settings'import type { SettingKey, SettingNamespace } from './contants'+import { validateQueueWorkerCount } from '~~/shared/utils/queue-config'export class SettingsManager {private static instance: SettingsManager@@ -282,6 +283,9 @@ export class SettingsManager {}const serializedValue = this.serialize(value)+ if (namespace === 'system' && key === 'queue.workerCount') {+ validateQueueWorkerCount(value)+ }db.update(tables.settings).set({@@ -299,6 +303,13 @@ export class SettingsManager {this._logger.info(`Setting ${namespace}:${key} updated`)this.settingsCache.set(cacheKey, value)+ if (+ namespace === 'system' &&+ key === 'queue.workerCount' &&+ !this.isInitializing+ ) {+ await globalThis.__workerPool?.setWorkerCount(value as number)+ }// Trigger storage provider switch if storage:provider is being changed// Skip during initialization as storage manager is not yet initializeddiff --git a/server/services/settings/ui-config.ts b/server/services/settings/ui-config.tsindex e4ce5bc0..a929d326 100644--- a/server/services/settings/ui-config.ts+++ b/server/services/settings/ui-config.ts@@ -19,7 +19,7 @@ export const APP_SETTINGS_UI: Record<string, FieldUIConfig> = {slogan: {type: 'input',placeholder: 'Your gallery slogan',- help: 'settings.app.slogan.help',+ help: 'settings.app.slogan.help',},author: {type: 'input',@@ -120,7 +120,7 @@ export const ANALYTICS_SETTINGS_UI: Record<string, FieldUIConfig> = {type: 'textarea',rows: 12,placeholder:- '<!-- Google Analytics -->\n<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXX"></script>\n<script>\n window.dataLayer = window.dataLayer || [];\n function gtag(){dataLayer.push(arguments);}\n gtag(\'js\', new Date());\n gtag(\'config\', \'G-XXXX\');\n</script>',+ "<!-- Google Analytics -->\n<script async src=\"https://www.googletagmanager.com/gtag/js?id=G-XXXX\"></script>\n<script>\n window.dataLayer = window.dataLayer || [];\n function gtag(){dataLayer.push(arguments);}\n gtag('js', new Date());\n gtag('config', 'G-XXXX');\n</script>",help: 'settings.analytics.headScripts.help',},bodyScripts: {@@ -133,6 +133,12 @@ export const ANALYTICS_SETTINGS_UI: Record<string, FieldUIConfig> = {}export const SYSTEM_SETTINGS_UI: Record<string, FieldUIConfig> = {+ 'queue.workerCount': {+ type: 'number',+ min: 1,+ max: 8,+ help: 'settings.system.queue.workerCount.help',+ },'upload.maxFileSize': {type: 'number',help: 'settings.app.upload.maxFileSize.help',diff --git a/server/services/storage/providers/openlist.ts b/server/services/storage/providers/openlist.tsindex aaae2459..94877d78 100644--- a/server/services/storage/providers/openlist.ts+++ b/server/services/storage/providers/openlist.ts@@ -315,11 +315,16 @@ export class OpenListStorageProvider implements StorageProvider {status: resp.status,body: text,})- return null+ if (resp.status === 404) return null+ throw new Error(`OpenList metadata request failed: ${resp.status}`)}const data = (await resp.json().catch(() => null)) as any- if (!data) return { key }+ if (!data) throw new Error('Invalid OpenList metadata response')+ if (typeof data.code === 'number' && data.code !== 200) {+ if (data.code === 404) return null+ throw new Error(`OpenList metadata error: ${data.code}`)+ }const node = data?.data || {}const size = node?.sizeconst modified = node?.modified || node?.lastModifieddiff --git a/server/services/storage/providers/s3.ts b/server/services/storage/providers/s3.tsindex 1e73d335..160b5605 100644--- a/server/services/storage/providers/s3.ts+++ b/server/services/storage/providers/s3.ts@@ -423,13 +423,9 @@ export class S3StorageProvider implements StorageProvider {const resp = await this.client.send(cmd)- if (!resp.ETag) {- return null- }-return {key,- size: resp.ContentLength || 0,+ size: resp.ContentLength,lastModified: resp.LastModified,etag: resp.ETag,}diff --git a/server/services/video/livephoto.ts b/server/services/video/livephoto.tsindex 255ab5c9..fd28e042 100644--- a/server/services/video/livephoto.ts+++ b/server/services/video/livephoto.ts@@ -104,9 +104,16 @@ export const findLivePhotoVideoForImage = async (// 检查存储中是否存在对应的视频文件for (const videoKey of possibleVideoKeys) {try {- const videoBuffer = await storageProvider.get(videoKey)- if (videoBuffer) {- const videoSize = videoBuffer.length+ const meta = await storageProvider.getFileMeta(videoKey)+ if (meta) {+ // Custom metadata endpoints may omit size; retain a compatibility fallback.+ const videoSize =+ typeof meta.size === 'number' &&+ Number.isFinite(meta.size) &&+ meta.size >= 0+ ? meta.size+ : (await storageProvider.get(videoKey))?.length+ if (videoSize === undefined) continue// 检查是否符合 LivePhoto 视频的特征const fileName = path.basename(videoKey)diff --git a/server/utils/retry.ts b/server/utils/retry.tsindex 4d8ec48c..cec435e1 100644--- a/server/utils/retry.ts+++ b/server/utils/retry.ts@@ -38,7 +38,7 @@ export interface RetryOptions {* ```*/export async function withRetry<T>(- operation: () => Promise<T>,+ operation: (signal: AbortSignal) => Promise<T>,options: RetryOptions = {},logger?: Logger[keyof Logger],): Promise<T> {@@ -54,26 +54,30 @@ export async function withRetry<T>(let lastError: Errorfor (let attempt = 1; attempt <= maxAttempts; attempt++) {+ const controller = new AbortController()+ let timer: ReturnType<typeof setTimeout> | undefinedtry {logger?.info(`Operation attempt ${attempt}/${maxAttempts}`)// 应用超时机制- const result = await Promise.race([- operation(),- new Promise<never>((_, reject) =>- setTimeout(- () => reject(new Error(`Operation timeout after ${timeout}ms`)),- timeout,- ),- ),- ])+ const timeoutError = new Error(`Operation timeout after ${timeout}ms`)+ timer = setTimeout(() => controller.abort(timeoutError), timeout)+ // Keep the resource slot until non-cancellable operations settle. Racing+ // them against a timer would allow retries to overlap the original work.+ const result = await operation(controller.signal)+ if (controller.signal.aborted) throw timeoutErrorif (attempt > 1) {logger?.success(`Operation succeeded on attempt ${attempt}`)}return result} catch (error) {- lastError = error as Error+ if (timer) clearTimeout(timer)+ lastError = controller.signal.aborted+ ? controller.signal.reason+ : error instanceof Error+ ? error+ : new Error(String(error))logger?.warn(`Attempt ${attempt} failed:`, error)const shouldRetry = attempt < maxAttempts && retryCondition(lastError)@@ -87,6 +91,8 @@ export async function withRetry<T>(logger?.info(`Retrying in ${delay}ms...`)await new Promise((resolve) => setTimeout(resolve, delay))}+ } finally {+ if (timer) clearTimeout(timer)}}diff --git a/shared/utils/queue-config.ts b/shared/utils/queue-config.tsnew file mode 100644index 00000000..f42aa0fe--- /dev/null+++ b/shared/utils/queue-config.ts@@ -0,0 +1,14 @@+export const DEFAULT_QUEUE_WORKER_COUNT = 5++export function validateQueueWorkerCount(+ value: unknown,+): asserts value is number {+ if (+ typeof value !== 'number' ||+ !Number.isInteger(value) ||+ value < 1 ||+ value > 8+ ) {+ throw new Error('Queue concurrency must be an integer between 1 and 8')+ }+}