From e93a1e96e36c2876bcdab50ce6a8729fe21279e6 Mon Sep 17 00:00:00 2001
From: 9kbx <550591004@qq.com>
Date: Fri, 6 Sep 2024 13:52:23 +0800
Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=96=87=E4=BB=B6=E4=B8=8A?=
=?UTF-8?q?=E4=BC=A0=E6=A8=A1=E5=9D=97=EF=BC=9AMinio=E5=A4=96=E9=93=BE?=
=?UTF-8?q?=E6=8B=BC=E6=8E=A5=E5=A2=9E=E5=8A=A0=E8=87=AA=E5=AE=9A=E4=B9=89?=
=?UTF-8?q?=E5=9F=9F=E5=90=8D=EF=BC=8C=E7=94=A8=E4=BA=8E=E6=8B=BC=E6=8E=A5?=
=?UTF-8?q?=E5=A4=96=E9=93=BE=E7=9A=84Host=EF=BC=8C=E7=95=99=E7=A9=BA?=
=?UTF-8?q?=E5=88=99=E4=BD=BF=E7=94=A8Endpoint=E6=8B=BC=E6=8E=A5=E3=80=82?=
=?UTF-8?q?=E7=94=B1=E4=BA=8E=E5=85=AC=E5=8F=B8MinioApi=E5=BF=85=E9=A1=BB?=
=?UTF-8?q?=E7=99=BD=E5=90=8D=E5=8D=95IP=E8=AE=BF=E9=97=AE=EF=BC=8C?=
=?UTF-8?q?=E5=AF=B9=E5=A4=96=E8=AE=BF=E9=97=AE=E6=98=AF=E5=8F=A6=E4=B8=80?=
=?UTF-8?q?=E4=B8=AA=E5=9F=9F=E5=90=8D=E5=B9=B6=E4=B8=94=E5=8F=AA=E8=AE=B8?=
=?UTF-8?q?Get=E8=AF=B7=E6=B1=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Admin.NET/Admin.NET.Application/Configuration/Upload.json | 3 ++-
Admin.NET/Admin.NET.Core/Option/UploadOptions.cs | 6 ++++++
Admin.NET/Admin.NET.Core/Service/File/SysFileService.cs | 5 ++++-
3 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/Admin.NET/Admin.NET.Application/Configuration/Upload.json b/Admin.NET/Admin.NET.Application/Configuration/Upload.json
index 75fea258..5b105d39 100644
--- a/Admin.NET/Admin.NET.Application/Configuration/Upload.json
+++ b/Admin.NET/Admin.NET.Application/Configuration/Upload.json
@@ -16,7 +16,8 @@
"SecretKey": "",
"IsEnableHttps": false, // 是否启用HTTPS
"IsEnableCache": true, // 是否启用缓存
- "Bucket": "admin.net"
+ "Bucket": "admin.net",
+ "CustomHost": "" // 自定义Host,用于拼接外链的Host,留空则使用Endpoint拼接。由于公司MinioApi必须白名单IP访问,对外访问是另一个域名并且只许Get请求
},
"SSHProvider": {
"IsEnable": false,
diff --git a/Admin.NET/Admin.NET.Core/Option/UploadOptions.cs b/Admin.NET/Admin.NET.Core/Option/UploadOptions.cs
index 83615d61..b0b077a6 100644
--- a/Admin.NET/Admin.NET.Core/Option/UploadOptions.cs
+++ b/Admin.NET/Admin.NET.Core/Option/UploadOptions.cs
@@ -50,4 +50,10 @@ public sealed class OSSProviderOptions : OSSOptions, IConfigurableOptions
/// 例:阿里云 1.只能包括小写字母,数字,短横线(-)2.必须以小写字母或者数字开头 3.长度必须在3-63字节之间
///
public string Bucket { get; set; }
+
+ ///
+ /// 自定义Host
+ ///
+ /// 用于拼接外链的Host,留空则使用Endpoint拼接。由于公司MinioApi必须白名单IP访问,对外访问是另一个域名并且只许Get请求
+ public string CustomHost { get; set; }
}
\ No newline at end of file
diff --git a/Admin.NET/Admin.NET.Core/Service/File/SysFileService.cs b/Admin.NET/Admin.NET.Core/Service/File/SysFileService.cs
index f5bc405f..65fdf167 100644
--- a/Admin.NET/Admin.NET.Core/Service/File/SysFileService.cs
+++ b/Admin.NET/Admin.NET.Core/Service/File/SysFileService.cs
@@ -384,7 +384,10 @@ public class SysFileService : IDynamicApiController, ITransient
// 获取Minio文件的下载或者预览地址
// newFile.Url = await GetMinioPreviewFileUrl(newFile.BucketName, filePath);// 这种方法生成的Url是有7天有效期的,不能这样使用
// 需要在MinIO中的Buckets开通对 Anonymous 的readonly权限
- newFile.Url = $"{(_OSSProviderOptions.IsEnableHttps ? "https" : "http")}://{_OSSProviderOptions.Endpoint}/{newFile.BucketName}/{filePath}";
+ var customHost = _OSSProviderOptions.CustomHost;
+ if (string.IsNullOrWhiteSpace(customHost))
+ customHost = _OSSProviderOptions.Endpoint;
+ newFile.Url = $"{(_OSSProviderOptions.IsEnableHttps ? "https" : "http")}://{customHost}/{newFile.BucketName}/{filePath}";
break;
}
}