mirror of
https://github.com/DrizzleTime/Foxel.git
synced 2026-09-06 08:07:22 +08:00
feat(StorageConfig): enhance storage settings UI with separate configurations for logged-in and anonymous users
This commit is contained in:
@@ -441,15 +441,22 @@ public class PictureService(
|
|||||||
ImageFormat convertToFormat = ImageFormat.Original,
|
ImageFormat convertToFormat = ImageFormat.Original,
|
||||||
int quality = 95)
|
int quality = 95)
|
||||||
{
|
{
|
||||||
// 如果未指定存储类型,则从配置中获取默认存储类型
|
StorageType GetConfigStorageType(string configKey)
|
||||||
if (storageType == null)
|
|
||||||
{
|
{
|
||||||
var defaultStorageTypeStr = configuration["Storage:DefaultStorage"];
|
string? configValue = configuration[configKey];
|
||||||
if (string.IsNullOrEmpty(defaultStorageTypeStr) || !Enum.TryParse<StorageType>(defaultStorageTypeStr, out var defaultStorageType))
|
return !string.IsNullOrEmpty(configValue) &&
|
||||||
{
|
Enum.TryParse<StorageType>(configValue, out var configStorageType)
|
||||||
defaultStorageType = StorageType.Local; // 如果配置中没有或解析失败,使用本地存储作为默认
|
? configStorageType
|
||||||
|
: StorageType.Local;
|
||||||
}
|
}
|
||||||
storageType = defaultStorageType;
|
|
||||||
|
if (userId == null)
|
||||||
|
{
|
||||||
|
storageType = GetConfigStorageType("Storage:AnonymousDefaultStorage");
|
||||||
|
}
|
||||||
|
else if (storageType == null)
|
||||||
|
{
|
||||||
|
storageType = GetConfigStorageType("Storage:DefaultStorage");
|
||||||
}
|
}
|
||||||
|
|
||||||
string originalFileName = fileName;
|
string originalFileName = fileName;
|
||||||
|
|||||||
@@ -190,28 +190,37 @@ const SystemConfig: React.FC = () => {
|
|||||||
</TabPane>
|
</TabPane>
|
||||||
|
|
||||||
<TabPane tab="存储设置" key="Storage">
|
<TabPane tab="存储设置" key="Storage">
|
||||||
|
{/* 存储类型配置卡片 */}
|
||||||
|
<Card
|
||||||
|
size="small"
|
||||||
|
title="存储类型配置"
|
||||||
|
style={{ marginBottom: isMobile ? 16 : 24 }}
|
||||||
|
bodyStyle={{ padding: isMobile ? '12px' : '16px' }}
|
||||||
|
>
|
||||||
<div style={{
|
<div style={{
|
||||||
marginBottom: isMobile ? 16 : 20,
|
display: 'grid',
|
||||||
display: 'flex',
|
gridTemplateColumns: isMobile ? '1fr' : 'repeat(auto-fit, minmax(300px, 1fr))',
|
||||||
flexDirection: isMobile ? 'column' : 'row',
|
gap: isMobile ? 12 : 16,
|
||||||
alignItems: isMobile ? 'flex-start' : 'center',
|
marginBottom: 0
|
||||||
gap: isMobile ? 8 : 0
|
|
||||||
}}>
|
}}>
|
||||||
<span style={{
|
{/* 登录用户默认存储 */}
|
||||||
marginRight: isMobile ? 0 : 8,
|
<div>
|
||||||
display: 'inline-block',
|
<div style={{
|
||||||
width: isMobile ? 'auto' : 100,
|
marginBottom: 8,
|
||||||
marginBottom: isMobile ? 4 : 0
|
fontSize: 14,
|
||||||
|
fontWeight: 500,
|
||||||
|
color: '#666'
|
||||||
}}>
|
}}>
|
||||||
默认存储:
|
登录用户默认存储
|
||||||
</span>
|
</div>
|
||||||
<Select
|
<Select
|
||||||
value={configs.Storage?.DefaultStorage || 'Local'}
|
value={configs.Storage?.DefaultStorage || 'Local'}
|
||||||
onChange={(value) => {
|
onChange={(value) => {
|
||||||
handleSaveConfig('Storage', 'DefaultStorage', value);
|
handleSaveConfig('Storage', 'DefaultStorage', value);
|
||||||
}}
|
}}
|
||||||
style={{ width: isMobile ? '100%' : 200 }}
|
style={{ width: '100%' }}
|
||||||
size={isMobile ? "middle" : "large"}
|
size="large"
|
||||||
|
placeholder="选择登录用户的默认存储方式"
|
||||||
>
|
>
|
||||||
{storageOptions.map(option => (
|
{storageOptions.map(option => (
|
||||||
<Option key={option.value} value={option.value}>
|
<Option key={option.value} value={option.value}>
|
||||||
@@ -222,30 +231,78 @@ const SystemConfig: React.FC = () => {
|
|||||||
</Option>
|
</Option>
|
||||||
))}
|
))}
|
||||||
</Select>
|
</Select>
|
||||||
|
<div style={{
|
||||||
|
fontSize: 12,
|
||||||
|
color: '#999',
|
||||||
|
marginTop: 4
|
||||||
|
}}>
|
||||||
|
已登录用户上传文件时的默认存储位置
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* 匿名用户默认存储 */}
|
||||||
|
<div>
|
||||||
<div style={{
|
<div style={{
|
||||||
marginBottom: isMobile ? 16 : 20,
|
marginBottom: 8,
|
||||||
display: 'flex',
|
fontSize: 14,
|
||||||
flexDirection: isMobile ? 'column' : 'row',
|
fontWeight: 500,
|
||||||
alignItems: isMobile ? 'flex-start' : 'center',
|
color: '#666'
|
||||||
gap: isMobile ? 8 : 0
|
|
||||||
}}>
|
}}>
|
||||||
<span style={{
|
匿名用户默认存储
|
||||||
marginRight: isMobile ? 0 : 8,
|
</div>
|
||||||
display: 'inline-block',
|
<Select
|
||||||
width: isMobile ? 'auto' : 100,
|
value={configs.Storage?.AnonymousDefaultStorage || 'Local'}
|
||||||
marginBottom: isMobile ? 4 : 0
|
onChange={(value) => {
|
||||||
|
handleSaveConfig('Storage', 'AnonymousDefaultStorage', value);
|
||||||
|
}}
|
||||||
|
style={{ width: '100%' }}
|
||||||
|
size="large"
|
||||||
|
placeholder="选择匿名用户的默认存储方式"
|
||||||
|
>
|
||||||
|
{storageOptions.map(option => (
|
||||||
|
<Option key={option.value} value={option.value}>
|
||||||
|
<div style={{ display: 'flex', alignItems: 'center' }}>
|
||||||
|
{option.icon}
|
||||||
|
<span style={{ marginLeft: 8 }}>{option.label}</span>
|
||||||
|
</div>
|
||||||
|
</Option>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
<div style={{
|
||||||
|
fontSize: 12,
|
||||||
|
color: '#999',
|
||||||
|
marginTop: 4
|
||||||
}}>
|
}}>
|
||||||
配置存储:
|
未登录用户上传文件时的默认存储位置
|
||||||
</span>
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
{/* 存储服务配置卡片 */}
|
||||||
|
<Card
|
||||||
|
size="small"
|
||||||
|
title="存储服务配置"
|
||||||
|
style={{ marginBottom: isMobile ? 16 : 24 }}
|
||||||
|
bodyStyle={{ padding: isMobile ? '12px' : '16px' }}
|
||||||
|
>
|
||||||
|
<div style={{ marginBottom: 16 }}>
|
||||||
|
<div style={{
|
||||||
|
marginBottom: 8,
|
||||||
|
fontSize: 14,
|
||||||
|
fontWeight: 500,
|
||||||
|
color: '#666'
|
||||||
|
}}>
|
||||||
|
选择要配置的存储服务
|
||||||
|
</div>
|
||||||
<Select
|
<Select
|
||||||
value={storageType}
|
value={storageType}
|
||||||
onChange={(value) => {
|
onChange={(value) => {
|
||||||
setStorageType(value);
|
setStorageType(value);
|
||||||
}}
|
}}
|
||||||
style={{ width: isMobile ? '100%' : 200 }}
|
style={{ width: isMobile ? '100%' : '300px' }}
|
||||||
size={isMobile ? "middle" : "large"}
|
size="large"
|
||||||
|
placeholder="选择需要配置的存储服务类型"
|
||||||
>
|
>
|
||||||
{storageOptions.map(option => (
|
{storageOptions.map(option => (
|
||||||
<Option key={option.value} value={option.value}>
|
<Option key={option.value} value={option.value}>
|
||||||
@@ -256,7 +313,27 @@ const SystemConfig: React.FC = () => {
|
|||||||
</Option>
|
</Option>
|
||||||
))}
|
))}
|
||||||
</Select>
|
</Select>
|
||||||
|
<div style={{
|
||||||
|
fontSize: 12,
|
||||||
|
color: '#999',
|
||||||
|
marginTop: 4
|
||||||
|
}}>
|
||||||
|
选择后将显示对应存储服务的详细配置选项
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* 存储服务具体配置 */}
|
||||||
|
<div style={{
|
||||||
|
border: '1px solid #f0f0f0',
|
||||||
|
borderRadius: 6,
|
||||||
|
padding: isMobile ? 12 : 16,
|
||||||
|
backgroundColor: '#fafafa'
|
||||||
|
}}>
|
||||||
|
{storageType === 'Local' && (
|
||||||
|
<div style={{ textAlign: 'center', color: '#999', padding: '20px 0' }}>
|
||||||
|
本地存储无需额外配置
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{storageType === 'Telegram' && (
|
{storageType === 'Telegram' && (
|
||||||
<ConfigGroup
|
<ConfigGroup
|
||||||
@@ -345,6 +422,8 @@ const SystemConfig: React.FC = () => {
|
|||||||
isMobile={isMobile}
|
isMobile={isMobile}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
</TabPane>
|
</TabPane>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Reference in New Issue
Block a user