🐛 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

@@ -1,7 +1,7 @@
# dependencies (bun install) # dependencies (bun install)
node_modules node_modules
wwwroot/css/site.dist.css wwwroot/css/site.dist.css
wwwroot/SiteData SiteData
# output # output
out out

View File

@@ -82,6 +82,7 @@
<_ContentIncludedByDefault Remove="wwwroot\lib\jquery-validation\dist\jquery.validate.js" /> <_ContentIncludedByDefault Remove="wwwroot\lib\jquery-validation\dist\jquery.validate.js" />
<_ContentIncludedByDefault Remove="wwwroot\lib\jquery-validation\dist\jquery.validate.min.js" /> <_ContentIncludedByDefault Remove="wwwroot\lib\jquery-validation\dist\jquery.validate.min.js" />
<_ContentIncludedByDefault Remove="wwwroot\lib\jquery-validation\LICENSE.md" /> <_ContentIncludedByDefault Remove="wwwroot\lib\jquery-validation\LICENSE.md" />
<_ContentIncludedByDefault Remove="wwwroot\SiteData\5755cb46-ae17-4b4e-9716-45b264e9851f\capture-the-flag.mp4" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

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 the site is enabled the self-managed mode, try lookup the files then
if (Site.Mode == PublicationSiteMode.SelfManaged) if (Site.Mode == PublicationSiteMode.SelfManaged)
{ {
// TODO: Fix the path contains a wwwroot
var provider = new FileExtensionContentTypeProvider(); var provider = new FileExtensionContentTypeProvider();
var hostedFilePath = psm.GetValidatedFullPath(Site.Id, CurrentPath); var hostedFilePath = psm.GetValidatedFullPath(Site.Id, CurrentPath);
if (System.IO.File.Exists(hostedFilePath)) if (System.IO.File.Exists(hostedFilePath))
{ {
if (!provider.TryGetContentType(hostedFilePath, out var mimeType)) if (!provider.TryGetContentType(hostedFilePath, out var mimeType))
mimeType = "text/html"; 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"); var hostedNotFoundPath = psm.GetValidatedFullPath(Site.Id, "404.html");
if (System.IO.File.Exists(hostedNotFoundPath)) 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(); return Page();

View File

@@ -17,7 +17,7 @@ public class PublicationSiteManager(
) )
{ {
private readonly string _basePath = Path.Combine( private readonly string _basePath = Path.Combine(
hostEnvironment.WebRootPath, hostEnvironment.ContentRootPath,
configuration["Sites:BasePath"]!.TrimStart('/') configuration["Sites:BasePath"]!.TrimStart('/')
); );