shoko/Protocols/ResProtoHandler.cs

36 lines
813 B
C#
Raw Normal View History

using System.Reflection;
2023-10-20 04:59:28 +00:00
using System.Text;
using System.Web;
2023-10-09 02:27:47 +00:00
using HeyRed.Mime;
namespace Shoko;
[Protocol("res")]
class ResProtoHandler : ProtoHandler
{
public ResProtoHandler(Uri url)
{
URL = url;
}
2023-10-20 04:59:28 +00:00
public override async Task Load()
{
2023-10-20 04:59:28 +00:00
var path = HttpUtility.HtmlDecode(URL.AbsolutePath);
Status = "OK";
try
{
2023-10-20 04:59:28 +00:00
Content = await Download(Assembly.GetExecutingAssembly().GetManifestResourceStream(path));
2023-10-09 02:27:47 +00:00
MediaType = MimeGuesser.GuessMimeType(Content);
}
catch
{
2023-10-20 04:59:28 +00:00
Content = new MemoryStream(Encoding.UTF8.GetBytes("resource not found"));
MediaType = "text/plain";
Status = "not found";
}
2023-10-20 04:59:28 +00:00
OnLoaded();
}
public override void Render()
{
}
}