Add ability to enable HTTP routes for servers to host static files
parent
dcaa9a8ac9
commit
a2f9a8f217
|
@ -0,0 +1,33 @@
|
||||||
|
using LANCommander.Services;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace LANCommander.Controllers
|
||||||
|
{
|
||||||
|
public class ServerController : Controller
|
||||||
|
{
|
||||||
|
private readonly ServerService ServerService;
|
||||||
|
|
||||||
|
public ServerController(ServerService serverService)
|
||||||
|
{
|
||||||
|
this.ServerService = serverService;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("/Server/{id:guid}/{*path}")]
|
||||||
|
public async Task<IActionResult> Web(Guid id, string path)
|
||||||
|
{
|
||||||
|
var server = await ServerService.Get(id);
|
||||||
|
|
||||||
|
if (server == null)
|
||||||
|
return NotFound();
|
||||||
|
|
||||||
|
path = path.Replace('/', Path.DirectorySeparatorChar);
|
||||||
|
|
||||||
|
var filename = Path.Combine(server.HTTPRootPath, path);
|
||||||
|
|
||||||
|
if (!System.IO.File.Exists(filename))
|
||||||
|
return NotFound();
|
||||||
|
|
||||||
|
return File(new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read), "application/octet-stream", Path.GetFileName(filename));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -17,6 +17,9 @@ namespace LANCommander.Data.Models
|
||||||
public bool Autostart { get; set; }
|
public bool Autostart { get; set; }
|
||||||
public int AutostartDelay { get; set; }
|
public int AutostartDelay { get; set; }
|
||||||
|
|
||||||
|
public bool EnableHTTP { get; set; }
|
||||||
|
public string HTTPRootPath { get; set; }
|
||||||
|
|
||||||
public Guid? GameId { get; set; }
|
public Guid? GameId { get; set; }
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
[ForeignKey(nameof(GameId))]
|
[ForeignKey(nameof(GameId))]
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,40 @@
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace LANCommander.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class AddServerHTTPSupport : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<bool>(
|
||||||
|
name: "EnableHTTP",
|
||||||
|
table: "Servers",
|
||||||
|
type: "INTEGER",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: false);
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<string>(
|
||||||
|
name: "HTTPRootPath",
|
||||||
|
table: "Servers",
|
||||||
|
type: "TEXT",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: "");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "EnableHTTP",
|
||||||
|
table: "Servers");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "HTTPRootPath",
|
||||||
|
table: "Servers");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -643,9 +643,16 @@ namespace LANCommander.Migrations
|
||||||
b.Property<DateTime>("CreatedOn")
|
b.Property<DateTime>("CreatedOn")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<bool>("EnableHTTP")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
b.Property<Guid?>("GameId")
|
b.Property<Guid?>("GameId")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("HTTPRootPath")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<string>("Name")
|
b.Property<string>("Name")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
<Sider Width="200">
|
<Sider Width="200">
|
||||||
<Menu Mode="@MenuMode.Inline" Style="height: 100%;">
|
<Menu Mode="@MenuMode.Inline" Style="height: 100%;">
|
||||||
<MenuItem RouterLink="@($"/Servers/{Server.Id}/General")">General</MenuItem>
|
<MenuItem RouterLink="@($"/Servers/{Server.Id}/General")">General</MenuItem>
|
||||||
|
<MenuItem RouterLink="@($"/Servers/{Server.Id}/HTTP")">HTTP</MenuItem>
|
||||||
@if (Server != null && Server.Id != Guid.Empty)
|
@if (Server != null && Server.Id != Guid.Empty)
|
||||||
{
|
{
|
||||||
<MenuItem RouterLink="@($"/Servers/{Server.Id}/Consoles")">Consoles</MenuItem>
|
<MenuItem RouterLink="@($"/Servers/{Server.Id}/Consoles")">Consoles</MenuItem>
|
||||||
|
@ -116,6 +116,23 @@
|
||||||
</Form>
|
</Form>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@if (Panel == "HTTP")
|
||||||
|
{
|
||||||
|
<Form Model="@Server" Layout="@FormLayout.Vertical">
|
||||||
|
<FormItem Label="Enable HTTP">
|
||||||
|
<Switch @bind-Checked="context.EnableHTTP" />
|
||||||
|
</FormItem>
|
||||||
|
|
||||||
|
<FormItem Label="Root Path">
|
||||||
|
<FilePicker Root="@RootPath" Title="Choose Root Path" OkText="Select Directory" EntrySelectable="x => x is FileManagerDirectory" @bind-Value="@context.HTTPRootPath" />
|
||||||
|
</FormItem>
|
||||||
|
|
||||||
|
<FormItem>
|
||||||
|
<Button Type="@ButtonType.Primary" OnClick="Save" Icon="@IconType.Fill.Save">Save</Button>
|
||||||
|
</FormItem>
|
||||||
|
</Form>
|
||||||
|
}
|
||||||
|
|
||||||
@if (Panel == "Monitor")
|
@if (Panel == "Monitor")
|
||||||
{
|
{
|
||||||
@if (LogId == "Console") {
|
@if (LogId == "Console") {
|
||||||
|
|
Loading…
Reference in New Issue