提交功能
This commit is contained in:
44
Utils/FileUtil.cs
Normal file
44
Utils/FileUtil.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
namespace ACBuildService;
|
||||
|
||||
public class FileUtil
|
||||
{
|
||||
public static readonly string BaseRootPath = $"{AppContext.BaseDirectory}wwwroot/";
|
||||
|
||||
public static string GetFileSizeTitle(long length)
|
||||
{
|
||||
if (length < 1024)
|
||||
{
|
||||
return length + "B";
|
||||
}
|
||||
|
||||
length /= 1024;
|
||||
|
||||
if (length < 1024)
|
||||
{
|
||||
return (length * 100 / 100) + "KB";
|
||||
}
|
||||
|
||||
length /= 1024;
|
||||
if (length < 1024)
|
||||
{
|
||||
return (length * 100 / 100.0f) + "MB";
|
||||
}
|
||||
|
||||
return ((length / 1024 * 100) / 100.0f) + "GB";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得文件夹下所有的文件(类库调用)
|
||||
/// </summary>
|
||||
/// <param name="dir"></param>
|
||||
/// <returns></returns>
|
||||
public static FileInfo[] GetAllFileInfo(DirectoryInfo dir)
|
||||
{
|
||||
return dir.GetFiles(".", SearchOption.AllDirectories);
|
||||
}
|
||||
|
||||
public static string GetVideoPath(string fileName)
|
||||
{
|
||||
return Path.Combine(BaseRootPath, fileName);
|
||||
}
|
||||
}
|
||||
50
Utils/HttpHelper.cs
Normal file
50
Utils/HttpHelper.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace ACBuildService;
|
||||
|
||||
public static class HttpHelper
|
||||
{
|
||||
private static readonly HttpClient _httpClient = new HttpClient();
|
||||
|
||||
public static async Task<string> GetAsync(string url)
|
||||
{
|
||||
try
|
||||
{
|
||||
HttpResponseMessage response = await _httpClient.GetAsync(url);
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
// 使用 UTF-8 编码读取响应内容
|
||||
byte[] byteArray = await response.Content.ReadAsByteArrayAsync();
|
||||
return Encoding.UTF8.GetString(byteArray);
|
||||
}
|
||||
catch (HttpRequestException e)
|
||||
{
|
||||
// 处理请求异常
|
||||
Console.WriteLine($"Request error: {e.Message}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task<string> PostAsync<T>(string url, T data)
|
||||
{
|
||||
try
|
||||
{
|
||||
string json = JsonSerializer.Serialize(data);
|
||||
StringContent content = new StringContent(json, Encoding.UTF8, "application/json");
|
||||
|
||||
HttpResponseMessage response = await _httpClient.PostAsync(url, content);
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
// 使用 UTF-8 编码读取响应内容
|
||||
byte[] byteArray = await response.Content.ReadAsByteArrayAsync();
|
||||
return Encoding.UTF8.GetString(byteArray);
|
||||
}
|
||||
catch (HttpRequestException e)
|
||||
{
|
||||
// 处理请求异常
|
||||
Console.WriteLine($"Request error: {e.Message}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user