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.

feat: make upload file size limit configurable via settings panel (#255)

Copilotf4175f220d4b
diff --git a/app/pages/dashboard/photos.vue b/app/pages/dashboard/photos.vue
index 0ebfda35..c1746f75 100644
--- a/app/pages/dashboard/photos.vue
+++ b/app/pages/dashboard/photos.vue
@@ -33,7 +33,10 @@ useHead({
title: $t('title.photos'),
})
-const MAX_FILE_SIZE = 256 // in MB
+const maxFileSizeMB = computed(() => {
+ const val = getSetting('app:upload.maxFileSize')
+ return typeof val === 'number' ? val : 256
+})
const dayjs = useDayjs()
@@ -1005,13 +1008,13 @@ const validateFile = (file: File): { valid: boolean; error?: string } => {
}
}
- const maxSize = MAX_FILE_SIZE * 1024 * 1024
+ const maxSize = maxFileSizeMB.value * 1024 * 1024
if (file.size > maxSize) {
return {
valid: false,
error: $t('dashboard.photos.errors.fileTooLarge', {
size: (file.size / 1024 / 1024).toFixed(2),
- maxSize: MAX_FILE_SIZE,
+ maxSize: maxFileSizeMB.value,
}),
}
}
@@ -1852,7 +1855,7 @@ onUnmounted(() => {
>
{{
$t('dashboard.photos.maxFileSize', {
- size: MAX_FILE_SIZE,
+ size: maxFileSizeMB,
})
}}
</UBadge>
@@ -1901,7 +1904,7 @@ onUnmounted(() => {
:label="$t('dashboard.photos.uploader.label')"
:description="
$t('dashboard.photos.uploader.description', {
- maxSize: MAX_FILE_SIZE,
+ maxSize: maxFileSizeMB,
})
"
icon="tabler:cloud-upload"
diff --git a/i18n/locales/en.json b/i18n/locales/en.json
index 5d994348..541b4297 100644
--- a/i18n/locales/en.json
+++ b/i18n/locales/en.json
@@ -895,6 +895,13 @@
"dark": "Dark",
"system": "System"
}
+ },
+ "upload": {
+ "maxFileSize": {
+ "label": "Max Upload File Size",
+ "description": "Maximum size of a single uploaded file (MB)",
+ "help": "Takes effect immediately and applies to all users"
+ }
}
},
"map": {
@@ -1062,10 +1069,18 @@
},
"wizard": {
"admin": {
- "username": { "label": "Username" },
- "email": { "label": "Email" },
- "password": { "label": "Password" },
- "confirmPassword": { "label": "Confirm Password" }
+ "username": {
+ "label": "Username"
+ },
+ "email": {
+ "label": "Email"
+ },
+ "password": {
+ "label": "Password"
+ },
+ "confirmPassword": {
+ "label": "Confirm Password"
+ }
},
"map": {
"provider": {
@@ -1080,4 +1095,4 @@
}
}
}
-}
+}
\ No newline at end of file
diff --git a/i18n/locales/ja.json b/i18n/locales/ja.json
index 1ade6d3c..6db1d5a0 100644
--- a/i18n/locales/ja.json
+++ b/i18n/locales/ja.json
@@ -838,6 +838,13 @@
"dark": "ダーク",
"system": "システム"
}
+ },
+ "upload": {
+ "maxFileSize": {
+ "label": "アップロードファイルの最大サイズ",
+ "description": "アップロード可能な単一ファイルの最大サイズ(MB)",
+ "help": "設定後すぐに反映され、全ユーザーのファイルアップロードに適用されます"
+ }
}
},
"map": {
@@ -1005,10 +1012,18 @@
},
"wizard": {
"admin": {
- "username": { "label": "ユーザー名" },
- "email": { "label": "メールアドレス" },
- "password": { "label": "パスワード" },
- "confirmPassword": { "label": "パスワード(確認)" }
+ "username": {
+ "label": "ユーザー名"
+ },
+ "email": {
+ "label": "メールアドレス"
+ },
+ "password": {
+ "label": "パスワード"
+ },
+ "confirmPassword": {
+ "label": "パスワード(確認)"
+ }
},
"map": {
"provider": {
@@ -1023,4 +1038,4 @@
}
}
}
-}
+}
\ No newline at end of file
diff --git a/i18n/locales/zh-Hans.json b/i18n/locales/zh-Hans.json
index 7557ccba..74cc6ee3 100644
--- a/i18n/locales/zh-Hans.json
+++ b/i18n/locales/zh-Hans.json
@@ -897,6 +897,13 @@
"dark": "深色",
"system": "系统"
}
+ },
+ "upload": {
+ "maxFileSize": {
+ "label": "最大上传文件大小",
+ "description": "允许上传的单个文件最大大小(MB)",
+ "help": "设置后将立即生效,影响所有用户的文件上传操作"
+ }
}
},
"map": {
@@ -1064,10 +1071,18 @@
},
"wizard": {
"admin": {
- "username": { "label": "用户名" },
- "email": { "label": "电子邮箱" },
- "password": { "label": "密码" },
- "confirmPassword": { "label": "确认密码" }
+ "username": {
+ "label": "用户名"
+ },
+ "email": {
+ "label": "电子邮箱"
+ },
+ "password": {
+ "label": "密码"
+ },
+ "confirmPassword": {
+ "label": "确认密码"
+ }
},
"map": {
"provider": {
@@ -1082,4 +1097,4 @@
}
}
}
-}
+}
\ No newline at end of file
diff --git a/i18n/locales/zh-Hant-HK.json b/i18n/locales/zh-Hant-HK.json
index 363487b5..76985c13 100644
--- a/i18n/locales/zh-Hant-HK.json
+++ b/i18n/locales/zh-Hant-HK.json
@@ -838,6 +838,13 @@
"dark": "深色",
"system": "系統"
}
+ },
+ "upload": {
+ "maxFileSize": {
+ "label": "最大上傳檔案大小",
+ "description": "允許上傳的單一檔案最大大小(MB)",
+ "help": "設定後立即生效,影響所有用戶的檔案上傳操作"
+ }
}
},
"map": {
@@ -1005,10 +1012,18 @@
},
"wizard": {
"admin": {
- "username": { "label": "用戶名" },
- "email": { "label": "電子郵箱" },
- "password": { "label": "密碼" },
- "confirmPassword": { "label": "確認密碼" }
+ "username": {
+ "label": "用戶名"
+ },
+ "email": {
+ "label": "電子郵箱"
+ },
+ "password": {
+ "label": "密碼"
+ },
+ "confirmPassword": {
+ "label": "確認密碼"
+ }
},
"map": {
"provider": {
@@ -1023,4 +1038,4 @@
}
}
}
-}
+}
\ No newline at end of file
diff --git a/i18n/locales/zh-Hant-TW.json b/i18n/locales/zh-Hant-TW.json
index 81dd5be8..6e77596f 100644
--- a/i18n/locales/zh-Hant-TW.json
+++ b/i18n/locales/zh-Hant-TW.json
@@ -838,6 +838,13 @@
"dark": "深色",
"system": "系統"
}
+ },
+ "upload": {
+ "maxFileSize": {
+ "label": "最大上傳檔案大小",
+ "description": "允許上傳的單一檔案最大大小(MB)",
+ "help": "設定後立即生效,影響所有使用者的檔案上傳操作"
+ }
}
},
"map": {
@@ -1005,10 +1012,18 @@
},
"wizard": {
"admin": {
- "username": { "label": "使用者名稱" },
- "email": { "label": "電子郵件" },
- "password": { "label": "密碼" },
- "confirmPassword": { "label": "確認密碼" }
+ "username": {
+ "label": "使用者名稱"
+ },
+ "email": {
+ "label": "電子郵件"
+ },
+ "password": {
+ "label": "密碼"
+ },
+ "confirmPassword": {
+ "label": "確認密碼"
+ }
},
"map": {
"provider": {
@@ -1023,4 +1038,4 @@
}
}
}
-}
+}
\ No newline at end of file
diff --git a/server/api/photos/upload.put.ts b/server/api/photos/upload.put.ts
index 7ac369b6..fd071448 100644
--- a/server/api/photos/upload.put.ts
+++ b/server/api/photos/upload.put.ts
@@ -1,5 +1,6 @@
import { useStorageProvider } from '~~/server/utils/useStorageProvider'
import { logger } from '~~/server/utils/logger'
+import { settingsManager } from '~~/server/services/settings/settingsManager'
export default eventHandler(async (event) => {
await requireUserSession(event)
@@ -63,8 +64,10 @@ export default eventHandler(async (event) => {
})
}
- // 简单大小限制(例如 128MB)
- const maxBytes = 128 * 1024 * 1024
+ // 简单大小限制(从设置中读取,默认 256MB)
+ const maxFileSizeMB =
+ (await settingsManager.get<number>('app', 'upload.maxFileSize')) ?? 256
+ const maxBytes = maxFileSizeMB * 1024 * 1024
if (raw.byteLength > maxBytes) {
const sizeInMB = (raw.byteLength / 1024 / 1024).toFixed(2)
throw createError({
@@ -73,7 +76,9 @@ export default eventHandler(async (event) => {
data: {
title: t('upload.error.tooLarge.title'),
message: t('upload.error.tooLarge.message', { size: sizeInMB }),
- suggestion: t('upload.error.tooLarge.suggestion', { maxSize: 128 }),
+ suggestion: t('upload.error.tooLarge.suggestion', {
+ maxSize: maxFileSizeMB,
+ }),
},
})
}
diff --git a/server/services/settings/contants.ts b/server/services/settings/contants.ts
index 7b88dba6..69dc54c7 100644
--- a/server/services/settings/contants.ts
+++ b/server/services/settings/contants.ts
@@ -63,6 +63,15 @@ export const DEFAULT_SETTINGS = [
description: 'settings.app.appearance.theme.description',
isPublic: true,
},
+ {
+ namespace: 'app',
+ key: 'upload.maxFileSize',
+ type: 'number',
+ defaultValue: 256,
+ label: 'settings.app.upload.maxFileSize.label',
+ description: 'settings.app.upload.maxFileSize.description',
+ isPublic: true,
+ },
// NAMESPACE: map
{
namespace: 'map',
diff --git a/server/services/settings/ui-config.ts b/server/services/settings/ui-config.ts
index ec0f888a..f36ef485 100644
--- a/server/services/settings/ui-config.ts
+++ b/server/services/settings/ui-config.ts
@@ -29,6 +29,12 @@ export const APP_SETTINGS_UI: Record<string, FieldUIConfig> = {
placeholder: 'https://example.com/avatar.jpg',
help: 'settings.app.avatarUrl.help',
},
+ 'upload.maxFileSize': {
+ type: 'number',
+ help: 'settings.app.upload.maxFileSize.help',
+ min: 1,
+ max: 10240,
+ },
'appearance.theme': {
type: 'tabs',
options: [
diff --git a/shared/types/settings.ts b/shared/types/settings.ts
index e4892eb6..27e90471 100644
--- a/shared/types/settings.ts
+++ b/shared/types/settings.ts
@@ -68,6 +68,8 @@ export interface FieldUIConfig {
required?: boolean
minLength?: number
maxLength?: number
+ min?: number // 最小值(用于 number 类型)
+ max?: number // 最大值(用于 number 类型)
pattern?: string // 正则表达式
// 样式和尺寸