🐛 Fix self-managed files hosting
This commit is contained in:
2
DysonNetwork.Zone/.gitignore
vendored
2
DysonNetwork.Zone/.gitignore
vendored
@@ -1,7 +1,7 @@
|
||||
# dependencies (bun install)
|
||||
node_modules
|
||||
wwwroot/css/site.dist.css
|
||||
wwwroot/SiteData
|
||||
SiteData
|
||||
|
||||
# output
|
||||
out
|
||||
|
||||
@@ -82,6 +82,7 @@
|
||||
<_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\LICENSE.md" />
|
||||
<_ContentIncludedByDefault Remove="wwwroot\SiteData\5755cb46-ae17-4b4e-9716-45b264e9851f\capture-the-flag.mp4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -17,7 +17,7 @@ public class PublicationSiteManager(
|
||||
)
|
||||
{
|
||||
private readonly string _basePath = Path.Combine(
|
||||
hostEnvironment.WebRootPath,
|
||||
hostEnvironment.ContentRootPath,
|
||||
configuration["Sites:BasePath"]!.TrimStart('/')
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user