对接MinIO
	
		
			
	
		
	
	
		
			
				
	
				continuous-integration/drone/push Build is passing
				
					Details
				
			
		
	
				
					
				
			
				
	
				continuous-integration/drone/push Build is passing
				
					Details
				
			
		
	
							parent
							
								
									2ce78f333b
								
							
						
					
					
						commit
						55b72a9156
					
				| 
						 | 
				
			
			@ -206,9 +206,65 @@ namespace IRaCIS.Api.Controllers
 | 
			
		|||
            return ResponseOutput.Ok("/showdicom?studyId=f7b67793-8155-0223-2f15-118f2642efb8&type=Share&token=" + token);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [HttpGet("user/GetObjectStoreToken")]
 | 
			
		||||
        public IResponseOutput GetObjectStoreToken([FromServices] IOptionsMonitor<ObjectStoreServiceOptions> options)
 | 
			
		||||
        {
 | 
			
		||||
            var serviceOption = options.CurrentValue;
 | 
			
		||||
 | 
			
		||||
            if (Enum.TryParse<ObjectStoreUse>(serviceOption.ObjectStoreUse, out var parsedEnum) && parsedEnum == ObjectStoreUse.AliyunOSS)
 | 
			
		||||
            {
 | 
			
		||||
                var ossOptions = serviceOption.AliyunOSS;
 | 
			
		||||
 | 
			
		||||
                IClientProfile profile = DefaultProfile.GetProfile(ossOptions.RegionId, ossOptions.AccessKeyId, ossOptions.AccessKeySecret);
 | 
			
		||||
                DefaultAcsClient client = new DefaultAcsClient(profile);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
                // 创建一个STS请求
 | 
			
		||||
                AssumeRoleRequest request = new AssumeRoleRequest
 | 
			
		||||
                {
 | 
			
		||||
                    RoleArn = ossOptions.RoleArn, // 角色ARN,需要替换为你的角色ARN
 | 
			
		||||
                    RoleSessionName = $"session-name-{NewId.NextGuid()}", // 角色会话名称,可自定义
 | 
			
		||||
                    DurationSeconds = 900, // 令牌有效期(单位:秒),这里设置为1小时
 | 
			
		||||
                };
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
                AssumeRoleResponse response = client.GetAcsResponse(request);
 | 
			
		||||
 | 
			
		||||
                // 返回STS令牌信息给前端
 | 
			
		||||
                var stsToken = new ObjectStoreDTO()
 | 
			
		||||
                {
 | 
			
		||||
                    ObjectStoreUse=serviceOption.ObjectStoreUse,
 | 
			
		||||
                    AliyunOSS=new AliyunOSSTempToken()
 | 
			
		||||
                    {
 | 
			
		||||
                        AccessKeyId = response.Credentials.AccessKeyId,
 | 
			
		||||
                        AccessKeySecret = response.Credentials.AccessKeySecret,
 | 
			
		||||
                        SecurityToken = response.Credentials.SecurityToken,
 | 
			
		||||
                        Expiration = response.Credentials.Expiration,
 | 
			
		||||
 | 
			
		||||
                        Region = ossOptions.Region,
 | 
			
		||||
                        BucketName = ossOptions.BucketName,
 | 
			
		||||
                        ViewEndpoint = ossOptions.ViewEndpoint,
 | 
			
		||||
 | 
			
		||||
                    },
 | 
			
		||||
                    MinIO=serviceOption.MinIO
 | 
			
		||||
                }
 | 
			
		||||
               ;
 | 
			
		||||
 | 
			
		||||
                return ResponseOutput.Ok(stsToken);
 | 
			
		||||
            }
 | 
			
		||||
            else if(Enum.TryParse<ObjectStoreUse>(serviceOption.ObjectStoreUse, out var parsedValue) && parsedValue == ObjectStoreUse.MinIO)
 | 
			
		||||
            {
 | 
			
		||||
                return ResponseOutput.Ok(new ObjectStoreDTO() { ObjectStoreUse=serviceOption.ObjectStoreUse,MinIO=serviceOption.MinIO});
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                return ResponseOutput.Ok(new ObjectStoreDTO() { ObjectStoreUse = serviceOption.ObjectStoreUse, MinIO = serviceOption.MinIO });
 | 
			
		||||
            }
 | 
			
		||||
                   
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
            [HttpGet("user/GenerateSTS")]
 | 
			
		||||
        public IResponseOutput GenerateSTS([FromServices]IOptionsMonitor<AliyunOssOptions> options )
 | 
			
		||||
        public IResponseOutput GenerateSTS([FromServices]IOptionsMonitor<AliyunOSSOptions> options )
 | 
			
		||||
        {
 | 
			
		||||
            var ossOptions = options.CurrentValue;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -93,7 +93,8 @@ namespace IRaCIS.Core.API
 | 
			
		|||
 | 
			
		||||
            services.AddOptions().Configure<SystemEmailSendConfig>( _configuration.GetSection("SystemEmailSendConfig"));
 | 
			
		||||
            services.AddOptions().Configure<ServiceVerifyConfigOption>(_configuration.GetSection("BasicSystemConfig"));
 | 
			
		||||
            services.AddOptions().Configure<AliyunOssOptions>(_configuration.GetSection("AliyunOSS"));
 | 
			
		||||
            services.AddOptions().Configure<AliyunOSSOptions>(_configuration.GetSection("AliyunOSS"));
 | 
			
		||||
            services.AddOptions().Configure<ObjectStoreServiceOptions>(_configuration.GetSection("ObjectStoreService"));
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            //动态WebApi + UnifiedApiResultFilter  省掉控制器代码
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -12,6 +12,31 @@
 | 
			
		|||
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
  "ObjectStoreService": {
 | 
			
		||||
 | 
			
		||||
    "ObjectStoreUse": "AliyunOSS",
 | 
			
		||||
 | 
			
		||||
    "AliyunOSS": {
 | 
			
		||||
      "RegionId": "cn-shanghai",
 | 
			
		||||
      "Endpoint": "https://oss-cn-shanghai.aliyuncs.com",
 | 
			
		||||
      "AccessKeyId": "LTAI5tKvzs7ed3UfSpNk3xwQ",
 | 
			
		||||
      "AccessKeySecret": "zTIceGEShlZDGnLrCFfIGFE7TXVRio",
 | 
			
		||||
      "BucketName": "zyypacs",
 | 
			
		||||
      "RoleArn": "acs:ram::1899121822495495:role/oss-upload",
 | 
			
		||||
      "ViewEndpoint": "https://zyypacs.oss-cn-shanghai.aliyuncs.com",
 | 
			
		||||
      "Region": "oss-cn-shanghai"
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    "MinIO": {
 | 
			
		||||
      "Endpoint": "http://192.168.3.68",
 | 
			
		||||
      "Port": "8001",
 | 
			
		||||
      "UseSSL": false,
 | 
			
		||||
      "AccessKey": "IDFkwEpWej0b4DtiuThL",
 | 
			
		||||
      "SecretKey": "Lhuu83yMhVwu7c1SnjvGY6lq74jzpYqifK6Qtj4h",
 | 
			
		||||
      "BucketName": "test"
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
  "AliyunOSS": {
 | 
			
		||||
    "RegionId": "cn-shanghai",
 | 
			
		||||
    "Endpoint": "https://oss-cn-shanghai.aliyuncs.com",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -14,8 +14,17 @@ using System.Threading.Tasks;
 | 
			
		|||
 | 
			
		||||
namespace IRaCIS.Core.Application.Helper
 | 
			
		||||
{
 | 
			
		||||
    public class MinIOOptions
 | 
			
		||||
    {
 | 
			
		||||
        public string Endpoint { get; set; }
 | 
			
		||||
        public string Port { get; set; }
 | 
			
		||||
        public bool UseSSL { get; set; }
 | 
			
		||||
        public string AccessKey { get; set; }
 | 
			
		||||
        public string SecretKey { get; set; }
 | 
			
		||||
        public string BucketName { get; set; }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public class AliyunOssOptions
 | 
			
		||||
    public class AliyunOSSOptions
 | 
			
		||||
    {
 | 
			
		||||
        public string RegionId { get; set; }
 | 
			
		||||
        public string AccessKeyId { get; set; }
 | 
			
		||||
| 
						 | 
				
			
			@ -23,15 +32,56 @@ namespace IRaCIS.Core.Application.Helper
 | 
			
		|||
        public string EndPoint { get; set; }
 | 
			
		||||
        public string BucketName { get; set; }
 | 
			
		||||
 | 
			
		||||
        public string RoleArn { get;set; }
 | 
			
		||||
        public string RoleArn { get; set; }
 | 
			
		||||
 | 
			
		||||
        public string Region { get; set; }
 | 
			
		||||
 | 
			
		||||
        public string ViewEndpoint { get; set; }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public class ObjectStoreServiceOptions
 | 
			
		||||
    {
 | 
			
		||||
        public string ObjectStoreUse { get; set; }
 | 
			
		||||
        public AliyunOSSOptions AliyunOSS { get; set; }
 | 
			
		||||
        public MinIOOptions MinIO { get; set; }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public class ObjectStoreDTO
 | 
			
		||||
    {
 | 
			
		||||
        public string ObjectStoreUse { get; set; }
 | 
			
		||||
        public AliyunOSSTempToken AliyunOSS { get; set; }
 | 
			
		||||
 | 
			
		||||
        public MinIOOptions MinIO { get; set; }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public class AliyunOSSTempToken
 | 
			
		||||
    {
 | 
			
		||||
        public string AccessKeyId { get; set; }
 | 
			
		||||
        public string AccessKeySecret { get; set; }
 | 
			
		||||
        public string SecurityToken { get; set; }
 | 
			
		||||
        public string Expiration { get; set; }
 | 
			
		||||
 | 
			
		||||
        public string Region { get; set; }
 | 
			
		||||
        public string BucketName { get; set; }
 | 
			
		||||
        public string ViewEndpoint { get; set; }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public enum ObjectStoreUse
 | 
			
		||||
    {
 | 
			
		||||
        AliyunOSS = 0,
 | 
			
		||||
        MinIO = 1,
 | 
			
		||||
        AWS = 2,
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public interface IOSSService
 | 
			
		||||
    {
 | 
			
		||||
| 
						 | 
				
			
			@ -41,29 +91,17 @@ namespace IRaCIS.Core.Application.Helper
 | 
			
		|||
    public class OSSService : IOSSService
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
        public AliyunOssOptions _OSSConfig { get; set; }
 | 
			
		||||
        public AliyunOSSOptions _OSSConfig { get; set; }
 | 
			
		||||
 | 
			
		||||
        public OssClient _ossClient { get; set; }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        public OSSService(IOptionsMonitor<AliyunOssOptions> options)
 | 
			
		||||
        public OSSService(IOptionsMonitor<AliyunOSSOptions> options)
 | 
			
		||||
        {
 | 
			
		||||
            var ossOptions = options.CurrentValue;
 | 
			
		||||
 | 
			
		||||
            _OSSConfig= ossOptions;
 | 
			
		||||
 | 
			
		||||
            //_OSSConfig = new AliyunOssOptions()
 | 
			
		||||
            //{
 | 
			
		||||
            //    RegionId = ossOptions.RegionId,
 | 
			
		||||
            //    AccessKeyId = ossOptions.AccessKeyId,
 | 
			
		||||
            //    AccessKeySecret = ossOptions.AccessKeySecret,
 | 
			
		||||
            //    EndPoint = ossOptions.EndPoint,
 | 
			
		||||
            //    BucketName = ossOptions.BucketName,
 | 
			
		||||
            //    RoleArn = ossOptions.RoleArn,
 | 
			
		||||
            //    Region = ossOptions.Region,
 | 
			
		||||
            //    ViewEndpoint = ossOptions.ViewEndpoint
 | 
			
		||||
            //};
 | 
			
		||||
            _OSSConfig = ossOptions;
 | 
			
		||||
 | 
			
		||||
            _ossClient = new OssClient(_OSSConfig.EndPoint, _OSSConfig.AccessKeyId, _OSSConfig.AccessKeySecret);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -89,6 +89,7 @@
 | 
			
		|||
		<PackageReference Include="MediatR" Version="12.1.1" />
 | 
			
		||||
		<PackageReference Include="MimeKit" Version="4.2.0" />
 | 
			
		||||
		<PackageReference Include="MiniExcel" Version="1.31.2" />
 | 
			
		||||
		<PackageReference Include="Minio" Version="6.0.1" />
 | 
			
		||||
		<PackageReference Include="MiniWord" Version="0.7.0" />
 | 
			
		||||
		<PackageReference Include="My.Extensions.Localization.Json" Version="3.0.0">
 | 
			
		||||
		  <TreatAsUsed>true</TreatAsUsed>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,6 @@
 | 
			
		|||
using BeetleX.BNR;
 | 
			
		||||
using BeetleX;
 | 
			
		||||
using BeetleX.BNR;
 | 
			
		||||
using IRaCIS.Core.Application.Helper;
 | 
			
		||||
using IRaCIS.Core.Application.Service;
 | 
			
		||||
using IRaCIS.Core.Application.ViewModel;
 | 
			
		||||
using IRaCIS.Core.Domain.Share;
 | 
			
		||||
| 
						 | 
				
			
			@ -12,6 +14,8 @@ using Microsoft.Extensions.Caching.Distributed;
 | 
			
		|||
using Microsoft.Extensions.Logging;
 | 
			
		||||
using Microsoft.Extensions.Options;
 | 
			
		||||
using MiniExcelLibs;
 | 
			
		||||
using Minio;
 | 
			
		||||
using NPOI.POIFS.Crypt;
 | 
			
		||||
using System.Linq.Expressions;
 | 
			
		||||
using System.Reflection.Metadata;
 | 
			
		||||
using System.Security.Cryptography;
 | 
			
		||||
| 
						 | 
				
			
			@ -58,7 +62,22 @@ namespace IRaCIS.Application.Services
 | 
			
		|||
            //_cache = cache;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [AllowAnonymous]
 | 
			
		||||
        public async Task<IResponseOutput> TestMinIO([FromServices] IOptionsMonitor<ObjectStoreServiceOptions> options)
 | 
			
		||||
        {
 | 
			
		||||
 | 
			
		||||
            var minIO = options.CurrentValue.MinIO;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            var minioClient = new MinioClient().WithEndpoint($"{minIO.Endpoint}:{minIO.Port}")
 | 
			
		||||
                .WithCredentials(minIO.AccessKey,minIO.SecretKey)
 | 
			
		||||
                .Build();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            return ResponseOutput.Ok(options);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [AllowAnonymous]
 | 
			
		||||
        public async Task<IResponseOutput> TestDistributedLock( )
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue