伪彩图像解析遮盖
This commit is contained in:
@@ -204,6 +204,8 @@ public interface IOSSService
|
||||
public Task<long> GetObjectSizeAsync(string sourcePath);
|
||||
|
||||
public Task SyncFileAsync(string objectKey, ObjectStoreUse source, ObjectStoreUse destination, CancellationToken ct = default);
|
||||
|
||||
public void ConvertPrefixToStandard(string prefix);
|
||||
}
|
||||
|
||||
|
||||
@@ -215,6 +217,7 @@ public class OSSService(IOptionsMonitor<ObjectStoreServiceOptions> options,
|
||||
private AliyunOSSTempToken AliyunOSSTempToken { get; set; }
|
||||
|
||||
private AWSTempToken AWSTempToken { get; set; }
|
||||
public object result { get; private set; }
|
||||
|
||||
|
||||
|
||||
@@ -652,6 +655,90 @@ public class OSSService(IOptionsMonitor<ObjectStoreServiceOptions> options,
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 将某个路径下的归档的文件 转为标准存储
|
||||
/// </summary>
|
||||
/// <param name="prefix"></param>
|
||||
public void ConvertPrefixToStandard(string prefix)
|
||||
{
|
||||
|
||||
BackBatchGetToken();
|
||||
|
||||
if (ObjectStoreServiceOptions.ObjectStoreUse == "AliyunOSS")
|
||||
{
|
||||
|
||||
var aliConfig = ObjectStoreServiceOptions.AliyunOSS;
|
||||
var _ossClient = new OssClient(
|
||||
RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? aliConfig.EndPoint : aliConfig.InternalEndpoint,
|
||||
AliyunOSSTempToken.AccessKeyId,
|
||||
AliyunOSSTempToken.AccessKeySecret,
|
||||
AliyunOSSTempToken.SecurityToken
|
||||
);
|
||||
var bucketName = aliConfig.BucketName;
|
||||
|
||||
try
|
||||
{
|
||||
ObjectListing objectListing = null;
|
||||
string nextMarker = null;
|
||||
do
|
||||
{
|
||||
// 使用 prefix 模拟目录结构,设置 MaxKeys 和 NextMarker
|
||||
objectListing = _ossClient.ListObjects(new Aliyun.OSS.ListObjectsRequest(bucketName)
|
||||
{
|
||||
Prefix = prefix,
|
||||
MaxKeys = 1000,
|
||||
Marker = nextMarker
|
||||
});
|
||||
|
||||
|
||||
foreach (var obj in objectListing.ObjectSummaries)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 👇 跳过已经是标准存储的(优化)
|
||||
if (obj.StorageClass == StorageClass.Standard.ToString())
|
||||
continue;
|
||||
|
||||
var metadata = new ObjectMetadata();
|
||||
|
||||
// 👇 关键:手动加 Header
|
||||
metadata.AddHeader("x-oss-storage-class", "Standard");
|
||||
|
||||
var copyRequest = new Aliyun.OSS.CopyObjectRequest(bucketName, obj.Key, bucketName, obj.Key) { NewObjectMetadata = metadata };
|
||||
|
||||
|
||||
_ossClient.CopyObject(copyRequest);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Logger.Error($"❌ 失败: {obj.Key}, 错误: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 设置 NextMarker 以获取下一页的数据
|
||||
nextMarker = objectListing.NextMarker;
|
||||
|
||||
} while (objectListing.IsTruncated);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Logger.Error($"Error: {ex.Message}");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else if (ObjectStoreServiceOptions.ObjectStoreUse == "AWS")
|
||||
{
|
||||
throw new BusinessValidationFailedException("未定义的存储介质类型");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 坑方法,会清空之前的规则
|
||||
/// </summary>
|
||||
@@ -1507,20 +1594,20 @@ public class OSSService(IOptionsMonitor<ObjectStoreServiceOptions> options,
|
||||
|
||||
GetObjectStoreTempToken(objectUse: config.Primary);
|
||||
|
||||
await DeleteFromPrefixInternal(config.Primary,prefix, isCache);
|
||||
await DeleteFromPrefixInternal(config.Primary, prefix, isCache);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GetObjectStoreTempToken();
|
||||
|
||||
await DeleteFromPrefixInternal(ObjectStoreServiceOptions.ObjectStoreUse,prefix, isCache);
|
||||
await DeleteFromPrefixInternal(ObjectStoreServiceOptions.ObjectStoreUse, prefix, isCache);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private async Task DeleteFromPrefixInternal(string objectUse ,string prefix, bool isCache = false)
|
||||
private async Task DeleteFromPrefixInternal(string objectUse, string prefix, bool isCache = false)
|
||||
{
|
||||
if (objectUse == "AliyunOSS")
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user