🐛 Fix self-managed files hosting

This commit is contained in:
2025-11-21 22:27:27 +08:00
parent 7016a0a943
commit 2a35786204
4 changed files with 9 additions and 5 deletions

View File

@@ -47,19 +47,22 @@ public class IndexModel(AppDatabase db, PublicationSiteManager psm) : PageModel
// If the site is enabled the self-managed mode, try lookup the files then
if (Site.Mode == PublicationSiteMode.SelfManaged)
{
// TODO: Fix the path contains a wwwroot
var provider = new FileExtensionContentTypeProvider();
var hostedFilePath = psm.GetValidatedFullPath(Site.Id, CurrentPath);
if (System.IO.File.Exists(hostedFilePath))
{
if (!provider.TryGetContentType(hostedFilePath, out var mimeType))
mimeType = "text/html";
return File(hostedFilePath, mimeType);
var fileStream = new FileStream(hostedFilePath, FileMode.Open, FileAccess.Read);
return new FileStreamResult(fileStream, mimeType);
}
var hostedNotFoundPath = psm.GetValidatedFullPath(Site.Id, "404.html");
if (System.IO.File.Exists(hostedNotFoundPath))
return File(hostedNotFoundPath, "text/html");
{
var fileStream = new FileStream(hostedNotFoundPath, FileMode.Open, FileAccess.Read);
return new FileStreamResult(fileStream, "text/html");
}
}
return Page();