mirror of
https://github.com/DrizzleTime/Foxel.git
synced 2026-05-15 04:17:41 +08:00
feat(storage): add support for Tencent Cloud COS
This commit is contained in:
@@ -24,6 +24,7 @@ public static class ServiceCollectionExtensions
|
||||
services.AddSingleton<LocalStorageProvider>();
|
||||
services.AddSingleton<TelegramStorageProvider>();
|
||||
services.AddSingleton<S3StorageProvider>();
|
||||
services.AddSingleton<CosStorageProvider>();
|
||||
services.AddSingleton<IStorageProviderFactory, StorageProviderFactory>();
|
||||
services.AddSingleton<IDatabaseInitializer, DatabaseInitializer>();
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
<PackageReference Include="Pgvector.EntityFrameworkCore" Version="0.2.2" />
|
||||
<PackageReference Include="Scalar.AspNetCore" Version="2.3.1" />
|
||||
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.8" />
|
||||
<PackageReference Include="Tencent.QCloud.Cos.Sdk" Version="5.4.46" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -10,6 +10,7 @@ public enum StorageType
|
||||
Local = 0,
|
||||
Telegram = 1,
|
||||
S3 = 2,
|
||||
Cos = 3,
|
||||
}
|
||||
|
||||
public class Picture : BaseModel
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
using Foxel.Models.DataBase;
|
||||
using Foxel.Services.Interface;
|
||||
using Foxel.Services.StorageProvider;
|
||||
using Pgvector.EntityFrameworkCore;
|
||||
|
||||
namespace Foxel.Services;
|
||||
|
||||
public class StorageProviderFactory(
|
||||
LocalStorageProvider localStorageProvider,
|
||||
TelegramStorageProvider telegramStorageProvider,
|
||||
CosStorageProvider cosStorageProvider,
|
||||
S3StorageProvider s3StorageProvider) : IStorageProviderFactory
|
||||
{
|
||||
public IStorageProvider GetProvider(StorageType storageType)
|
||||
@@ -16,6 +18,7 @@ public class StorageProviderFactory(
|
||||
StorageType.Local => localStorageProvider,
|
||||
StorageType.Telegram => telegramStorageProvider,
|
||||
StorageType.S3 => s3StorageProvider,
|
||||
StorageType.Cos => cosStorageProvider,
|
||||
_ => throw new ArgumentException($"不支持的存储类型: {storageType}")
|
||||
};
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ import AllImages from '../pages/allImages/Index';
|
||||
import Albums from '../pages/albums/Index';
|
||||
import AlbumDetail from '../pages/albumDetail/Index';
|
||||
import Favorites from '../pages/favorites/Index';
|
||||
import Upload from '../pages/upload/Index';
|
||||
import Settings from '../pages/settings/Index';
|
||||
import BackgroundTasks from '../pages/backgroundTasks/Index';
|
||||
import PixHub from '../pages/pixHub/Index';
|
||||
@@ -111,16 +110,6 @@ const routes: RouteConfig[] = [
|
||||
title: '设置'
|
||||
}
|
||||
},
|
||||
{
|
||||
path: 'upload',
|
||||
key: 'upload',
|
||||
label: '上传',
|
||||
element: <Upload />,
|
||||
hideInMenu: true,
|
||||
breadcrumb: {
|
||||
title: '上传'
|
||||
}
|
||||
},
|
||||
];
|
||||
|
||||
export default routes;
|
||||
|
||||
@@ -85,8 +85,9 @@ const SystemConfig: React.FC = () => {
|
||||
// 存储类型选项
|
||||
const storageOptions = [
|
||||
{ value: 'Local', label: '本地存储', icon: <DatabaseOutlined style={{ color: '#52c41a' }} /> },
|
||||
{ value: 'Telegram', label: 'Telegram存储', icon: <CloudOutlined style={{ color: '#0088cc' }} /> },
|
||||
{ value: 'S3', label: 'S3兼容存储', icon: <CloudServerOutlined style={{ color: '#ff9900' }} /> },
|
||||
{ value: 'Telegram', label: 'Telegram 频道', icon: <CloudOutlined style={{ color: '#0088cc' }} /> },
|
||||
{ value: 'S3', label: '亚马逊 S3', icon: <CloudServerOutlined style={{ color: '#ff9900' }} /> },
|
||||
{ value: 'Cos', label: '腾讯云 COS', icon: <CloudServerOutlined style={{ color: '#00a4ff' }} /> },
|
||||
];
|
||||
|
||||
useEffect(() => {
|
||||
@@ -292,6 +293,30 @@ const SystemConfig: React.FC = () => {
|
||||
isMobile={isMobile}
|
||||
/>
|
||||
)}
|
||||
|
||||
{storageType === 'Cos' && (
|
||||
<ConfigGroup
|
||||
groupName="Storage"
|
||||
configs={{
|
||||
"CosStorageSecretId": configs.Storage?.CosStorageSecretId || '',
|
||||
"CosStorageSecretKey": configs.Storage?.CosStorageSecretKey || '',
|
||||
"CosStorageToken": configs.Storage?.CosStorageToken || '',
|
||||
"CosStorageBucketName": configs.Storage?.CosStorageBucketName || '',
|
||||
"CosStorageRegion": configs.Storage?.CosStorageRegion || '',
|
||||
"CosStorageCdnUrl": configs.Storage?.CosStorageCdnUrl || '',
|
||||
}}
|
||||
onSave={handleSaveConfig}
|
||||
descriptions={{
|
||||
"CosStorageSecretId": '腾讯云COS密钥ID',
|
||||
"CosStorageSecretKey": '腾讯云COS私有密钥',
|
||||
"CosStorageToken": '腾讯云COS临时令牌(可选)',
|
||||
"CosStorageBucketName": 'COS存储桶名称',
|
||||
"CosStorageRegion": 'COS区域 (例如:ap-shanghai)',
|
||||
"CosStorageCdnUrl": 'CDN URL (可选,用于加速文件访问)',
|
||||
}}
|
||||
isMobile={isMobile}
|
||||
/>
|
||||
)}
|
||||
</TabPane>
|
||||
</Tabs>
|
||||
)}
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
import { Typography } from 'antd';
|
||||
|
||||
const { Title } = Typography;
|
||||
|
||||
function Upload() {
|
||||
return (
|
||||
<div>
|
||||
<Title level={2} style={{
|
||||
margin: 0,
|
||||
marginBottom: 20,
|
||||
fontWeight: 600,
|
||||
letterSpacing: '0.5px',
|
||||
fontSize: 32,
|
||||
background: 'linear-gradient(120deg, #000000, #444444)',
|
||||
WebkitBackgroundClip: 'text',
|
||||
WebkitTextFillColor: 'transparent',
|
||||
}}>上传图片</Title>
|
||||
{/* 上传表单 */}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default Upload;
|
||||
Reference in New Issue
Block a user