From 5c5b63e82f98ab12a5406540a11ce7995f7947ea Mon Sep 17 00:00:00 2001 From: ShiYu Date: Sat, 24 May 2025 00:35:13 +0800 Subject: [PATCH] feat(StorageConfig): enhance storage settings UI with separate configurations for logged-in and anonymous users --- Services/Media/PictureService.cs | 23 +- Web/src/pages/settings/SystemConfig.tsx | 379 ++++++++++++++---------- 2 files changed, 244 insertions(+), 158 deletions(-) diff --git a/Services/Media/PictureService.cs b/Services/Media/PictureService.cs index 8cf8e53..f7477ed 100644 --- a/Services/Media/PictureService.cs +++ b/Services/Media/PictureService.cs @@ -441,15 +441,22 @@ public class PictureService( ImageFormat convertToFormat = ImageFormat.Original, int quality = 95) { - // 如果未指定存储类型,则从配置中获取默认存储类型 - if (storageType == null) + StorageType GetConfigStorageType(string configKey) { - var defaultStorageTypeStr = configuration["Storage:DefaultStorage"]; - if (string.IsNullOrEmpty(defaultStorageTypeStr) || !Enum.TryParse(defaultStorageTypeStr, out var defaultStorageType)) - { - defaultStorageType = StorageType.Local; // 如果配置中没有或解析失败,使用本地存储作为默认 - } - storageType = defaultStorageType; + string? configValue = configuration[configKey]; + return !string.IsNullOrEmpty(configValue) && + Enum.TryParse(configValue, out var configStorageType) + ? configStorageType + : StorageType.Local; + } + + if (userId == null) + { + storageType = GetConfigStorageType("Storage:AnonymousDefaultStorage"); + } + else if (storageType == null) + { + storageType = GetConfigStorageType("Storage:DefaultStorage"); } string originalFileName = fileName; diff --git a/Web/src/pages/settings/SystemConfig.tsx b/Web/src/pages/settings/SystemConfig.tsx index 74a9b25..afb73d1 100644 --- a/Web/src/pages/settings/SystemConfig.tsx +++ b/Web/src/pages/settings/SystemConfig.tsx @@ -190,161 +190,240 @@ const SystemConfig: React.FC = () => { -
- +
- 默认存储: - - -
- -
- +
+ 登录用户默认存储 +
+ +
+ 已登录用户上传文件时的默认存储位置 +
+
+ + {/* 匿名用户默认存储 */} +
+
+ 匿名用户默认存储 +
+ +
+ 未登录用户上传文件时的默认存储位置 +
+
+
+ + + {/* 存储服务配置卡片 */} + +
+
+ 选择要配置的存储服务 +
+ +
+ 选择后将显示对应存储服务的详细配置选项 +
+
+ + {/* 存储服务具体配置 */} +
- 配置存储: - - -
+ {storageType === 'Local' && ( +
+ 本地存储无需额外配置 +
+ )} - {storageType === 'Telegram' && ( - - )} + {storageType === 'Telegram' && ( + + )} - {storageType === 'S3' && ( - - )} + {storageType === 'S3' && ( + + )} - {storageType === 'Cos' && ( - - )} - - {storageType === 'WebDAV' && ( - - )} + {storageType === 'Cos' && ( + + )} + + {storageType === 'WebDAV' && ( + + )} + +
)}