submodule对gitea不管用,所以直接拉了一份拉格兰

This commit is contained in:
2025-02-04 16:29:43 +08:00
parent b0bfc803e3
commit d149a2ea0f
1023 changed files with 43308 additions and 18 deletions

View File

@@ -0,0 +1,34 @@
namespace Lagrange.OneBot.Message.Entity;
public static class CommonResolver
{
private static readonly HttpClient Client = new();
public static byte[]? Resolve(string url)
{
if (url.StartsWith("base64://")) return Convert.FromBase64String(url.Replace("base64://", ""));
Uri uri = new(url);
return uri.Scheme switch
{
"http" or "https" => Client.GetAsync(uri).Result.Content.ReadAsByteArrayAsync().Result,
"file" => File.ReadAllBytes(Path.GetFullPath(uri.LocalPath)),
_ => null,
};
}
public static Stream? ResolveStream(string url)
{
if (url.StartsWith("base64://")) return new MemoryStream(Convert.FromBase64String(url.Replace("base64://", "")));
Uri uri = new(url);
return uri.Scheme switch
{
"http" or "https" => Client.GetAsync(uri).Result.Content.ReadAsStreamAsync().Result,
"file" => new FileStream(Path.GetFullPath(uri.LocalPath), FileMode.Open, FileAccess.Read, FileShare.Read),
_ => null,
};
}
}