improve BaseUrl handling for MAUI, replace ContentUrl with FileUrl and improve file server

This commit is contained in:
Shaun Walker
2022-09-21 13:38:21 -04:00
parent a5f1bc3895
commit 06812d5df8
8 changed files with 155 additions and 58 deletions

View File

@ -42,6 +42,13 @@ namespace Oqtane.Pages
var folderpath = "";
var filename = "";
bool download = false;
if (path.Contains("?download"))
{
download = true;
path = path.Substring(0, path.IndexOf("?download"));
}
var segments = path.Split('/');
if (segments.Length > 0)
{
@ -52,15 +59,31 @@ namespace Oqtane.Pages
}
}
var file = _files.GetFile(_alias.SiteId, folderpath, filename);
Models.File file;
if (folderpath == "id" && int.TryParse(filename, out int fileid))
{
file = _files.GetFile(fileid, false);
}
else
{
file = _files.GetFile(_alias.SiteId, folderpath, filename);
}
if (file != null)
{
if (_userPermissions.IsAuthorized(User, PermissionNames.View, file.Folder.Permissions))
if (file.Folder.SiteId == _alias.SiteId && _userPermissions.IsAuthorized(User, PermissionNames.View, file.Folder.Permissions))
{
var filepath = _files.GetFilePath(file);
if (System.IO.File.Exists(filepath))
{
return PhysicalFile(filepath, file.GetMimeType());
if (download)
{
return PhysicalFile(filepath, file.GetMimeType(), file.Name);
}
else
{
return PhysicalFile(filepath, file.GetMimeType());
}
}
else
{
@ -91,7 +114,7 @@ namespace Oqtane.Pages
}
// broken link
string errorPath = Path.Combine(Utilities.PathCombine(_environment.ContentRootPath, "wwwroot\\images"), "error.png");
string errorPath = Path.Combine(Utilities.PathCombine(_environment.ContentRootPath, "wwwroot/images"), "error.png");
return PhysicalFile(errorPath, MimeUtilities.GetMimeType(errorPath));
}
}

View File

@ -126,7 +126,7 @@ namespace Oqtane.Pages
}
if (site.FaviconFileId != null)
{
FavIcon = Utilities.ContentUrl(alias, site.FaviconFileId.Value);
FavIcon = Utilities.FileUrl(alias, site.FaviconFileId.Value);
}
if (site.PwaIsEnabled && site.PwaAppIconFileId != null && site.PwaSplashIconFileId != null)
{
@ -384,11 +384,11 @@ namespace Oqtane.Pages
"\"background_color\": \"#fff\", " +
"\"description\": \"" + site.Name + "\", " +
"\"icons\": [{ " +
"\"src\": \"" + route.RootUrl + Utilities.ContentUrl(alias, site.PwaAppIconFileId.Value) + "\", " +
"\"src\": \"" + route.RootUrl + Utilities.FileUrl(alias, site.PwaAppIconFileId.Value) + "\", " +
"\"sizes\": \"192x192\", " +
"\"type\": \"image/png\" " +
"}, { " +
"\"src\": \"" + route.RootUrl + Utilities.ContentUrl(alias, site.PwaSplashIconFileId.Value) + "\", " +
"\"src\": \"" + route.RootUrl + Utilities.FileUrl(alias, site.PwaSplashIconFileId.Value) + "\", " +
"\"sizes\": \"512x512\", " +
"\"type\": \"image/png\" " +
"}] " +