Merge branch 'Test_IRC_Net8' of https://gitea.frp.extimaging.com/XCKJ/irc-netcore-api into Test_IRC_Net8
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
commit
199f7060fa
|
@ -145,6 +145,8 @@ public interface IOSSService
|
|||
|
||||
public Task DeleteFromPrefix(string prefix);
|
||||
|
||||
List<string> GetRootFolderNames();
|
||||
|
||||
public ObjectStoreDTO GetObjectStoreTempToken();
|
||||
}
|
||||
|
||||
|
@ -526,6 +528,55 @@ public class OSSService : IOSSService
|
|||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有根目录名称
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<string> GetRootFolderNames()
|
||||
{
|
||||
GetObjectStoreTempToken();
|
||||
var aliConfig = ObjectStoreServiceOptions.AliyunOSS;
|
||||
var _ossClient = new OssClient(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? aliConfig.EndPoint : aliConfig.InternalEndpoint,
|
||||
AliyunOSSTempToken.AccessKeyId,
|
||||
AliyunOSSTempToken.AccessKeySecret,
|
||||
AliyunOSSTempToken.SecurityToken);
|
||||
|
||||
List<string> rootFolders = new List<string>();
|
||||
string nextMarker = null;
|
||||
|
||||
try
|
||||
{
|
||||
ObjectListing objectListing = null;
|
||||
do
|
||||
{
|
||||
// 列出根目录下的对象和文件夹
|
||||
objectListing = _ossClient.ListObjects(new Aliyun.OSS.ListObjectsRequest(aliConfig.BucketName)
|
||||
{
|
||||
|
||||
MaxKeys = 1000,
|
||||
Marker = nextMarker,
|
||||
Delimiter = "/" // 使用分隔符来模拟文件夹
|
||||
});
|
||||
|
||||
// 遍历 CommonPrefixes 获取根文件夹名称
|
||||
foreach (var prefix in objectListing.CommonPrefixes)
|
||||
{
|
||||
rootFolders.Add(prefix.TrimEnd('/')); // 去掉末尾的斜杠
|
||||
}
|
||||
|
||||
// 设置 NextMarker 以获取下一页的数据
|
||||
nextMarker = objectListing.NextMarker;
|
||||
|
||||
} while (objectListing.IsTruncated);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Error: {ex.Message}");
|
||||
}
|
||||
|
||||
return rootFolders;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除某个目录的文件
|
||||
/// </summary>
|
||||
|
|
|
@ -12977,6 +12977,12 @@
|
|||
<param name="trialId"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IRaCIS.Core.Application.Service.TrialService.DeleteFolder">
|
||||
<summary>
|
||||
删除脏文件夹
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IRaCIS.Core.Application.Service.TrialService.DeleteTrial(System.Guid,IRaCIS.Core.Infra.EFCore.IRepository)">
|
||||
<summary> 真删除项目 方便清理测试数据 </summary>
|
||||
<param name="trialId">临床试验项目Id</param>
|
||||
|
@ -13324,6 +13330,12 @@
|
|||
<returns></returns>
|
||||
<exception cref="T:IRaCIS.Core.Infrastructure.BusinessValidationFailedException"></exception>
|
||||
</member>
|
||||
<member name="M:IRaCIS.Core.Application.Helper.OSSService.GetRootFolderNames">
|
||||
<summary>
|
||||
获取所有根目录名称
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IRaCIS.Core.Application.Helper.OSSService.DeleteFromPrefix(System.String)">
|
||||
<summary>
|
||||
删除某个目录的文件
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
using IRaCIS.Application.Contracts;
|
||||
using DocumentFormat.OpenXml.Office2010.ExcelAc;
|
||||
using IRaCIS.Application.Contracts;
|
||||
using IRaCIS.Application.Interfaces;
|
||||
using IRaCIS.Core.Application.Filter;
|
||||
using IRaCIS.Core.Application.Helper;
|
||||
using IRaCIS.Core.Domain.Models;
|
||||
using IRaCIS.Core.Domain.Share;
|
||||
using IRaCIS.Core.Infrastructure;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
@ -432,6 +434,23 @@ namespace IRaCIS.Core.Application.Service
|
|||
return ResponseOutput.Ok();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除OSS脏文件夹
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task DeleteOSSFolder()
|
||||
{
|
||||
List<Guid> trialids = await _trialRepository.Select(x => x.Id).ToListAsync();
|
||||
List<string> path= _oSSService.GetRootFolderNames();
|
||||
foreach (var item in path)
|
||||
{
|
||||
if (Guid.TryParse(item, out Guid folderId) && !trialids.Contains(folderId))
|
||||
{
|
||||
await _oSSService.DeleteFromPrefix(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary> 真删除项目 方便清理测试数据 </summary>
|
||||
/// <param name="trialId">临床试验项目Id</param>
|
||||
[AllowAnonymous]
|
||||
|
|
Loading…
Reference in New Issue