Quellcode durchsuchen

Merge commit 'refs/pull/440/head' of https://gitee.com/zuohuaijun/Admin.NET into next

zuohuaijun vor 3 Jahren
Ursprung
Commit
a04ff7c7a5

+ 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>

+ 19 - 1
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>
@@ -194,6 +194,7 @@ public class SysFileService : IDynamicApiController, ITransient
         var finalName = newFile.Id + suffix; // 文件最终名称
         if (_OSSProviderOptions.IsEnable)
         {
+            newFile.Provider = Enum.GetName(_OSSProviderOptions.Provider);
             var filePath = string.Concat(path, "/", finalName);
             await _OSSService.PutObjectAsync(newFile.BucketName, filePath, file.OpenReadStream());
             //  http://<你的bucket名字>.oss.aliyuncs.com/<你的object名字>
@@ -203,10 +204,15 @@ public class SysFileService : IDynamicApiController, ITransient
                 case OSSProvider.Aliyun:
                     newFile.Url = $"{(_OSSProviderOptions.IsEnableHttps ? "https" : "http")}://{newFile.BucketName}.{_OSSProviderOptions.Endpoint}/{filePath}";
                     break;
+                case OSSProvider.Minio:
+                    //获取Minio文件的下载或者预览地址
+                    newFile.Url = await GetMinioPreviewFileUrl(newFile.BucketName, filePath); ;
+                    break;
             }
         }
         else
         {
+            newFile.Provider = "";//本地存储 Provider 显示为空
             var filePath = Path.Combine(App.WebHostEnvironment.WebRootPath, path);
             if (!Directory.Exists(filePath))
                 Directory.CreateDirectory(filePath);
@@ -232,4 +238,16 @@ public class SysFileService : IDynamicApiController, ITransient
         await _sysFileRep.AsInsertable(newFile).ExecuteCommandAsync();
         return newFile;
     }
+
+    /// <summary>
+    /// 获取Minio文件的下载或者预览地址
+    /// </summary>
+    /// <param name="bucketName">桶名</param>
+    /// <param name="fileName">文件名</param>
+    /// <returns></returns>
+    private async Task<string> GetMinioPreviewFileUrl(String bucketName, String fileName)
+    {
+        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',