From f1893579cc9e479843e8e65922e86b6561e000cc Mon Sep 17 00:00:00 2001 From: Marrrrrrrrry <34876935+Marrrrrrrrry@users.noreply.github.com> Date: Fri, 11 Sep 2026 04:09:25 +0800 Subject: [PATCH] fix: read public config contract as snake_case (sync backend D7 follow-up) Drop the allowedFileTypes camel twin from SystemConfig/ConfigState/ config-storage defaults and mapping; send-flow file-type validation reads allowed_file_types only; DEFAULT_CONFIG drops dead keys. --- src/composables/useSendFlow.ts | 2 +- src/composables/useSystemConfig.ts | 3 +-- src/constants/index.ts | 4 +--- src/types/config.ts | 5 +---- src/utils/config-storage.ts | 11 ++++------- 5 files changed, 8 insertions(+), 17 deletions(-) diff --git a/src/composables/useSendFlow.ts b/src/composables/useSendFlow.ts index f122a1c..958bdc4 100644 --- a/src/composables/useSendFlow.ts +++ b/src/composables/useSendFlow.ts @@ -42,7 +42,7 @@ export function useSendFlow() { }) ) const allowedFileTypes = computed(() => { - const types = config.value.allowedFileTypes || config.value.allowed_file_types || ['*'] + const types = config.value.allowed_file_types || ['*'] const normalized = types.map((type) => String(type).trim()).filter(Boolean) return normalized.length > 0 ? normalized : ['*'] }) diff --git a/src/composables/useSystemConfig.ts b/src/composables/useSystemConfig.ts index c5776e7..8e61eb4 100644 --- a/src/composables/useSystemConfig.ts +++ b/src/composables/useSystemConfig.ts @@ -70,7 +70,7 @@ export function useSystemConfig() { const normalizeEditableConfig = (nextConfig: Partial): ConfigState => { const allowedFileTypes = normalizeAllowedFileTypes( - nextConfig.allowed_file_types ?? nextConfig.allowedFileTypes + nextConfig.allowed_file_types ) const codeGenerateType = nextConfig.code_generate_type === 'secret' ? 'secret' : 'number' @@ -78,7 +78,6 @@ export function useSystemConfig() { ...DEFAULT_CONFIG_STATE, ...nextConfig, allowed_file_types: allowedFileTypes, - allowedFileTypes, code_generate_type: codeGenerateType, admin_token: '' } diff --git a/src/constants/index.ts b/src/constants/index.ts index ae2ab41..5dc6351 100644 --- a/src/constants/index.ts +++ b/src/constants/index.ts @@ -94,7 +94,5 @@ export const REGEX_PATTERNS = { export const DEFAULT_CONFIG = { name: 'FileCodeBox', description: '文件传输工具', - maxFileSize: FILE_SIZE_LIMITS.MAX_FILE_SIZE, - allowedFileTypes: ['*'] as string[], - expireDays: 7 + allowed_file_types: ['*'] as string[] } diff --git a/src/types/config.ts b/src/types/config.ts index 1250d10..3f007f0 100644 --- a/src/types/config.ts +++ b/src/types/config.ts @@ -1,9 +1,7 @@ export interface SystemConfig { name: string description?: string - maxFileSize: number - allowedFileTypes: string[] - expireDays: number + allowed_file_types: string[] notify_title?: string notify_content?: string } @@ -43,7 +41,6 @@ export interface ConfigState { open_upload: number upload_size: number allowed_file_types: string[] - allowedFileTypes?: string[] storage_path: string storage_limit: number upload_minute: number diff --git a/src/utils/config-storage.ts b/src/utils/config-storage.ts index 32b7450..024e99d 100644 --- a/src/utils/config-storage.ts +++ b/src/utils/config-storage.ts @@ -26,7 +26,6 @@ type PublicConfigInput = Omit, 'show_admin_addr'> & { export const DEFAULT_PUBLIC_CONFIG: PublicConfig = { ...DEFAULT_CONFIG, upload_size: FILE_SIZE_LIMITS.MAX_FILE_SIZE, - allowedFileTypes: ['*'], allowed_file_types: ['*'], expire_style: ['day'], code_generate_type: 'secret', @@ -51,8 +50,7 @@ export const DEFAULT_CONFIG_STATE: ConfigState = { notify_content: '', open_upload: DEFAULT_PUBLIC_CONFIG.open_upload, upload_size: DEFAULT_PUBLIC_CONFIG.upload_size, - allowed_file_types: DEFAULT_PUBLIC_CONFIG.allowedFileTypes, - allowedFileTypes: DEFAULT_PUBLIC_CONFIG.allowedFileTypes, + allowed_file_types: DEFAULT_PUBLIC_CONFIG.allowed_file_types, storage_path: '', storage_limit: 0, upload_minute: 1, @@ -87,7 +85,7 @@ function normalizeFileTypes(value: unknown): string[] { ? value.split(',') : Array.isArray(value) ? value - : DEFAULT_PUBLIC_CONFIG.allowedFileTypes + : DEFAULT_PUBLIC_CONFIG.allowed_file_types const normalized = rawTypes.map((item) => String(item).trim()).filter(Boolean) return normalized.length > 0 ? normalized : ['*'] } @@ -111,14 +109,13 @@ export function toPublicConfig( ): Partial { if (!config) return {} - const allowedFileTypes = normalizeFileTypes(config.allowedFileTypes ?? config.allowed_file_types) + const allowed_file_types = normalizeFileTypes(config.allowed_file_types) return { name: config.name, description: config.description, upload_size: config.upload_size, - allowedFileTypes, - allowed_file_types: allowedFileTypes, + allowed_file_types, expire_style: config.expire_style, code_generate_type: config.code_generate_type, open_upload: config.open_upload,