Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

only allow download of assemblies when using WebAssembly #3526

Merged
merged 1 commit into from
Dec 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 additions & 3 deletions Oqtane.Server/Controllers/InstallationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ public class InstallationController : Controller
private readonly IMemoryCache _cache;
private readonly IHttpContextAccessor _accessor;
private readonly IAliasRepository _aliases;
private readonly ISiteRepository _sites;
private readonly ILogger<InstallationController> _filelogger;
private readonly ITenantManager _tenantManager;
private readonly IServerStateManager _serverState;

public InstallationController(IConfigManager configManager, IInstallationManager installationManager, IDatabaseManager databaseManager, ILocalizationManager localizationManager, IMemoryCache cache, IHttpContextAccessor accessor, IAliasRepository aliases, ILogger<InstallationController> filelogger, ITenantManager tenantManager, IServerStateManager serverState)
public InstallationController(IConfigManager configManager, IInstallationManager installationManager, IDatabaseManager databaseManager, ILocalizationManager localizationManager, IMemoryCache cache, IHttpContextAccessor accessor, IAliasRepository aliases, ISiteRepository sites, ILogger<InstallationController> filelogger, ITenantManager tenantManager, IServerStateManager serverState)
{
_configManager = configManager;
_installationManager = installationManager;
Expand All @@ -43,6 +44,7 @@ public InstallationController(IConfigManager configManager, IInstallationManager
_cache = cache;
_accessor = accessor;
_aliases = aliases;
_sites = sites;
_filelogger = filelogger;
_tenantManager = tenantManager;
_serverState = serverState;
Expand Down Expand Up @@ -105,14 +107,32 @@ public void Restart()
[HttpGet("list")]
public List<string> List()
{
return GetAssemblyList().Select(item => item.HashedName).ToList();
var alias = _tenantManager.GetAlias();
var site = _sites.GetSite(alias.SiteId);
if (site != null && site.Runtime == "WebAssembly")
{
return GetAssemblyList().Select(item => item.HashedName).ToList();
}
else
{
return new List<string>();
}
}

// GET api/<controller>/load?list=x,y
[HttpGet("load")]
public IActionResult Load(string list = "*")
{
return File(GetAssemblies(list), System.Net.Mime.MediaTypeNames.Application.Octet, "oqtane.dll");
var alias = _tenantManager.GetAlias();
var site = _sites.GetSite(alias.SiteId);
if (site != null && site.Runtime == "WebAssembly")
{
return File(GetAssemblies(list), System.Net.Mime.MediaTypeNames.Application.Octet, "oqtane.dll");
}
else
{
return File(GetEmptyZip(), System.Net.Mime.MediaTypeNames.Application.Octet, "oqtane.dll");
}
}

private List<ClientAssembly> GetAssemblyList()
Expand Down Expand Up @@ -238,6 +258,18 @@ private byte[] GetZIP(string list)
}
}

private byte[] GetEmptyZip()
{
using (var stream = new MemoryStream())
{
using (var zip = new ZipArchive(stream, ZipArchiveMode.Create))
{
}

return stream.ToArray();
}
}

private async Task RegisterContact(string email)
{
try
Expand Down