瀏覽代碼

规范OSS文件管理,统一配置

Signed-off-by: rqc <rqiancheng@qq.com>
rqc 3 年之前
父節點
當前提交
7b924c2b6a

+ 2 - 3
Admin.NET/Admin.NET.Core/AdminNETConfig.json

@@ -87,15 +87,14 @@
     },
     "OSSProvider": {
         "IsEnable": false,
-        "Provider": 2, // 0.Invalid/1.Minio/2.Aliyun/3.QCloud/4.Qiniu/5.HuaweiCloud
+        "Provider": "Aliyun", // Invalid/Minio/Aliyun/QCloud/Qiniu/HuaweiCloud
         "Endpoint": "",
         "Region": "",
         "AccessKey": "",
         "SecretKey": "",
         "IsEnableHttps": true,
         "IsEnableCache": true,
-        "Bucket": "",
-        "ProviderName": "Aliyun"
+        "Bucket": ""
     },
     "Email": {
         "Server": "smtp.163.com", // 主机

+ 8 - 1
Admin.NET/Admin.NET.Core/Entity/SysFile.cs

@@ -1,4 +1,4 @@
-namespace Admin.NET.Core;
+namespace Admin.NET.Core;
 
 /// <summary>
 /// 系统文件表
@@ -6,6 +6,13 @@
 [SugarTable("sys_file", "系统文件表")]
 public class SysFile : EntityBase
 {
+    /// <summary>
+    /// 提供者
+    /// </summary>
+    [SugarColumn(ColumnDescription = "提供者", Length = 128)]
+    [MaxLength(128)]
+    public string Provider { get; set; }
+
     /// <summary>
     /// 仓储名称
     /// </summary>

+ 1 - 6
Admin.NET/Admin.NET.Core/Option/OSSProviderOptions.cs

@@ -1,4 +1,4 @@
-using OnceMi.AspNetCore.OSS;
+using OnceMi.AspNetCore.OSS;
 
 namespace Admin.NET.Core;
 
@@ -17,9 +17,4 @@ public sealed class OSSProviderOptions : OSSOptions, IConfigurableOptions
     /// 例:阿里云 1.只能包括小写字母,数字,短横线(-)2.必须以小写字母或者数字开头 3.长度必须在3-63字节之间
     /// </summary>
     public string Bucket { get; set; }
-
-    /// <summary>
-    /// 对象存储名称
-    /// </summary>
-    public string ProviderName { get; set; }
 }

+ 6 - 1
Admin.NET/Admin.NET.Core/Service/File/Dto/FileOutput.cs

@@ -1,4 +1,4 @@
-namespace Admin.NET.Core.Service;
+namespace Admin.NET.Core.Service;
 
 public class FileOutput
 {
@@ -7,6 +7,11 @@ public class FileOutput
     /// </summary>
     public long Id { get; set; }
 
+    /// <summary>
+    /// 提供者
+    /// </summary>
+    public string Provider { get; set; }
+    
     /// <summary>
     /// 名称
     /// </summary>

+ 3 - 2
Admin.NET/Admin.NET.Core/Service/File/SysFileService.cs

@@ -26,7 +26,7 @@ public class SysFileService : IDynamicApiController, ITransient
         _uploadOptions = uploadOptions.Value;
         _commonService = commonService;
         if (_OSSProviderOptions.IsEnable)
-            _OSSService = ossServiceFactory.Create(_OSSProviderOptions.ProviderName);
+            _OSSService = ossServiceFactory.Create(Enum.GetName(_OSSProviderOptions.Provider));
     }
 
     /// <summary>
@@ -181,6 +181,7 @@ public class SysFileService : IDynamicApiController, ITransient
         var newFile = new SysFile
         {
             Id = Yitter.IdGenerator.YitIdHelper.NextId(),
+            Provider = Enum.GetName(_OSSProviderOptions.Provider),
             // BucketName = _OSSProviderOptions.IsEnable ? _OSSProviderOptions.Provider.ToString() : "Local",
             // 阿里云对bucket名称有要求,1.只能包括小写字母,数字,短横线(-)2.必须以小写字母或者数字开头  3.长度必须在3-63字节之间
             // 无法使用Provider
@@ -237,7 +238,6 @@ public class SysFileService : IDynamicApiController, ITransient
         return newFile;
     }
 
-    
     /// <summary>
     /// 获取Minio文件的下载或者预览地址
     /// </summary>
@@ -248,4 +248,5 @@ public class SysFileService : IDynamicApiController, ITransient
     {
         return await _OSSService.PresignedGetObjectAsync(bucketName, fileName,7);
     }
+
 }

+ 2 - 2
Admin.NET/Admin.NET.Web.Core/Startup.cs

@@ -1,4 +1,4 @@
-using Admin.NET.Core;
+using Admin.NET.Core;
 using AspNetCoreRateLimit;
 using Furion;
 using Furion.SpecificationDocument;
@@ -99,7 +99,7 @@ public class Startup : AppStartup
 
         // OSS对象存储(必须一个个赋值)
         var ossOpt = App.GetOptions<OSSProviderOptions>();
-        services.AddOSSService(ossOpt.ProviderName, options =>
+        services.AddOSSService(Enum.GetName(ossOpt.Provider), options =>
         {
             options.Provider = ossOpt.Provider;
             options.Endpoint = ossOpt.Endpoint;

+ 6 - 0
Vben2/src/views/sys/admin/file/file.data.ts

@@ -6,6 +6,12 @@ import { useGlobSetting } from '/@/hooks/setting';
 
 const { uploadUrl = '' } = useGlobSetting();
 export const columns: BasicColumn[] = [
+  {
+    title: '提供者',
+    dataIndex: 'provider',
+    width: 100,
+    align: 'left',
+  },
   {
     title: '仓储名称',
     dataIndex: 'bucketName',