Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed the loading issue of nuget packages #185

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
189 changes: 0 additions & 189 deletions src/BaGetter.Tencent/BucketClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,6 @@
_region = region;
}

public bool UploadBytes(string key, byte[] fileData)
{
var result = false;
try
{
var request = new PutObjectRequest(_fullBucketName, key, fileData);

var resultData = CosXml.PutObject(request);

if (resultData != null && resultData.IsSuccessful())
{
result = true;
}
}
catch (CosClientException clientEx)
{
throw new Exception(clientEx.Message);
}
catch (CosServerException serverEx)
{
throw new Exception(serverEx.Message);
}
return result;
}

public bool UploadStream(string key, Stream stream)
{
var result = false;
Expand All @@ -73,40 +48,6 @@
return result;
}

public (string, byte[]) DownloadDirDefaultFileBytes(string dir)
{
try
{
var request = new GetBucketRequest(_fullBucketName);
request.SetPrefix($"{dir.TrimEnd('/')}/");
request.SetDelimiter("/");

var result = CosXml.GetBucket(request);

var info = result.listBucket;

var objects = info.contentsList;

var objectData = objects.FirstOrDefault(o => o.size > 0);

if (objectData != null)
{
var fileName = Path.GetFileName(objectData.key);
var fileBytes = DownloadFileBytes(objectData.key);
return (fileName, fileBytes);
}
}
catch (CosClientException clientEx)
{
throw new Exception(clientEx.Message);
}
catch (CosServerException serverEx)
{
throw new Exception(serverEx.Message);
}
return (string.Empty, Array.Empty<byte>());
}

public byte[] DownloadFileBytes(string key)
{
try
Expand All @@ -129,141 +70,11 @@
return Array.Empty<byte>();
}

public List<string> GetDirFiles(string dir)
{
try
{
var request = new GetBucketRequest(_fullBucketName);
request.SetPrefix($"{dir.TrimEnd('/')}/");
request.SetDelimiter("/");

var result = CosXml.GetBucket(request);

var info = result.listBucket;

var objects = info.contentsList;

return objects.Where(o => o.size > 0).Select(o => o.key).ToList();

}
catch (CosClientException clientEx)
{
throw new Exception(clientEx.Message);
}
catch (CosServerException serverEx)
{
throw new Exception(serverEx.Message);
}
}

public List<string> GetDirectories(string dir)
{
var dirs = new List<string>();
try
{
var request = new GetBucketRequest(_fullBucketName);
request.SetPrefix($"{dir.TrimEnd('/')}/");
request.SetDelimiter("/");

var result = CosXml.GetBucket(request);

var info = result.listBucket;

var objects = info.contentsList;

var list = objects.Where(o => o.size == 0 && o.key != dir).Select(o => o.key).ToList();

dirs.AddRange(list);

var commonPrefixes = info.commonPrefixesList;

dirs.AddRange(commonPrefixes.Select(c => c.prefix));

return dirs;

}
catch (CosClientException clientEx)
{
throw new Exception(clientEx.Message);
}
catch (CosServerException serverEx)
{
throw new Exception(serverEx.Message);
}
}

public bool DirExists(string dir)
{
try
{
var request = new GetBucketRequest(_fullBucketName);
request.SetPrefix($"{dir.TrimEnd('/')}/");
request.SetDelimiter("/");

var result = CosXml.GetBucket(request);

var info = result.listBucket;

var objects = info.contentsList;

return objects.Count > 0 || info?.commonPrefixesList.Count > 0;

}
catch (CosClientException clientEx)
{
throw new Exception(clientEx.Message);
}
catch (CosServerException serverEx)
{
throw new Exception(serverEx.Message);
}
}

public void MoveDir(string sourceDir, string destDir)
{
var listRequest = new GetBucketRequest(_fullBucketName);

listRequest.SetPrefix($"{sourceDir.TrimEnd('/')}/");
var listResult = CosXml.GetBucket(listRequest);

var info = listResult.listBucket;

var objects = info.contentsList;

foreach (var obj in objects)
{
string sourceKey = obj.key;
string destinationKey = $"{destDir.TrimEnd('/')}/{sourceKey.Substring(sourceDir.Length)}";

var copySource = new CopySourceStruct(_appId, _fullBucketName, _region, sourceKey);

var request = new CopyObjectRequest(_fullBucketName, destinationKey);

request.SetCopySource(copySource);
try
{

var result = CosXml.CopyObject(request);
var deleteRequest = new DeleteObjectRequest(_fullBucketName, sourceKey);
var deleteResult = CosXml.DeleteObject(deleteRequest);
}
catch (CosClientException clientEx)
{
throw new Exception(clientEx.Message);
}
catch (CosServerException serverEx)
{
throw new Exception(serverEx.Message);
}
}

}

public void DeleteDir(string dir)
{
try
{
string nextMarker = null;

Check warning on line 77 in src/BaGetter.Tencent/BucketClient.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Converting null literal or possible null value to non-nullable type.

Check warning on line 77 in src/BaGetter.Tencent/BucketClient.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Converting null literal or possible null value to non-nullable type.
do
{
var listRequest = new GetBucketRequest(_fullBucketName);
Expand Down
13 changes: 9 additions & 4 deletions src/BaGetter.Tencent/TencentStorageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,23 @@
_options = options.Value;
}

public async Task DeleteAsync(string path, CancellationToken cancellationToken = default)

Check warning on line 18 in src/BaGetter.Tencent/TencentStorageService.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 18 in src/BaGetter.Tencent/TencentStorageService.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
ArgumentException.ThrowIfNullOrEmpty(path);
var found = _cosClient.BucketClient.GetDirFiles(PrepareKey(path)).FirstOrDefault() ?? string.Empty;
if(string.IsNullOrEmpty(found))
var found = _cosClient.BucketClient.DoesObjectExist(PrepareKey(path)) ? PrepareKey(path) : string.Empty;
if (string.IsNullOrEmpty(found))
{
throw new KeyNotFoundException($"The file {path} was not found.");
}
_cosClient.BucketClient.DeleteDir(path);
}

public async Task<Stream> GetAsync(string path, CancellationToken cancellationToken = default)

Check warning on line 29 in src/BaGetter.Tencent/TencentStorageService.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 29 in src/BaGetter.Tencent/TencentStorageService.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
ArgumentException.ThrowIfNullOrEmpty(path);
var fileStorageUrl = _cosClient.BucketClient.GetDirFiles(PrepareKey(path)).FirstOrDefault() ?? string.Empty;

var fileStorageUrl = _cosClient.BucketClient.DoesObjectExist(PrepareKey(path)) ? PrepareKey(path) : string.Empty;

if (string.IsNullOrEmpty(fileStorageUrl))
{
throw new KeyNotFoundException($"The file {path} was not found.");
Expand All @@ -38,10 +40,12 @@
return new MemoryStream(bytes);
}

public async Task<Uri> GetDownloadUriAsync(string path, CancellationToken cancellationToken = default)

Check warning on line 43 in src/BaGetter.Tencent/TencentStorageService.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 43 in src/BaGetter.Tencent/TencentStorageService.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
ArgumentException.ThrowIfNullOrEmpty(path);
var fileStorageUrl = _cosClient.BucketClient.GetDirFiles(PrepareKey(path)).FirstOrDefault() ?? string.Empty;

var fileStorageUrl = _cosClient.BucketClient.DoesObjectExist(PrepareKey(path)) ? PrepareKey(path) : string.Empty;

if (string.IsNullOrEmpty(fileStorageUrl))
{
throw new KeyNotFoundException($"The file {path} was not found.");
Expand All @@ -59,6 +63,7 @@
seekableContent.Seek(0, SeekOrigin.Begin);

var fileRet = _cosClient.BucketClient.UploadStream(PrepareKey(path), seekableContent);

if(!fileRet)
{
return StoragePutResult.AlreadyExists;
Expand Down
Loading