19 lines
656 B
C#
19 lines
656 B
C#
namespace ForgejoReleaseSync.Services;
|
|
|
|
public class ReleaseAssetDownloadService(HttpClient httpClient)
|
|
{
|
|
public async Task<string> DownloadReleaseAssetAsync(Uri url)
|
|
{
|
|
var fileName = Path.GetFileName(url.AbsoluteUri);
|
|
var filePath = Path.Combine(Path.GetTempPath(), fileName);
|
|
await using Stream resource = await httpClient.GetStreamAsync(url);
|
|
await using FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate);
|
|
await resource.CopyToAsync(fs, 8192);
|
|
return filePath;
|
|
}
|
|
|
|
public async Task DeleteReleaseAssetAsync(string downloadPath)
|
|
{
|
|
File.Delete(downloadPath);
|
|
}
|
|
} |