module installer
This commit is contained in:
parent
a84eee8782
commit
f60898dbc7
|
@ -2,9 +2,11 @@
|
||||||
@using Oqtane.Client.Modules.Controls
|
@using Oqtane.Client.Modules.Controls
|
||||||
@using Oqtane.Modules
|
@using Oqtane.Modules
|
||||||
@using Oqtane.Services
|
@using Oqtane.Services
|
||||||
|
@using Oqtane.Shared
|
||||||
@inherits ModuleBase
|
@inherits ModuleBase
|
||||||
@inject IUriHelper UriHelper
|
@inject IUriHelper UriHelper
|
||||||
@inject IFileService FileService
|
@inject IFileService FileService
|
||||||
|
@inject IModuleDefinitionService ModuleDefinitionService
|
||||||
|
|
||||||
<table class="table table-borderless">
|
<table class="table table-borderless">
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -16,15 +18,32 @@
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<button type="button" class="btn btn-success" @onclick="UploadFile">Upload</button>
|
@if (uploaded)
|
||||||
|
{
|
||||||
|
<button type="button" class="btn btn-success" @onclick="InstallFile">Install</button>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<button type="button" class="btn btn-success" @onclick="UploadFile">Upload</button>
|
||||||
|
}
|
||||||
<NavLink class="btn btn-secondary" href="@NavigateUrl()">Cancel</NavLink>
|
<NavLink class="btn btn-secondary" href="@NavigateUrl()">Cancel</NavLink>
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Host; } }
|
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Host; } }
|
||||||
|
|
||||||
|
bool uploaded = false;
|
||||||
|
|
||||||
private async Task UploadFile()
|
private async Task UploadFile()
|
||||||
{
|
{
|
||||||
await FileService.UploadFilesAsync("/Sites/Modules");
|
await FileService.UploadFilesAsync("Modules");
|
||||||
|
uploaded = true;
|
||||||
|
StateHasChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task InstallFile()
|
||||||
|
{
|
||||||
|
await ModuleDefinitionService.InstallModulesAsync();
|
||||||
|
PageState.Reload = Constants.ReloadApplication;
|
||||||
|
UriHelper.NavigateTo(NavigateUrl());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
<ActionLink Action="Add" Text="Upload Module" />
|
<ActionLink Action="Add" Text="Install Module" />
|
||||||
<table class="table table-borderless">
|
<table class="table table-borderless">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
|
|
@ -7,5 +7,6 @@ namespace Oqtane.Services
|
||||||
public interface IModuleDefinitionService
|
public interface IModuleDefinitionService
|
||||||
{
|
{
|
||||||
Task<List<ModuleDefinition>> GetModuleDefinitionsAsync();
|
Task<List<ModuleDefinition>> GetModuleDefinitionsAsync();
|
||||||
}
|
Task InstallModulesAsync();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,5 +63,10 @@ namespace Oqtane.Services
|
||||||
|
|
||||||
return moduledefinitions.OrderBy(item => item.Name).ToList();
|
return moduledefinitions.OrderBy(item => item.Name).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task InstallModulesAsync()
|
||||||
|
{
|
||||||
|
await http.GetJsonAsync<List<string>>(apiurl + "/install");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
{
|
{
|
||||||
if (PageState.Site.Logo != "")
|
if (PageState.Site.Logo != "")
|
||||||
{
|
{
|
||||||
logo = "<a href=\"" + PageState.Alias.Url + "\"><img src=\"/Sites/" + PageState.Site.SiteId.ToString() + "/" + PageState.Site.Logo + "\" alt=\"" + PageState.Site.Name + "\"/></a>";
|
logo = "<a href=\"" + PageState.Alias.Url + "\"><img src=\"" + PageState.Alias.SiteRootUrl + PageState.Site.Logo + "\" alt=\"" + PageState.Site.Name + "\"/></a>";
|
||||||
}
|
}
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,5 +55,61 @@ window.interop = {
|
||||||
|
|
||||||
document.body.appendChild(form);
|
document.body.appendChild(form);
|
||||||
form.submit();
|
form.submit();
|
||||||
|
},
|
||||||
|
uploadFiles: function (posturl, folder, name) {
|
||||||
|
var files = document.getElementById(name + 'FileInput').files;
|
||||||
|
var progressinfo = document.getElementById(name + 'ProgressInfo');
|
||||||
|
var progressbar = document.getElementById(name + 'ProgressBar');
|
||||||
|
var filename = '';
|
||||||
|
|
||||||
|
for (var i = 0; i < files.length; i++) {
|
||||||
|
var FileChunk = [];
|
||||||
|
var file = files[i];
|
||||||
|
var MaxFileSizeMB = 1;
|
||||||
|
var BufferChunkSize = MaxFileSizeMB * (1024 * 1024);
|
||||||
|
var FileStreamPos = 0;
|
||||||
|
var EndPos = BufferChunkSize;
|
||||||
|
var Size = file.size;
|
||||||
|
|
||||||
|
progressbar.setAttribute("style", "visibility: visible;");
|
||||||
|
|
||||||
|
if (files.length > 1) {
|
||||||
|
filename = file.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (FileStreamPos < Size) {
|
||||||
|
FileChunk.push(file.slice(FileStreamPos, EndPos));
|
||||||
|
FileStreamPos = EndPos;
|
||||||
|
EndPos = FileStreamPos + BufferChunkSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
var TotalParts = FileChunk.length;
|
||||||
|
var PartCount = 0;
|
||||||
|
|
||||||
|
while (Chunk = FileChunk.shift()) {
|
||||||
|
PartCount++;
|
||||||
|
var FileName = file.name + ".part_" + PartCount + "_" + TotalParts;
|
||||||
|
|
||||||
|
var data = new FormData();
|
||||||
|
data.append('folder', folder);
|
||||||
|
data.append('file', Chunk, FileName);
|
||||||
|
var request = new XMLHttpRequest();
|
||||||
|
request.open('POST', posturl, true);
|
||||||
|
request.upload.onloadstart = function (e) {
|
||||||
|
progressbar.value = 0;
|
||||||
|
progressinfo.innerHTML = filename + ' 0%';
|
||||||
|
};
|
||||||
|
request.upload.onprogress = function (e) {
|
||||||
|
var percent = Math.ceil((e.loaded / e.total) * 100);
|
||||||
|
progressbar.value = (percent / 100);
|
||||||
|
progressinfo.innerHTML = filename + '[' + PartCount + '] ' + percent + '%';
|
||||||
|
};
|
||||||
|
request.upload.onloadend = function (e) {
|
||||||
|
progressbar.value = 1;
|
||||||
|
progressinfo.innerHTML = filename + ' 100%';
|
||||||
|
};
|
||||||
|
request.send(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,6 +2,13 @@
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Oqtane.Repository;
|
using Oqtane.Repository;
|
||||||
using Oqtane.Models;
|
using Oqtane.Models;
|
||||||
|
using Oqtane.Shared;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using System.IO.Compression;
|
||||||
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
namespace Oqtane.Controllers
|
namespace Oqtane.Controllers
|
||||||
{
|
{
|
||||||
|
@ -9,10 +16,14 @@ namespace Oqtane.Controllers
|
||||||
public class ModuleDefinitionController : Controller
|
public class ModuleDefinitionController : Controller
|
||||||
{
|
{
|
||||||
private readonly IModuleDefinitionRepository ModuleDefinitions;
|
private readonly IModuleDefinitionRepository ModuleDefinitions;
|
||||||
|
private readonly IHostApplicationLifetime HostApplicationLifetime;
|
||||||
|
private readonly IWebHostEnvironment environment;
|
||||||
|
|
||||||
public ModuleDefinitionController(IModuleDefinitionRepository ModuleDefinitions)
|
public ModuleDefinitionController(IModuleDefinitionRepository ModuleDefinitions, IHostApplicationLifetime HostApplicationLifetime, IWebHostEnvironment environment)
|
||||||
{
|
{
|
||||||
this.ModuleDefinitions = ModuleDefinitions;
|
this.ModuleDefinitions = ModuleDefinitions;
|
||||||
|
this.HostApplicationLifetime = HostApplicationLifetime;
|
||||||
|
this.environment = environment;
|
||||||
}
|
}
|
||||||
|
|
||||||
// GET: api/<controller>
|
// GET: api/<controller>
|
||||||
|
@ -21,5 +32,42 @@ namespace Oqtane.Controllers
|
||||||
{
|
{
|
||||||
return ModuleDefinitions.GetModuleDefinitions();
|
return ModuleDefinitions.GetModuleDefinitions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet("install")]
|
||||||
|
[Authorize(Roles = Constants.HostRole)]
|
||||||
|
public void InstallModules()
|
||||||
|
{
|
||||||
|
bool install = false;
|
||||||
|
string modulefolder = Path.Combine(environment.WebRootPath, "Modules");
|
||||||
|
string binfolder = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
||||||
|
|
||||||
|
// iterate through module packages
|
||||||
|
foreach (string packagename in Directory.GetFiles(modulefolder, "*.nupkg"))
|
||||||
|
{
|
||||||
|
// iterate through files and deploy to appropriate locations
|
||||||
|
using (ZipArchive archive = ZipFile.OpenRead(packagename))
|
||||||
|
{
|
||||||
|
foreach (ZipArchiveEntry entry in archive.Entries)
|
||||||
|
{
|
||||||
|
string filename = Path.GetFileName(entry.FullName);
|
||||||
|
switch (Path.GetExtension(filename))
|
||||||
|
{
|
||||||
|
case ".dll":
|
||||||
|
entry.ExtractToFile(Path.Combine(binfolder, filename));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// remove module package
|
||||||
|
System.IO.File.Delete(packagename);
|
||||||
|
install = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (install)
|
||||||
|
{
|
||||||
|
// restart application
|
||||||
|
HostApplicationLifetime.StopApplication();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 7.8 KiB |
Binary file not shown.
Before Width: | Height: | Size: 7.8 KiB |
Before Width: | Height: | Size: 7.8 KiB After Width: | Height: | Size: 7.8 KiB |
Before Width: | Height: | Size: 7.8 KiB After Width: | Height: | Size: 7.8 KiB |
|
@ -44,5 +44,40 @@ namespace Oqtane.Models
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[NotMapped]
|
||||||
|
public string TenantRootPath
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return "Tenants/" + TenantId.ToString() + "/";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[NotMapped]
|
||||||
|
public string TenantRootUrl
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return Url + "/Tenants/" + TenantId.ToString() + "/";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[NotMapped]
|
||||||
|
public string SiteRootPath
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return "Tenants/" + TenantId.ToString() + "/Sites/" + SiteId.ToString() + "/";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[NotMapped]
|
||||||
|
public string SiteRootUrl
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return Url + "/Tenants/" + TenantId.ToString() + "/Sites/" + SiteId.ToString() + "/";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user