Updated to latest moonlight and mooncore version. Done refactoring to async scheme and other changes. Recreated database migrations and cleaned models

This commit is contained in:
2025-09-22 12:13:57 +02:00
parent 91fb15a03e
commit 85392208c4
150 changed files with 2722 additions and 2726 deletions

View File

@@ -13,7 +13,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="9.0.7" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="9.0.9" />
<PackageReference Include="MoonCore.PluginFramework" Version="1.0.8"/>
<PackageReference Include="MoonCore.PluginFramework.Generator" Version="1.0.2"/>
</ItemGroup>

View File

@@ -6,15 +6,15 @@ pluginLoader.Initialize();
var cs = new Startup();
await cs.Initialize(args, pluginLoader.Instances);
await cs.InitializeAsync(args, pluginLoader.Instances);
var builder = WebApplication.CreateBuilder(args);
await cs.AddMoonlight(builder);
await cs.AddMoonlightAsync(builder);
var app = builder.Build();
await cs.AddMoonlight(app);
await cs.AddMoonlightAsync(app);
// Handle setup of wasm app hosting in the runtime
// so the Moonlight.ApiServer doesn't need the wasm package

View File

@@ -18,8 +18,4 @@ public class Node
public int HttpPort { get; set; }
public int FtpPort { get; set; }
public bool UseSsl { get; set; }
// Misc
public bool EnableTransparentMode { get; set; }
public bool EnableDynamicFirewall { get; set; }
}

View File

@@ -24,6 +24,4 @@ public class Server
public int Cpu { get; set; }
public int Memory { get; set; }
public int Disk { get; set; }
public bool UseVirtualDisk { get; set; }
public int Bandwidth { get; set; }
}

View File

@@ -1,452 +0,0 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using MoonlightServers.ApiServer.Database;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace MoonlightServers.ApiServer.Database.Migrations
{
[DbContext(typeof(ServersDataContext))]
[Migration("20250226210232_RecreatedMigrationsForPostgresql")]
partial class RecreatedMigrationsForPostgresql
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.11")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Allocation", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("IpAddress")
.IsRequired()
.HasColumnType("text");
b.Property<int>("NodeId")
.HasColumnType("integer");
b.Property<int>("Port")
.HasColumnType("integer");
b.Property<int?>("ServerId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("NodeId");
b.HasIndex("ServerId");
b.ToTable("Servers_Allocations", (string)null);
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Node", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<bool>("EnableDynamicFirewall")
.HasColumnType("boolean");
b.Property<bool>("EnableTransparentMode")
.HasColumnType("boolean");
b.Property<string>("Fqdn")
.IsRequired()
.HasColumnType("text");
b.Property<int>("FtpPort")
.HasColumnType("integer");
b.Property<int>("HttpPort")
.HasColumnType("integer");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Token")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("UseSsl")
.HasColumnType("boolean");
b.HasKey("Id");
b.ToTable("Servers_Nodes", (string)null);
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Server", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("Bandwidth")
.HasColumnType("integer");
b.Property<int>("Cpu")
.HasColumnType("integer");
b.Property<int>("Disk")
.HasColumnType("integer");
b.Property<int>("DockerImageIndex")
.HasColumnType("integer");
b.Property<int>("Memory")
.HasColumnType("integer");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<int>("NodeId")
.HasColumnType("integer");
b.Property<int>("OwnerId")
.HasColumnType("integer");
b.Property<int>("StarId")
.HasColumnType("integer");
b.Property<string>("StartupOverride")
.HasColumnType("text");
b.Property<bool>("UseVirtualDisk")
.HasColumnType("boolean");
b.HasKey("Id");
b.HasIndex("NodeId");
b.HasIndex("StarId");
b.ToTable("Servers_Servers", (string)null);
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.ServerBackup", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<bool>("Completed")
.HasColumnType("boolean");
b.Property<DateTime>("CompletedAt")
.HasColumnType("timestamp with time zone");
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<int?>("ServerId")
.HasColumnType("integer");
b.Property<long>("Size")
.HasColumnType("bigint");
b.Property<bool>("Successful")
.HasColumnType("boolean");
b.HasKey("Id");
b.HasIndex("ServerId");
b.ToTable("Servers_ServerBackups", (string)null);
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.ServerVariable", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Key")
.IsRequired()
.HasColumnType("text");
b.Property<int>("ServerId")
.HasColumnType("integer");
b.Property<string>("Value")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("ServerId");
b.ToTable("Servers_ServerVariables", (string)null);
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Star", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<bool>("AllowDockerImageChange")
.HasColumnType("boolean");
b.Property<string>("Author")
.IsRequired()
.HasColumnType("text");
b.Property<int>("DefaultDockerImage")
.HasColumnType("integer");
b.Property<string>("DonateUrl")
.HasColumnType("text");
b.Property<string>("InstallDockerImage")
.IsRequired()
.HasColumnType("text");
b.Property<string>("InstallScript")
.IsRequired()
.HasColumnType("text");
b.Property<string>("InstallShell")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("OnlineDetection")
.IsRequired()
.HasColumnType("text");
b.Property<string>("ParseConfiguration")
.IsRequired()
.HasColumnType("text");
b.Property<int>("RequiredAllocations")
.HasColumnType("integer");
b.Property<string>("StartupCommand")
.IsRequired()
.HasColumnType("text");
b.Property<string>("StopCommand")
.IsRequired()
.HasColumnType("text");
b.Property<string>("UpdateUrl")
.HasColumnType("text");
b.Property<string>("Version")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Servers_Stars", (string)null);
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.StarDockerImage", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<bool>("AutoPulling")
.HasColumnType("boolean");
b.Property<string>("DisplayName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Identifier")
.IsRequired()
.HasColumnType("text");
b.Property<int>("StarId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("StarId");
b.ToTable("Servers_StarDockerImages", (string)null);
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.StarVariable", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<bool>("AllowEditing")
.HasColumnType("boolean");
b.Property<bool>("AllowViewing")
.HasColumnType("boolean");
b.Property<string>("DefaultValue")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Filter")
.HasColumnType("text");
b.Property<string>("Key")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<int>("StarId")
.HasColumnType("integer");
b.Property<int>("Type")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("StarId");
b.ToTable("Servers_StarVariables", (string)null);
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Allocation", b =>
{
b.HasOne("MoonlightServers.ApiServer.Database.Entities.Node", "Node")
.WithMany("Allocations")
.HasForeignKey("NodeId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("MoonlightServers.ApiServer.Database.Entities.Server", "Server")
.WithMany("Allocations")
.HasForeignKey("ServerId");
b.Navigation("Node");
b.Navigation("Server");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Server", b =>
{
b.HasOne("MoonlightServers.ApiServer.Database.Entities.Node", "Node")
.WithMany("Servers")
.HasForeignKey("NodeId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("MoonlightServers.ApiServer.Database.Entities.Star", "Star")
.WithMany()
.HasForeignKey("StarId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Node");
b.Navigation("Star");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.ServerBackup", b =>
{
b.HasOne("MoonlightServers.ApiServer.Database.Entities.Server", null)
.WithMany("Backups")
.HasForeignKey("ServerId");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.ServerVariable", b =>
{
b.HasOne("MoonlightServers.ApiServer.Database.Entities.Server", "Server")
.WithMany("Variables")
.HasForeignKey("ServerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Server");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.StarDockerImage", b =>
{
b.HasOne("MoonlightServers.ApiServer.Database.Entities.Star", "Star")
.WithMany("DockerImages")
.HasForeignKey("StarId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Star");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.StarVariable", b =>
{
b.HasOne("MoonlightServers.ApiServer.Database.Entities.Star", "Star")
.WithMany("Variables")
.HasForeignKey("StarId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Star");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Node", b =>
{
b.Navigation("Allocations");
b.Navigation("Servers");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Server", b =>
{
b.Navigation("Allocations");
b.Navigation("Backups");
b.Navigation("Variables");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Star", b =>
{
b.Navigation("DockerImages");
b.Navigation("Variables");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -1,456 +0,0 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using MoonlightServers.ApiServer.Database;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace MoonlightServers.ApiServer.Database.Migrations
{
[DbContext(typeof(ServersDataContext))]
[Migration("20250301142415_AddedTokenIdField")]
partial class AddedTokenIdField
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.11")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Allocation", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("IpAddress")
.IsRequired()
.HasColumnType("text");
b.Property<int>("NodeId")
.HasColumnType("integer");
b.Property<int>("Port")
.HasColumnType("integer");
b.Property<int?>("ServerId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("NodeId");
b.HasIndex("ServerId");
b.ToTable("Servers_Allocations", (string)null);
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Node", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<bool>("EnableDynamicFirewall")
.HasColumnType("boolean");
b.Property<bool>("EnableTransparentMode")
.HasColumnType("boolean");
b.Property<string>("Fqdn")
.IsRequired()
.HasColumnType("text");
b.Property<int>("FtpPort")
.HasColumnType("integer");
b.Property<int>("HttpPort")
.HasColumnType("integer");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Token")
.IsRequired()
.HasColumnType("text");
b.Property<string>("TokenId")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("UseSsl")
.HasColumnType("boolean");
b.HasKey("Id");
b.ToTable("Servers_Nodes", (string)null);
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Server", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("Bandwidth")
.HasColumnType("integer");
b.Property<int>("Cpu")
.HasColumnType("integer");
b.Property<int>("Disk")
.HasColumnType("integer");
b.Property<int>("DockerImageIndex")
.HasColumnType("integer");
b.Property<int>("Memory")
.HasColumnType("integer");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<int>("NodeId")
.HasColumnType("integer");
b.Property<int>("OwnerId")
.HasColumnType("integer");
b.Property<int>("StarId")
.HasColumnType("integer");
b.Property<string>("StartupOverride")
.HasColumnType("text");
b.Property<bool>("UseVirtualDisk")
.HasColumnType("boolean");
b.HasKey("Id");
b.HasIndex("NodeId");
b.HasIndex("StarId");
b.ToTable("Servers_Servers", (string)null);
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.ServerBackup", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<bool>("Completed")
.HasColumnType("boolean");
b.Property<DateTime>("CompletedAt")
.HasColumnType("timestamp with time zone");
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<int?>("ServerId")
.HasColumnType("integer");
b.Property<long>("Size")
.HasColumnType("bigint");
b.Property<bool>("Successful")
.HasColumnType("boolean");
b.HasKey("Id");
b.HasIndex("ServerId");
b.ToTable("Servers_ServerBackups", (string)null);
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.ServerVariable", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Key")
.IsRequired()
.HasColumnType("text");
b.Property<int>("ServerId")
.HasColumnType("integer");
b.Property<string>("Value")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("ServerId");
b.ToTable("Servers_ServerVariables", (string)null);
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Star", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<bool>("AllowDockerImageChange")
.HasColumnType("boolean");
b.Property<string>("Author")
.IsRequired()
.HasColumnType("text");
b.Property<int>("DefaultDockerImage")
.HasColumnType("integer");
b.Property<string>("DonateUrl")
.HasColumnType("text");
b.Property<string>("InstallDockerImage")
.IsRequired()
.HasColumnType("text");
b.Property<string>("InstallScript")
.IsRequired()
.HasColumnType("text");
b.Property<string>("InstallShell")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("OnlineDetection")
.IsRequired()
.HasColumnType("text");
b.Property<string>("ParseConfiguration")
.IsRequired()
.HasColumnType("text");
b.Property<int>("RequiredAllocations")
.HasColumnType("integer");
b.Property<string>("StartupCommand")
.IsRequired()
.HasColumnType("text");
b.Property<string>("StopCommand")
.IsRequired()
.HasColumnType("text");
b.Property<string>("UpdateUrl")
.HasColumnType("text");
b.Property<string>("Version")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Servers_Stars", (string)null);
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.StarDockerImage", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<bool>("AutoPulling")
.HasColumnType("boolean");
b.Property<string>("DisplayName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Identifier")
.IsRequired()
.HasColumnType("text");
b.Property<int>("StarId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("StarId");
b.ToTable("Servers_StarDockerImages", (string)null);
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.StarVariable", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<bool>("AllowEditing")
.HasColumnType("boolean");
b.Property<bool>("AllowViewing")
.HasColumnType("boolean");
b.Property<string>("DefaultValue")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Filter")
.HasColumnType("text");
b.Property<string>("Key")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<int>("StarId")
.HasColumnType("integer");
b.Property<int>("Type")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("StarId");
b.ToTable("Servers_StarVariables", (string)null);
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Allocation", b =>
{
b.HasOne("MoonlightServers.ApiServer.Database.Entities.Node", "Node")
.WithMany("Allocations")
.HasForeignKey("NodeId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("MoonlightServers.ApiServer.Database.Entities.Server", "Server")
.WithMany("Allocations")
.HasForeignKey("ServerId");
b.Navigation("Node");
b.Navigation("Server");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Server", b =>
{
b.HasOne("MoonlightServers.ApiServer.Database.Entities.Node", "Node")
.WithMany("Servers")
.HasForeignKey("NodeId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("MoonlightServers.ApiServer.Database.Entities.Star", "Star")
.WithMany()
.HasForeignKey("StarId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Node");
b.Navigation("Star");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.ServerBackup", b =>
{
b.HasOne("MoonlightServers.ApiServer.Database.Entities.Server", null)
.WithMany("Backups")
.HasForeignKey("ServerId");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.ServerVariable", b =>
{
b.HasOne("MoonlightServers.ApiServer.Database.Entities.Server", "Server")
.WithMany("Variables")
.HasForeignKey("ServerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Server");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.StarDockerImage", b =>
{
b.HasOne("MoonlightServers.ApiServer.Database.Entities.Star", "Star")
.WithMany("DockerImages")
.HasForeignKey("StarId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Star");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.StarVariable", b =>
{
b.HasOne("MoonlightServers.ApiServer.Database.Entities.Star", "Star")
.WithMany("Variables")
.HasForeignKey("StarId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Star");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Node", b =>
{
b.Navigation("Allocations");
b.Navigation("Servers");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Server", b =>
{
b.Navigation("Allocations");
b.Navigation("Backups");
b.Navigation("Variables");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Star", b =>
{
b.Navigation("DockerImages");
b.Navigation("Variables");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -1,29 +0,0 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace MoonlightServers.ApiServer.Database.Migrations
{
/// <inheritdoc />
public partial class AddedTokenIdField : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "TokenId",
table: "Servers_Nodes",
type: "text",
nullable: false,
defaultValue: "");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "TokenId",
table: "Servers_Nodes");
}
}
}

View File

@@ -1,51 +0,0 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace MoonlightServers.ApiServer.Database.Migrations
{
/// <inheritdoc />
public partial class AddedShares : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Servers_ServerShares",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
UserId = table.Column<int>(type: "integer", nullable: false),
ServerId = table.Column<int>(type: "integer", nullable: false),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
Content = table.Column<string>(type: "jsonb", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Servers_ServerShares", x => x.Id);
table.ForeignKey(
name: "FK_Servers_ServerShares_Servers_Servers_ServerId",
column: x => x.ServerId,
principalTable: "Servers_Servers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Servers_ServerShares_ServerId",
table: "Servers_ServerShares",
column: "ServerId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Servers_ServerShares");
}
}
}

View File

@@ -12,15 +12,16 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace MoonlightServers.ApiServer.Database.Migrations
{
[DbContext(typeof(ServersDataContext))]
[Migration("20250606121013_AddedShares")]
partial class AddedShares
[Migration("20250922091731_RecreatedModelsInNewSchema")]
partial class RecreatedModelsInNewSchema
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "9.0.5")
.HasDefaultSchema("servers")
.HasAnnotation("ProductVersion", "9.0.9")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
@@ -52,7 +53,7 @@ namespace MoonlightServers.ApiServer.Database.Migrations
b.HasIndex("ServerId");
b.ToTable("Servers_Allocations", (string)null);
b.ToTable("Allocations", "servers");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Node", b =>
@@ -63,12 +64,6 @@ namespace MoonlightServers.ApiServer.Database.Migrations
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<bool>("EnableDynamicFirewall")
.HasColumnType("boolean");
b.Property<bool>("EnableTransparentMode")
.HasColumnType("boolean");
b.Property<string>("Fqdn")
.IsRequired()
.HasColumnType("text");
@@ -96,7 +91,7 @@ namespace MoonlightServers.ApiServer.Database.Migrations
b.HasKey("Id");
b.ToTable("Servers_Nodes", (string)null);
b.ToTable("Nodes", "servers");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Server", b =>
@@ -107,9 +102,6 @@ namespace MoonlightServers.ApiServer.Database.Migrations
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("Bandwidth")
.HasColumnType("integer");
b.Property<int>("Cpu")
.HasColumnType("integer");
@@ -138,16 +130,13 @@ namespace MoonlightServers.ApiServer.Database.Migrations
b.Property<string>("StartupOverride")
.HasColumnType("text");
b.Property<bool>("UseVirtualDisk")
.HasColumnType("boolean");
b.HasKey("Id");
b.HasIndex("NodeId");
b.HasIndex("StarId");
b.ToTable("Servers_Servers", (string)null);
b.ToTable("Servers", "servers");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.ServerBackup", b =>
@@ -180,7 +169,7 @@ namespace MoonlightServers.ApiServer.Database.Migrations
b.HasIndex("ServerId");
b.ToTable("Servers_ServerBackups", (string)null);
b.ToTable("ServerBackups", "servers");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.ServerShare", b =>
@@ -207,7 +196,7 @@ namespace MoonlightServers.ApiServer.Database.Migrations
b.HasIndex("ServerId");
b.ToTable("Servers_ServerShares", (string)null);
b.ToTable("ServerShares", "servers");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.ServerVariable", b =>
@@ -233,7 +222,7 @@ namespace MoonlightServers.ApiServer.Database.Migrations
b.HasIndex("ServerId");
b.ToTable("Servers_ServerVariables", (string)null);
b.ToTable("ServerVariables", "servers");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Star", b =>
@@ -301,7 +290,7 @@ namespace MoonlightServers.ApiServer.Database.Migrations
b.HasKey("Id");
b.ToTable("Servers_Stars", (string)null);
b.ToTable("Stars", "servers");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.StarDockerImage", b =>
@@ -330,7 +319,7 @@ namespace MoonlightServers.ApiServer.Database.Migrations
b.HasIndex("StarId");
b.ToTable("Servers_StarDockerImages", (string)null);
b.ToTable("StarDockerImages", "servers");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.StarVariable", b =>
@@ -376,7 +365,7 @@ namespace MoonlightServers.ApiServer.Database.Migrations
b.HasIndex("StarId");
b.ToTable("Servers_StarVariables", (string)null);
b.ToTable("StarVariables", "servers");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Allocation", b =>
@@ -437,14 +426,14 @@ namespace MoonlightServers.ApiServer.Database.Migrations
b1.HasKey("ServerShareId");
b1.ToTable("Servers_ServerShares");
b1.ToTable("ServerShares", "servers");
b1.ToJson("Content");
b1.WithOwner()
.HasForeignKey("ServerShareId");
b1.OwnsMany("MoonlightServers.ApiServer.Models.ServerSharePermission", "Permissions", b2 =>
b1.OwnsMany("MoonlightServers.ApiServer.Models.ServerShareContent+SharePermission", "Permissions", b2 =>
{
b2.Property<int>("ServerShareContentServerShareId")
.HasColumnType("integer");
@@ -453,16 +442,16 @@ namespace MoonlightServers.ApiServer.Database.Migrations
.ValueGeneratedOnAdd()
.HasColumnType("integer");
b2.Property<string>("Name")
b2.Property<string>("Identifier")
.IsRequired()
.HasColumnType("text");
b2.Property<int>("Type")
b2.Property<int>("Level")
.HasColumnType("integer");
b2.HasKey("ServerShareContentServerShareId", "__synthesizedOrdinal");
b2.ToTable("Servers_ServerShares");
b2.ToTable("ServerShares", "servers");
b2.WithOwner()
.HasForeignKey("ServerShareContentServerShareId");

View File

@@ -7,13 +7,17 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace MoonlightServers.ApiServer.Database.Migrations
{
/// <inheritdoc />
public partial class RecreatedMigrationsForPostgresql : Migration
public partial class RecreatedModelsInNewSchema : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.EnsureSchema(
name: "servers");
migrationBuilder.CreateTable(
name: "Servers_Nodes",
name: "Nodes",
schema: "servers",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
@@ -21,19 +25,19 @@ namespace MoonlightServers.ApiServer.Database.Migrations
Name = table.Column<string>(type: "text", nullable: false),
Fqdn = table.Column<string>(type: "text", nullable: false),
Token = table.Column<string>(type: "text", nullable: false),
TokenId = table.Column<string>(type: "text", nullable: false),
HttpPort = table.Column<int>(type: "integer", nullable: false),
FtpPort = table.Column<int>(type: "integer", nullable: false),
UseSsl = table.Column<bool>(type: "boolean", nullable: false),
EnableTransparentMode = table.Column<bool>(type: "boolean", nullable: false),
EnableDynamicFirewall = table.Column<bool>(type: "boolean", nullable: false)
UseSsl = table.Column<bool>(type: "boolean", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Servers_Nodes", x => x.Id);
table.PrimaryKey("PK_Nodes", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Servers_Stars",
name: "Stars",
schema: "servers",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
@@ -56,11 +60,12 @@ namespace MoonlightServers.ApiServer.Database.Migrations
},
constraints: table =>
{
table.PrimaryKey("PK_Servers_Stars", x => x.Id);
table.PrimaryKey("PK_Stars", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Servers_Servers",
name: "Servers",
schema: "servers",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
@@ -73,29 +78,30 @@ namespace MoonlightServers.ApiServer.Database.Migrations
DockerImageIndex = table.Column<int>(type: "integer", nullable: false),
Cpu = table.Column<int>(type: "integer", nullable: false),
Memory = table.Column<int>(type: "integer", nullable: false),
Disk = table.Column<int>(type: "integer", nullable: false),
UseVirtualDisk = table.Column<bool>(type: "boolean", nullable: false),
Bandwidth = table.Column<int>(type: "integer", nullable: false)
Disk = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Servers_Servers", x => x.Id);
table.PrimaryKey("PK_Servers", x => x.Id);
table.ForeignKey(
name: "FK_Servers_Servers_Servers_Nodes_NodeId",
name: "FK_Servers_Nodes_NodeId",
column: x => x.NodeId,
principalTable: "Servers_Nodes",
principalSchema: "servers",
principalTable: "Nodes",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Servers_Servers_Servers_Stars_StarId",
name: "FK_Servers_Stars_StarId",
column: x => x.StarId,
principalTable: "Servers_Stars",
principalSchema: "servers",
principalTable: "Stars",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Servers_StarDockerImages",
name: "StarDockerImages",
schema: "servers",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
@@ -107,17 +113,19 @@ namespace MoonlightServers.ApiServer.Database.Migrations
},
constraints: table =>
{
table.PrimaryKey("PK_Servers_StarDockerImages", x => x.Id);
table.PrimaryKey("PK_StarDockerImages", x => x.Id);
table.ForeignKey(
name: "FK_Servers_StarDockerImages_Servers_Stars_StarId",
name: "FK_StarDockerImages_Stars_StarId",
column: x => x.StarId,
principalTable: "Servers_Stars",
principalSchema: "servers",
principalTable: "Stars",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Servers_StarVariables",
name: "StarVariables",
schema: "servers",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
@@ -134,17 +142,19 @@ namespace MoonlightServers.ApiServer.Database.Migrations
},
constraints: table =>
{
table.PrimaryKey("PK_Servers_StarVariables", x => x.Id);
table.PrimaryKey("PK_StarVariables", x => x.Id);
table.ForeignKey(
name: "FK_Servers_StarVariables_Servers_Stars_StarId",
name: "FK_StarVariables_Stars_StarId",
column: x => x.StarId,
principalTable: "Servers_Stars",
principalSchema: "servers",
principalTable: "Stars",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Servers_Allocations",
name: "Allocations",
schema: "servers",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
@@ -156,22 +166,25 @@ namespace MoonlightServers.ApiServer.Database.Migrations
},
constraints: table =>
{
table.PrimaryKey("PK_Servers_Allocations", x => x.Id);
table.PrimaryKey("PK_Allocations", x => x.Id);
table.ForeignKey(
name: "FK_Servers_Allocations_Servers_Nodes_NodeId",
name: "FK_Allocations_Nodes_NodeId",
column: x => x.NodeId,
principalTable: "Servers_Nodes",
principalSchema: "servers",
principalTable: "Nodes",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Servers_Allocations_Servers_Servers_ServerId",
name: "FK_Allocations_Servers_ServerId",
column: x => x.ServerId,
principalTable: "Servers_Servers",
principalSchema: "servers",
principalTable: "Servers",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "Servers_ServerBackups",
name: "ServerBackups",
schema: "servers",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
@@ -185,16 +198,43 @@ namespace MoonlightServers.ApiServer.Database.Migrations
},
constraints: table =>
{
table.PrimaryKey("PK_Servers_ServerBackups", x => x.Id);
table.PrimaryKey("PK_ServerBackups", x => x.Id);
table.ForeignKey(
name: "FK_Servers_ServerBackups_Servers_Servers_ServerId",
name: "FK_ServerBackups_Servers_ServerId",
column: x => x.ServerId,
principalTable: "Servers_Servers",
principalSchema: "servers",
principalTable: "Servers",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "Servers_ServerVariables",
name: "ServerShares",
schema: "servers",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
UserId = table.Column<int>(type: "integer", nullable: false),
ServerId = table.Column<int>(type: "integer", nullable: false),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
Content = table.Column<string>(type: "jsonb", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ServerShares", x => x.Id);
table.ForeignKey(
name: "FK_ServerShares_Servers_ServerId",
column: x => x.ServerId,
principalSchema: "servers",
principalTable: "Servers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "ServerVariables",
schema: "servers",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
@@ -205,53 +245,68 @@ namespace MoonlightServers.ApiServer.Database.Migrations
},
constraints: table =>
{
table.PrimaryKey("PK_Servers_ServerVariables", x => x.Id);
table.PrimaryKey("PK_ServerVariables", x => x.Id);
table.ForeignKey(
name: "FK_Servers_ServerVariables_Servers_Servers_ServerId",
name: "FK_ServerVariables_Servers_ServerId",
column: x => x.ServerId,
principalTable: "Servers_Servers",
principalSchema: "servers",
principalTable: "Servers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Servers_Allocations_NodeId",
table: "Servers_Allocations",
name: "IX_Allocations_NodeId",
schema: "servers",
table: "Allocations",
column: "NodeId");
migrationBuilder.CreateIndex(
name: "IX_Servers_Allocations_ServerId",
table: "Servers_Allocations",
name: "IX_Allocations_ServerId",
schema: "servers",
table: "Allocations",
column: "ServerId");
migrationBuilder.CreateIndex(
name: "IX_Servers_ServerBackups_ServerId",
table: "Servers_ServerBackups",
name: "IX_ServerBackups_ServerId",
schema: "servers",
table: "ServerBackups",
column: "ServerId");
migrationBuilder.CreateIndex(
name: "IX_Servers_Servers_NodeId",
table: "Servers_Servers",
name: "IX_Servers_NodeId",
schema: "servers",
table: "Servers",
column: "NodeId");
migrationBuilder.CreateIndex(
name: "IX_Servers_Servers_StarId",
table: "Servers_Servers",
name: "IX_Servers_StarId",
schema: "servers",
table: "Servers",
column: "StarId");
migrationBuilder.CreateIndex(
name: "IX_Servers_ServerVariables_ServerId",
table: "Servers_ServerVariables",
name: "IX_ServerShares_ServerId",
schema: "servers",
table: "ServerShares",
column: "ServerId");
migrationBuilder.CreateIndex(
name: "IX_Servers_StarDockerImages_StarId",
table: "Servers_StarDockerImages",
name: "IX_ServerVariables_ServerId",
schema: "servers",
table: "ServerVariables",
column: "ServerId");
migrationBuilder.CreateIndex(
name: "IX_StarDockerImages_StarId",
schema: "servers",
table: "StarDockerImages",
column: "StarId");
migrationBuilder.CreateIndex(
name: "IX_Servers_StarVariables_StarId",
table: "Servers_StarVariables",
name: "IX_StarVariables_StarId",
schema: "servers",
table: "StarVariables",
column: "StarId");
}
@@ -259,28 +314,40 @@ namespace MoonlightServers.ApiServer.Database.Migrations
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Servers_Allocations");
name: "Allocations",
schema: "servers");
migrationBuilder.DropTable(
name: "Servers_ServerBackups");
name: "ServerBackups",
schema: "servers");
migrationBuilder.DropTable(
name: "Servers_ServerVariables");
name: "ServerShares",
schema: "servers");
migrationBuilder.DropTable(
name: "Servers_StarDockerImages");
name: "ServerVariables",
schema: "servers");
migrationBuilder.DropTable(
name: "Servers_StarVariables");
name: "StarDockerImages",
schema: "servers");
migrationBuilder.DropTable(
name: "Servers_Servers");
name: "StarVariables",
schema: "servers");
migrationBuilder.DropTable(
name: "Servers_Nodes");
name: "Servers",
schema: "servers");
migrationBuilder.DropTable(
name: "Servers_Stars");
name: "Nodes",
schema: "servers");
migrationBuilder.DropTable(
name: "Stars",
schema: "servers");
}
}
}

View File

@@ -17,7 +17,8 @@ namespace MoonlightServers.ApiServer.Database.Migrations
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "9.0.5")
.HasDefaultSchema("servers")
.HasAnnotation("ProductVersion", "9.0.9")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
@@ -49,7 +50,7 @@ namespace MoonlightServers.ApiServer.Database.Migrations
b.HasIndex("ServerId");
b.ToTable("Servers_Allocations", (string)null);
b.ToTable("Allocations", "servers");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Node", b =>
@@ -60,12 +61,6 @@ namespace MoonlightServers.ApiServer.Database.Migrations
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<bool>("EnableDynamicFirewall")
.HasColumnType("boolean");
b.Property<bool>("EnableTransparentMode")
.HasColumnType("boolean");
b.Property<string>("Fqdn")
.IsRequired()
.HasColumnType("text");
@@ -93,7 +88,7 @@ namespace MoonlightServers.ApiServer.Database.Migrations
b.HasKey("Id");
b.ToTable("Servers_Nodes", (string)null);
b.ToTable("Nodes", "servers");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Server", b =>
@@ -104,9 +99,6 @@ namespace MoonlightServers.ApiServer.Database.Migrations
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("Bandwidth")
.HasColumnType("integer");
b.Property<int>("Cpu")
.HasColumnType("integer");
@@ -135,16 +127,13 @@ namespace MoonlightServers.ApiServer.Database.Migrations
b.Property<string>("StartupOverride")
.HasColumnType("text");
b.Property<bool>("UseVirtualDisk")
.HasColumnType("boolean");
b.HasKey("Id");
b.HasIndex("NodeId");
b.HasIndex("StarId");
b.ToTable("Servers_Servers", (string)null);
b.ToTable("Servers", "servers");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.ServerBackup", b =>
@@ -177,7 +166,7 @@ namespace MoonlightServers.ApiServer.Database.Migrations
b.HasIndex("ServerId");
b.ToTable("Servers_ServerBackups", (string)null);
b.ToTable("ServerBackups", "servers");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.ServerShare", b =>
@@ -204,7 +193,7 @@ namespace MoonlightServers.ApiServer.Database.Migrations
b.HasIndex("ServerId");
b.ToTable("Servers_ServerShares", (string)null);
b.ToTable("ServerShares", "servers");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.ServerVariable", b =>
@@ -230,7 +219,7 @@ namespace MoonlightServers.ApiServer.Database.Migrations
b.HasIndex("ServerId");
b.ToTable("Servers_ServerVariables", (string)null);
b.ToTable("ServerVariables", "servers");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Star", b =>
@@ -298,7 +287,7 @@ namespace MoonlightServers.ApiServer.Database.Migrations
b.HasKey("Id");
b.ToTable("Servers_Stars", (string)null);
b.ToTable("Stars", "servers");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.StarDockerImage", b =>
@@ -327,7 +316,7 @@ namespace MoonlightServers.ApiServer.Database.Migrations
b.HasIndex("StarId");
b.ToTable("Servers_StarDockerImages", (string)null);
b.ToTable("StarDockerImages", "servers");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.StarVariable", b =>
@@ -373,7 +362,7 @@ namespace MoonlightServers.ApiServer.Database.Migrations
b.HasIndex("StarId");
b.ToTable("Servers_StarVariables", (string)null);
b.ToTable("StarVariables", "servers");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Allocation", b =>
@@ -434,14 +423,14 @@ namespace MoonlightServers.ApiServer.Database.Migrations
b1.HasKey("ServerShareId");
b1.ToTable("Servers_ServerShares");
b1.ToTable("ServerShares", "servers");
b1.ToJson("Content");
b1.WithOwner()
.HasForeignKey("ServerShareId");
b1.OwnsMany("MoonlightServers.ApiServer.Models.ServerSharePermission", "Permissions", b2 =>
b1.OwnsMany("MoonlightServers.ApiServer.Models.ServerShareContent+SharePermission", "Permissions", b2 =>
{
b2.Property<int>("ServerShareContentServerShareId")
.HasColumnType("integer");
@@ -450,16 +439,16 @@ namespace MoonlightServers.ApiServer.Database.Migrations
.ValueGeneratedOnAdd()
.HasColumnType("integer");
b2.Property<string>("Name")
b2.Property<string>("Identifier")
.IsRequired()
.HasColumnType("text");
b2.Property<int>("Type")
b2.Property<int>("Level")
.HasColumnType("integer");
b2.HasKey("ServerShareContentServerShareId", "__synthesizedOrdinal");
b2.ToTable("Servers_ServerShares");
b2.ToTable("ServerShares", "servers");
b2.WithOwner()
.HasForeignKey("ServerShareContentServerShareId");

View File

@@ -1,17 +1,12 @@
using System.Text.Json;
using Microsoft.EntityFrameworkCore;
using MoonCore.Extended.SingleDb;
using Moonlight.ApiServer.Configuration;
using MoonlightServers.ApiServer.Database.Entities;
using MoonlightServers.ApiServer.Models;
using MoonlightServers.Shared.Models;
namespace MoonlightServers.ApiServer.Database;
public class ServersDataContext : DatabaseContext
public class ServersDataContext : DbContext
{
public override string Prefix { get; } = "Servers";
public DbSet<Allocation> Allocations { get; set; }
public DbSet<Node> Nodes { get; set; }
public DbSet<Server> Servers { get; set; }
@@ -22,20 +17,37 @@ public class ServersDataContext : DatabaseContext
public DbSet<StarDockerImage> StarDockerImages { get; set; }
public DbSet<StarVariable> StarVariables { get; set; }
private readonly AppConfiguration Configuration;
private readonly string Schema = "servers";
public ServersDataContext(AppConfiguration configuration)
{
Options = new()
Configuration = configuration;
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if(optionsBuilder.IsConfigured)
return;
var database = Configuration.Database;
var connectionString = $"Host={database.Host};" +
$"Port={database.Port};" +
$"Database={database.Database};" +
$"Username={database.Username};" +
$"Password={database.Password}";
optionsBuilder.UseNpgsql(connectionString, builder =>
{
Host = configuration.Database.Host,
Port = configuration.Database.Port,
Username = configuration.Database.Username,
Password = configuration.Database.Password,
Database = configuration.Database.Database
};
builder.MigrationsHistoryTable("MigrationsHistory", Schema);
});
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Model.SetDefaultSchema(Schema);
base.OnModelCreating(modelBuilder);
#region Shares

View File

@@ -1,5 +1,3 @@
using MoonlightServers.DaemonShared.Enums;
using MoonlightServers.Shared.Enums;
using ServerState = MoonlightServers.Shared.Enums.ServerState;
namespace MoonlightServers.ApiServer.Extensions;

View File

@@ -1,9 +1,7 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using MoonCore.Exceptions;
using MoonCore.Extended.Abstractions;
using MoonCore.Extended.Models;
using MoonCore.Models;
using MoonlightServers.ApiServer.Database.Entities;
using MoonlightServers.ApiServer.Mappers;
@@ -30,38 +28,39 @@ public class NodeAllocationsController : Controller
[HttpGet]
[Authorize(Policy = "permissions:admin.servers.nodes.get")]
public async Task<ActionResult<IPagedData<NodeAllocationResponse>>> Get(
public async Task<ActionResult<CountedData<NodeAllocationResponse>>> GetAsync(
[FromRoute] int nodeId,
[FromQuery] PagedOptions options
[FromQuery] int startIndex,
[FromQuery] int count
)
{
var count = await AllocationRepository
if (count > 100)
return Problem("Only 100 items can be fetched at a time", statusCode: 400);
var totalCount = await AllocationRepository
.Get()
.CountAsync(x => x.Node.Id == nodeId);
var allocations = await AllocationRepository
.Get()
.OrderBy(x => x.Id)
.Skip(options.Page * options.PageSize)
.Take(options.PageSize)
.Skip(startIndex)
.Take(count)
.Where(x => x.Node.Id == nodeId)
.AsNoTracking()
.ProjectToAdminResponse()
.ToArrayAsync();
return new PagedData<NodeAllocationResponse>()
return new CountedData<NodeAllocationResponse>()
{
Items = allocations,
CurrentPage = options.Page,
PageSize = options.PageSize,
TotalItems = count,
TotalPages = (int)Math.Ceiling(Math.Max(0, count) / (double)options.PageSize)
TotalCount = totalCount
};
}
[HttpGet("{id:int}")]
[Authorize(Policy = "permissions:admin.servers.nodes.get")]
public async Task<ActionResult<NodeAllocationResponse>> GetSingle([FromRoute] int nodeId, [FromRoute] int id)
public async Task<ActionResult<NodeAllocationResponse>> GetSingleAsync([FromRoute] int nodeId, [FromRoute] int id)
{
var allocation = await AllocationRepository
.Get()
@@ -78,7 +77,7 @@ public class NodeAllocationsController : Controller
[HttpPost]
[Authorize(Policy = "permissions:admin.servers.nodes.create")]
public async Task<ActionResult<NodeAllocationResponse>> Create(
public async Task<ActionResult<NodeAllocationResponse>> CreateAsync(
[FromRoute] int nodeId,
[FromBody] CreateNodeAllocationRequest request
)
@@ -92,13 +91,13 @@ public class NodeAllocationsController : Controller
var allocation = AllocationMapper.ToAllocation(request);
var finalAllocation = await AllocationRepository.Add(allocation);
var finalAllocation = await AllocationRepository.AddAsync(allocation);
return AllocationMapper.ToNodeAllocation(finalAllocation);
}
[HttpPatch("{id:int}")]
public async Task<ActionResult<NodeAllocationResponse>> Update(
public async Task<ActionResult<NodeAllocationResponse>> UpdateAsync(
[FromRoute] int nodeId,
[FromRoute] int id,
[FromBody] UpdateNodeAllocationRequest request
@@ -113,13 +112,13 @@ public class NodeAllocationsController : Controller
return Problem("No allocation with that id found", statusCode: 404);
AllocationMapper.Merge(request, allocation);
await AllocationRepository.Update(allocation);
await AllocationRepository.UpdateAsync(allocation);
return AllocationMapper.ToNodeAllocation(allocation);
}
[HttpDelete("{id:int}")]
public async Task<ActionResult> Delete([FromRoute] int nodeId, [FromRoute] int id)
public async Task<ActionResult> DeleteAsync([FromRoute] int nodeId, [FromRoute] int id)
{
var allocation = await AllocationRepository
.Get()
@@ -129,12 +128,12 @@ public class NodeAllocationsController : Controller
if (allocation == null)
return Problem("No allocation with that id found", statusCode: 404);
await AllocationRepository.Remove(allocation);
await AllocationRepository.RemoveAsync(allocation);
return NoContent();
}
[HttpPost("range")]
public async Task<ActionResult> CreateRange(
public async Task<ActionResult> CreateRangeAsync(
[FromRoute] int nodeId,
[FromBody] CreateNodeAllocationRangeRequest request
)
@@ -179,58 +178,60 @@ public class NodeAllocationsController : Controller
})
.ToArray();
await AllocationRepository.RunTransaction(async set => { await set.AddRangeAsync(allocations); });
await AllocationRepository.RunTransactionAsync(async set => { await set.AddRangeAsync(allocations); });
return NoContent();
}
[HttpDelete("all")]
public async Task<ActionResult> DeleteAll([FromRoute] int nodeId)
public async Task<ActionResult> DeleteAllAsync([FromRoute] int nodeId)
{
var allocations = AllocationRepository
.Get()
.Where(x => x.Node.Id == nodeId)
.ToArray();
await AllocationRepository.RunTransaction(set => { set.RemoveRange(allocations); });
await AllocationRepository.RunTransactionAsync(set => { set.RemoveRange(allocations); });
return NoContent();
}
[HttpGet("free")]
[Authorize(Policy = "permissions:admin.servers.nodes.get")]
public async Task<IPagedData<NodeAllocationResponse>> GetFree(
public async Task<ActionResult<CountedData<NodeAllocationResponse>>> GetFreeAsync(
[FromRoute] int nodeId,
[FromQuery] PagedOptions options,
[FromQuery] int startIndex,
[FromQuery] int count,
[FromQuery] int serverId = -1
)
{
if (count > 100)
return Problem("Only 100 items can be fetched at a time", statusCode: 400);
var node = NodeRepository
.Get()
.FirstOrDefault(x => x.Id == nodeId);
if (node == null)
throw new HttpApiException("A node with this id could not be found", 404);
return Problem("A node with this id could not be found", statusCode: 404);
var freeAllocationsQuery = AllocationRepository
.Get()
.OrderBy(x => x.Id)
.Where(x => x.Node.Id == node.Id)
.Where(x => x.Server == null || x.Server.Id == serverId);
var count = await freeAllocationsQuery.CountAsync();
var totalCount = await freeAllocationsQuery.CountAsync();
var allocations = await freeAllocationsQuery
.Skip(options.Page * options.PageSize)
.Take(options.PageSize)
.Skip(startIndex)
.Take(count)
.AsNoTracking()
.ProjectToAdminResponse()
.ToArrayAsync();
return new PagedData<NodeAllocationResponse>()
return new CountedData<NodeAllocationResponse>()
{
Items = allocations,
CurrentPage = options.Page,
PageSize = options.PageSize,
TotalItems = count,
TotalPages = (int)Math.Ceiling(Math.Max(0, count) / (double)options.PageSize)
TotalCount = totalCount
};
}
}

View File

@@ -1,6 +1,5 @@
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using MoonCore.Exceptions;
using MoonCore.Extended.Abstractions;
using Microsoft.AspNetCore.Authorization;
using Microsoft.EntityFrameworkCore;
@@ -25,9 +24,9 @@ public class NodeStatusController : Controller
[HttpGet("{nodeId:int}/system/status")]
[Authorize(Policy = "permissions:admin.servers.nodes.status")]
public async Task<ActionResult<NodeSystemStatusResponse>> GetStatus([FromRoute] int nodeId)
public async Task<ActionResult<NodeSystemStatusResponse>> GetStatusAsync([FromRoute] int nodeId)
{
var node = await GetNode(nodeId);
var node = await GetNodeAsync(nodeId);
if (node.Value == null)
return node.Result ?? Problem("Unable to retrieve node");
@@ -39,7 +38,7 @@ public class NodeStatusController : Controller
try
{
var statusResponse = await NodeService.GetSystemStatus(node.Value);
var statusResponse = await NodeService.GetSystemStatusAsync(node.Value);
sw.Stop();
@@ -69,7 +68,7 @@ public class NodeStatusController : Controller
return response;
}
private async Task<ActionResult<Node>> GetNode(int nodeId)
private async Task<ActionResult<Node>> GetNodeAsync(int nodeId)
{
var result = await NodeRepository
.Get()

View File

@@ -1,10 +1,7 @@
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using MoonCore.Extended.Abstractions;
using Microsoft.AspNetCore.Authorization;
using MoonCore.Exceptions;
using MoonCore.Extended.Models;
using MoonCore.Helpers;
using MoonCore.Models;
using MoonlightServers.ApiServer.Database.Entities;
@@ -27,32 +24,35 @@ public class NodesController : Controller
[HttpGet]
[Authorize(Policy = "permissions:admin.servers.nodes.get")]
public async Task<IPagedData<NodeResponse>> Get([FromQuery] PagedOptions options)
public async Task<ActionResult<CountedData<NodeResponse>>> GetAsync(
[FromQuery] int startIndex,
[FromQuery] int count
)
{
var count = await NodeRepository.Get().CountAsync();
if (count > 100)
return Problem("Only 100 items can be fetched at a time", statusCode: 400);
var totalCount = await NodeRepository.Get().CountAsync();
var items = await NodeRepository
.Get()
.OrderBy(x => x.Id)
.Skip(options.Page * options.PageSize)
.Take(options.PageSize)
.Skip(startIndex)
.Take(count)
.AsNoTracking()
.ProjectToAdminResponse()
.ToArrayAsync();
return new PagedData<NodeResponse>()
return new CountedData<NodeResponse>()
{
Items = items,
CurrentPage = options.Page,
PageSize = options.PageSize,
TotalItems = count,
TotalPages = (int)Math.Ceiling(Math.Max(0, count) / (double)options.PageSize)
TotalCount = totalCount
};
}
[HttpGet("{id:int}")]
[Authorize(Policy = "permissions:admin.servers.nodes.get")]
public async Task<ActionResult<NodeResponse>> GetSingle([FromRoute] int id)
public async Task<ActionResult<NodeResponse>> GetSingleAsync([FromRoute] int id)
{
var node = await NodeRepository
.Get()
@@ -68,21 +68,21 @@ public class NodesController : Controller
[HttpPost]
[Authorize(Policy = "permissions:admin.servers.nodes.create")]
public async Task<ActionResult<NodeResponse>> Create([FromBody] CreateNodeRequest request)
public async Task<ActionResult<NodeResponse>> CreateAsync([FromBody] CreateNodeRequest request)
{
var node = NodeMapper.ToNode(request);
node.TokenId = Formatter.GenerateString(6);
node.Token = Formatter.GenerateString(32);
var finalNode = await NodeRepository.Add(node);
var finalNode = await NodeRepository.AddAsync(node);
return NodeMapper.ToAdminNodeResponse(finalNode);
}
[HttpPatch("{id:int}")]
[Authorize(Policy = "permissions:admin.servers.nodes.update")]
public async Task<ActionResult<NodeResponse>> Update([FromRoute] int id, [FromBody] UpdateNodeRequest request)
public async Task<ActionResult<NodeResponse>> UpdateAsync([FromRoute] int id, [FromBody] UpdateNodeRequest request)
{
var node = await NodeRepository
.Get()
@@ -92,14 +92,14 @@ public class NodesController : Controller
return Problem("No node with this id found", statusCode: 404);
NodeMapper.Merge(request, node);
await NodeRepository.Update(node);
await NodeRepository.UpdateAsync(node);
return NodeMapper.ToAdminNodeResponse(node);
}
[HttpDelete("{id:int}")]
[Authorize(Policy = "permissions:admin.servers.nodes.delete")]
public async Task<ActionResult> Delete([FromRoute] int id)
public async Task<ActionResult> DeleteAsync([FromRoute] int id)
{
var node = await NodeRepository
.Get()
@@ -108,7 +108,7 @@ public class NodesController : Controller
if (node == null)
return Problem("No node with this id found", statusCode: 404);
await NodeRepository.Remove(node);
await NodeRepository.RemoveAsync(node);
return Ok();
}
}

View File

@@ -2,7 +2,6 @@ using System.Diagnostics.CodeAnalysis;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using MoonCore.Exceptions;
using MoonCore.Extended.Abstractions;
using MoonlightServers.ApiServer.Database.Entities;
using MoonlightServers.ApiServer.Services;
@@ -27,14 +26,14 @@ public class StatisticsController : Controller
[HttpGet]
[SuppressMessage("ReSharper.DPA", "DPA0011: High execution time of MVC action", MessageId = "time: 1142ms",
Justification = "The daemon has an artificial delay of one second to calculate accurate cpu usage values")]
public async Task<ActionResult<StatisticsResponse>> Get([FromRoute] int nodeId)
public async Task<ActionResult<StatisticsResponse>> GetAsync([FromRoute] int nodeId)
{
var node = await GetNode(nodeId);
var node = await GetNodeAsync(nodeId);
if (node.Value == null)
return node.Result ?? Problem("Unable to retrieve node");
var statistics = await NodeService.GetStatistics(node.Value);
var statistics = await NodeService.GetStatisticsAsync(node.Value);
return new StatisticsResponse()
{
@@ -66,14 +65,14 @@ public class StatisticsController : Controller
}
[HttpGet("docker")]
public async Task<ActionResult<DockerStatisticsResponse>> GetDocker([FromRoute] int nodeId)
public async Task<ActionResult<DockerStatisticsResponse>> GetDockerAsync([FromRoute] int nodeId)
{
var node = await GetNode(nodeId);
var node = await GetNodeAsync(nodeId);
if (node.Value == null)
return node.Result ?? Problem("Unable to retrieve node");
var statistics = await NodeService.GetDockerStatistics(node.Value);
var statistics = await NodeService.GetDockerStatisticsAsync(node.Value);
return new DockerStatisticsResponse()
{
@@ -87,7 +86,7 @@ public class StatisticsController : Controller
};
}
private async Task<ActionResult<Node>> GetNode(int nodeId)
private async Task<ActionResult<Node>> GetNodeAsync(int nodeId)
{
var result = await NodeRepository
.Get()

View File

@@ -1,10 +1,7 @@
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Authorization;
using MoonCore.Exceptions;
using MoonCore.Extended.Abstractions;
using MoonCore.Extended.Models;
using MoonCore.Models;
using MoonlightServers.ApiServer.Database.Entities;
using MoonlightServers.ApiServer.Mappers;
@@ -30,11 +27,15 @@ public class ServerVariablesController : Controller
[HttpGet("{serverId:int}/variables")]
[Authorize(Policy = "permissions:admin.servers.read")]
public async Task<ActionResult<PagedData<ServerVariableResponse>>> Get(
public async Task<ActionResult<CountedData<ServerVariableResponse>>> GetAsync(
[FromRoute] int serverId,
[FromQuery] PagedOptions options
[FromQuery] int startIndex,
[FromQuery] int count
)
{
if (count > 100)
return Problem("Only 100 items can be fetched at a time", statusCode: 400);
var serverExists = await ServerRepository
.Get()
.AnyAsync(x => x.Id == serverId);
@@ -46,23 +47,20 @@ public class ServerVariablesController : Controller
.Get()
.Where(x => x.Server.Id == serverId);
var count = await query.CountAsync();
var totalCount = await query.CountAsync();
var variables = await query
.OrderBy(x => x.Id)
.Skip(options.Page * options.PageSize)
.Take(options.PageSize)
.Skip(startIndex)
.Take(count)
.AsNoTracking()
.ProjectToAdminResponse()
.ToArrayAsync();
return new PagedData<ServerVariableResponse>()
return new CountedData<ServerVariableResponse>()
{
Items = variables,
CurrentPage = options.Page,
PageSize = options.PageSize,
TotalItems = count,
TotalPages = (int)Math.Ceiling(Math.Max(0, count) / (double)options.PageSize)
TotalCount = totalCount
};
}
}

View File

@@ -1,13 +1,8 @@
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.Logging;
using MoonCore.Exceptions;
using MoonCore.Extended.Abstractions;
using MoonCore.Extended.Helpers;
using MoonCore.Extended.Models;
using MoonCore.Helpers;
using MoonCore.Models;
using Moonlight.ApiServer.Database.Entities;
using MoonlightServers.ApiServer.Database.Entities;
@@ -54,9 +49,15 @@ public class ServersController : Controller
[HttpGet]
[Authorize(Policy = "permissions:admin.servers.read")]
public async Task<ActionResult<IPagedData<ServerResponse>>> Get([FromQuery] PagedOptions options)
public async Task<ActionResult<CountedData<ServerResponse>>> GetAsync(
[FromQuery] int startIndex,
[FromQuery] int count
)
{
var count = await ServerRepository.Get().CountAsync();
if (count > 100)
return Problem("Only 100 items can be fetched at a time", statusCode: 400);
var totalCount = await ServerRepository.Get().CountAsync();
var servers = await ServerRepository
.Get()
@@ -65,25 +66,22 @@ public class ServersController : Controller
.Include(x => x.Variables)
.Include(x => x.Star)
.OrderBy(x => x.Id)
.Skip(options.Page * options.PageSize)
.Take(options.PageSize)
.Skip(startIndex)
.Take(count)
.AsNoTracking()
.ProjectToAdminResponse()
.ToArrayAsync();
return new PagedData<ServerResponse>()
return new CountedData<ServerResponse>()
{
Items = servers,
CurrentPage = options.Page,
PageSize = options.PageSize,
TotalItems = count,
TotalPages = (int)Math.Ceiling(Math.Max(0, count) / (double)options.PageSize)
TotalCount = totalCount
};
}
[HttpGet("{id:int}")]
[Authorize(Policy = "permissions:admin.servers.read")]
public async Task<ActionResult<ServerResponse>> GetSingle([FromRoute] int id)
public async Task<ActionResult<ServerResponse>> GetSingleAsync([FromRoute] int id)
{
var server = await ServerRepository
.Get()
@@ -104,7 +102,7 @@ public class ServersController : Controller
[HttpPost]
[Authorize(Policy = "permissions:admin.servers.write")]
public async Task<ActionResult<ServerResponse>> Create([FromBody] CreateServerRequest request)
public async Task<ActionResult<ServerResponse>> CreateAsync([FromBody] CreateServerRequest request)
{
// Check if owner user exist
if (UserRepository.Get().All(x => x.Id != request.OwnerId))
@@ -192,11 +190,11 @@ public class ServersController : Controller
server.Node = node;
server.Star = star;
var finalServer = await ServerRepository.Add(server);
var finalServer = await ServerRepository.AddAsync(server);
try
{
await ServerService.Sync(finalServer);
await ServerService.SyncAsync(finalServer);
}
catch (Exception e)
{
@@ -204,7 +202,7 @@ public class ServersController : Controller
// We are deleting the server from the database after the creation has failed
// to ensure we won't have a bugged server in the database which doesn't exist on the node
await ServerRepository.Remove(finalServer);
await ServerRepository.RemoveAsync(finalServer);
throw;
}
@@ -214,7 +212,10 @@ public class ServersController : Controller
[HttpPatch("{id:int}")]
[Authorize(Policy = "permissions:admin.servers.write")]
public async Task<ActionResult<ServerResponse>> Update([FromRoute] int id, [FromBody] UpdateServerRequest request)
public async Task<ActionResult<ServerResponse>> UpdateAsync(
[FromRoute] int id,
[FromBody] UpdateServerRequest request
)
{
//TODO: Handle shrinking virtual disk
@@ -277,16 +278,16 @@ public class ServersController : Controller
serverVar.Value = variable.Value;
}
await ServerRepository.Update(server);
await ServerRepository.UpdateAsync(server);
// Notify the node about the changes
await ServerService.Sync(server);
await ServerService.SyncAsync(server);
return ServerMapper.ToAdminServerResponse(server);
}
[HttpDelete("{id:int}")]
public async Task<ActionResult> Delete([FromRoute] int id, [FromQuery] bool force = false)
public async Task<ActionResult> DeleteAsync([FromRoute] int id, [FromQuery] bool force = false)
{
var server = await ServerRepository
.Get()
@@ -308,7 +309,7 @@ public class ServersController : Controller
{
// If the sync fails on the node and we aren't forcing the deletion,
// we don't want to delete it from the database yet
await ServerService.SyncDelete(server);
await ServerService.SyncDeleteAsync(server);
}
catch (Exception e)
{
@@ -323,7 +324,7 @@ public class ServersController : Controller
throw;
}
await ServerRepository.Remove(server);
await ServerRepository.RemoveAsync(server);
return NoContent();
}
}

View File

@@ -1,12 +1,7 @@
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using MoonCore.Exceptions;
using MoonCore.Extended.Abstractions;
using MoonCore.Extended.Helpers;
using Microsoft.AspNetCore.Authorization;
using MoonCore.Extended.Models;
using MoonCore.Helpers;
using MoonCore.Models;
using MoonlightServers.ApiServer.Database.Entities;
using MoonlightServers.ApiServer.Mappers;
@@ -33,9 +28,10 @@ public class StarDockerImagesController : Controller
[HttpGet]
[Authorize(Policy = "permissions:admin.servers.stars.get")]
public async Task<ActionResult<IPagedData<StarDockerImageResponse>>> Get(
public async Task<ActionResult<CountedData<StarDockerImageResponse>>> GetAsync(
[FromRoute] int starId,
[FromQuery] PagedOptions options
[FromQuery] int startIndex,
[FromQuery] int count
)
{
var starExists = StarRepository
@@ -49,29 +45,26 @@ public class StarDockerImagesController : Controller
.Get()
.Where(x => x.Star.Id == starId);
var count = await query.CountAsync();
var totalCount = await query.CountAsync();
var dockerImages = await query
.OrderBy(x => x.Id)
.Skip(options.Page * options.PageSize)
.Take(options.PageSize)
.Skip(startIndex)
.Take(count)
.AsNoTracking()
.ProjectToAdminResponse()
.ToArrayAsync();
return new PagedData<StarDockerImageResponse>()
return new CountedData<StarDockerImageResponse>()
{
Items = dockerImages,
CurrentPage = options.Page,
PageSize = options.PageSize,
TotalItems = count,
TotalPages = (int)Math.Ceiling(Math.Max(0, count) / (double)options.PageSize)
TotalCount = totalCount
};
}
[HttpGet("{id:int}")]
[Authorize(Policy = "permissions:admin.servers.stars.read")]
public async Task<ActionResult<StarDockerImageResponse>> GetSingle([FromRoute] int starId, [FromRoute] int id)
public async Task<ActionResult<StarDockerImageResponse>> GetSingleAsync([FromRoute] int starId, [FromRoute] int id)
{
var starExists = StarRepository
.Get()
@@ -94,7 +87,7 @@ public class StarDockerImagesController : Controller
[HttpPost]
[Authorize(Policy = "permissions:admin.servers.stars.write")]
public async Task<ActionResult<StarDockerImageResponse>> Create(
public async Task<ActionResult<StarDockerImageResponse>> CreateAsync(
[FromRoute] int starId,
[FromBody] CreateStarDockerImageRequest request
)
@@ -109,14 +102,14 @@ public class StarDockerImagesController : Controller
var dockerImage = DockerImageMapper.ToDockerImage(request);
dockerImage.Star = star;
var finalDockerImage = await DockerImageRepository.Add(dockerImage);
var finalDockerImage = await DockerImageRepository.AddAsync(dockerImage);
return DockerImageMapper.ToAdminResponse(finalDockerImage);
}
[HttpPatch("{id:int}")]
[Authorize(Policy = "permissions:admin.servers.stars.write")]
public async Task<ActionResult<StarDockerImageResponse>> Update(
public async Task<ActionResult<StarDockerImageResponse>> UpdateAsync(
[FromRoute] int starId,
[FromRoute] int id,
[FromBody] UpdateStarDockerImageRequest request
@@ -137,14 +130,14 @@ public class StarDockerImagesController : Controller
return Problem("No star docker image with this id found", statusCode: 404);
DockerImageMapper.Merge(request, dockerImage);
await DockerImageRepository.Update(dockerImage);
await DockerImageRepository.UpdateAsync(dockerImage);
return DockerImageMapper.ToAdminResponse(dockerImage);
}
[HttpDelete("{id:int}")]
[Authorize(Policy = "permissions:admin.servers.stars.write")]
public async Task<ActionResult> Delete([FromRoute] int starId, [FromRoute] int id)
public async Task<ActionResult> DeleteAsync([FromRoute] int starId, [FromRoute] int id)
{
var starExists = StarRepository
.Get()
@@ -160,7 +153,7 @@ public class StarDockerImagesController : Controller
if (dockerImage == null)
return Problem("No star docker image with this id found", statusCode: 404);
await DockerImageRepository.Remove(dockerImage);
await DockerImageRepository.RemoveAsync(dockerImage);
return NoContent();
}
}

View File

@@ -1,9 +1,7 @@
using System.Text;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using MoonCore.Exceptions;
using MoonCore.Helpers;
using MoonlightServers.ApiServer.Mappers;
using MoonlightServers.ApiServer.Services;
using MoonlightServers.Shared.Http.Responses.Admin.Stars;
@@ -23,15 +21,15 @@ public class StarImportExportController : Controller
[HttpGet("{starId:int}/export")]
[Authorize(Policy = "permissions:admin.servers.stars.get")]
public async Task<ActionResult> Export([FromRoute] int starId)
public async Task<ActionResult> ExportAsync([FromRoute] int starId)
{
var exportedStar = await ImportExportService.Export(starId);
var exportedStar = await ImportExportService.ExportAsync(starId);
return Content(exportedStar, "application/json");
}
[HttpPost("import")]
[Authorize(Policy = "permissions:admin.servers.stars.create")]
public async Task<StarResponse> Import()
public async Task<StarResponse> ImportAsync()
{
if (Request.Form.Files.Count == 0)
throw new HttpApiException("No file to import provided", 400);
@@ -44,7 +42,7 @@ public class StarImportExportController : Controller
using var sr = new StreamReader(stream, Encoding.UTF8);
var content = await sr.ReadToEndAsync();
var star = await ImportExportService.Import(content);
var star = await ImportExportService.ImportAsync(content);
return StarMapper.ToAdminResponse(star);
}

View File

@@ -1,10 +1,8 @@
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Authorization;
using MoonCore.Exceptions;
using MoonCore.Extended.Abstractions;
using MoonCore.Extended.Models;
using MoonCore.Models;
using MoonlightServers.ApiServer.Database.Entities;
using MoonlightServers.ApiServer.Mappers;
@@ -30,11 +28,15 @@ public class StarVariablesController : Controller
[HttpGet]
[Authorize(Policy = "permissions:admin.servers.stars.get")]
public async Task<ActionResult<IPagedData<StarVariableResponse>>> Get(
public async Task<ActionResult<CountedData<StarVariableResponse>>> GetAsync(
[FromRoute] int starId,
[FromQuery] PagedOptions options
[FromQuery] int startIndex,
[FromQuery] int count
)
{
if (count > 100)
return Problem("Only 100 items can be fetched at a time", statusCode: 400);
var starExists = StarRepository
.Get()
.Any(x => x.Id == starId);
@@ -46,29 +48,26 @@ public class StarVariablesController : Controller
.Get()
.Where(x => x.Star.Id == starId);
var count = await query.CountAsync();
var totalCount = await query.CountAsync();
var variables = await query
.OrderBy(x => x.Id)
.Skip(options.Page * options.PageSize)
.Take(options.PageSize)
.Skip(startIndex)
.Take(count)
.AsNoTracking()
.ProjectToAdminResponse()
.ToArrayAsync();
return new PagedData<StarVariableResponse>()
return new CountedData<StarVariableResponse>()
{
Items = variables,
CurrentPage = options.Page,
PageSize = options.PageSize,
TotalItems = count,
TotalPages = (int)Math.Ceiling(Math.Max(0, count) / (double)options.PageSize)
TotalCount = totalCount
};
}
[HttpGet("{id:int}")]
[Authorize(Policy = "permissions:admin.servers.stars.get")]
public async Task<StarVariableResponse> GetSingle(
public async Task<StarVariableResponse> GetSingleAsync(
[FromRoute] int starId,
[FromRoute] int id
)
@@ -92,7 +91,7 @@ public class StarVariablesController : Controller
[HttpPost("")]
[Authorize(Policy = "permissions:admin.servers.stars.create")]
public async Task<StarVariableResponse> Create([FromRoute] int starId,
public async Task<StarVariableResponse> CreateAsync([FromRoute] int starId,
[FromBody] CreateStarVariableRequest request)
{
var star = StarRepository
@@ -105,14 +104,14 @@ public class StarVariablesController : Controller
var starVariable = StarVariableMapper.ToStarVariable(request);
starVariable.Star = star;
await VariableRepository.Add(starVariable);
await VariableRepository.AddAsync(starVariable);
return StarVariableMapper.ToAdminResponse(starVariable);
}
[HttpPatch("{id:int}")]
[Authorize(Policy = "permissions:admin.servers.stars.update")]
public async Task<StarVariableResponse> Update(
public async Task<StarVariableResponse> UpdateAsync(
[FromRoute] int starId,
[FromRoute] int id,
[FromBody] UpdateStarVariableRequest request
@@ -133,14 +132,14 @@ public class StarVariablesController : Controller
throw new HttpApiException("No variable with this id found", 404);
StarVariableMapper.Merge(request, starVariable);
await VariableRepository.Update(starVariable);
await VariableRepository.UpdateAsync(starVariable);
return StarVariableMapper.ToAdminResponse(starVariable);
}
[HttpDelete("{id:int}")]
[Authorize(Policy = "permissions:admin.servers.stars.delete")]
public async Task Delete([FromRoute] int starId, [FromRoute] int id)
public async Task DeleteAsync([FromRoute] int starId, [FromRoute] int id)
{
var starExists = StarRepository
.Get()
@@ -156,6 +155,6 @@ public class StarVariablesController : Controller
if (starVariable == null)
throw new HttpApiException("No variable with this id found", 404);
await VariableRepository.Remove(starVariable);
await VariableRepository.RemoveAsync(starVariable);
}
}

View File

@@ -1,10 +1,7 @@
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Authorization;
using MoonCore.Exceptions;
using MoonCore.Extended.Abstractions;
using MoonCore.Extended.Models;
using MoonCore.Models;
using MoonlightServers.ApiServer.Database.Entities;
using MoonlightServers.ApiServer.Mappers;
@@ -26,32 +23,35 @@ public class StarsController : Controller
[HttpGet]
[Authorize(Policy = "permissions:admin.servers.stars.read")]
public async Task<ActionResult<IPagedData<StarResponse>>> Get([FromQuery] PagedOptions options)
public async Task<ActionResult<CountedData<StarResponse>>> GetAsync(
[FromQuery] int startIndex,
[FromQuery] int count
)
{
var count = await StarRepository.Get().CountAsync();
if (count > 100)
return Problem("Only 100 items can be fetched at a time", statusCode: 400);
var totalCount = await StarRepository.Get().CountAsync();
var stars = await StarRepository
.Get()
.OrderBy(x => x.Id)
.Skip(options.Page * options.PageSize)
.Take(options.PageSize)
.Skip(startIndex)
.Take(count)
.AsNoTracking()
.ProjectToAdminResponse()
.ToArrayAsync();
return new PagedData<StarResponse>()
return new CountedData<StarResponse>()
{
CurrentPage = options.Page,
Items = stars,
PageSize = options.PageSize,
TotalItems = count,
TotalPages = (int)Math.Ceiling(Math.Max(0, count) / (double)options.PageSize)
TotalCount = totalCount
};
}
[HttpGet("{id:int}")]
[Authorize(Policy = "permissions:admin.servers.stars.read")]
public async Task<ActionResult<StarResponse>> GetSingle([FromRoute] int id)
public async Task<ActionResult<StarResponse>> GetSingleAsync([FromRoute] int id)
{
var star = await StarRepository
.Get()
@@ -67,7 +67,7 @@ public class StarsController : Controller
[HttpPost]
[Authorize(Policy = "permissions:admin.servers.stars.create")]
public async Task<ActionResult<StarResponse>> Create([FromBody] CreateStarRequest request)
public async Task<ActionResult<StarResponse>> CreateAsync([FromBody] CreateStarRequest request)
{
var star = StarMapper.ToStar(request);
@@ -86,14 +86,14 @@ public class StarsController : Controller
star.DefaultDockerImage = -1;
star.ParseConfiguration = "[]";
var finalStar = await StarRepository.Add(star);
var finalStar = await StarRepository.AddAsync(star);
return StarMapper.ToAdminResponse(finalStar);
}
[HttpPatch("{id:int}")]
[Authorize(Policy = "permissions:admin.servers.stars.update")]
public async Task<ActionResult<StarResponse>> Update(
public async Task<ActionResult<StarResponse>> UpdateAsync(
[FromRoute] int id,
[FromBody] UpdateStarRequest request
)
@@ -106,14 +106,14 @@ public class StarsController : Controller
return Problem("No star with that id found", statusCode: 404);
StarMapper.Merge(request, star);
await StarRepository.Update(star);
await StarRepository.UpdateAsync(star);
return StarMapper.ToAdminResponse(star);
}
[HttpDelete("{id:int}")]
[Authorize(Policy = "permissions:admin.servers.stars.delete")]
public async Task<ActionResult> Delete([FromRoute] int id)
public async Task<ActionResult> DeleteAsync([FromRoute] int id)
{
var star = await StarRepository
.Get()
@@ -122,7 +122,7 @@ public class StarsController : Controller
if (star == null)
return Problem("No star with that id found", statusCode: 404);
await StarRepository.Remove(star);
await StarRepository.RemoveAsync(star);
return NoContent();
}
}

View File

@@ -1,7 +1,6 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using MoonCore.Exceptions;
using MoonCore.Extended.Abstractions;
using MoonlightServers.ApiServer.Database.Entities;
using MoonlightServers.ApiServer.Services;
@@ -37,14 +36,14 @@ public class FilesController : Controller
}
[HttpGet("list")]
public async Task<ActionResult<ServerFilesEntryResponse[]>> List([FromRoute] int serverId, [FromQuery] string path)
public async Task<ActionResult<ServerFilesEntryResponse[]>> ListAsync([FromRoute] int serverId, [FromQuery] string path)
{
var server = await GetServerById(serverId, ServerPermissionLevel.Read);
var server = await GetServerByIdAsync(serverId, ServerPermissionLevel.Read);
if (server.Value == null)
return server.Result ?? Problem("Unable to retrieve server");
var entries = await ServerFileSystemService.List(server.Value, path);
var entries = await ServerFileSystemService.ListAsync(server.Value, path);
return entries.Select(x => new ServerFilesEntryResponse()
{
@@ -57,57 +56,57 @@ public class FilesController : Controller
}
[HttpPost("move")]
public async Task<ActionResult> Move([FromRoute] int serverId, [FromQuery] string oldPath, [FromQuery] string newPath)
public async Task<ActionResult> MoveAsync([FromRoute] int serverId, [FromQuery] string oldPath, [FromQuery] string newPath)
{
var server = await GetServerById(serverId, ServerPermissionLevel.ReadWrite);
var server = await GetServerByIdAsync(serverId, ServerPermissionLevel.ReadWrite);
if (server.Value == null)
return server.Result ?? Problem("Unable to retrieve server");
await ServerFileSystemService.Move(server.Value, oldPath, newPath);
await ServerFileSystemService.MoveAsync(server.Value, oldPath, newPath);
return NoContent();
}
[HttpDelete("delete")]
public async Task<ActionResult> Delete([FromRoute] int serverId, [FromQuery] string path)
public async Task<ActionResult> DeleteAsync([FromRoute] int serverId, [FromQuery] string path)
{
var server = await GetServerById(serverId, ServerPermissionLevel.ReadWrite);
var server = await GetServerByIdAsync(serverId, ServerPermissionLevel.ReadWrite);
if (server.Value == null)
return server.Result ?? Problem("Unable to retrieve server");
await ServerFileSystemService.Delete(server.Value, path);
await ServerFileSystemService.DeleteAsync(server.Value, path);
return NoContent();
}
[HttpPost("mkdir")]
public async Task<ActionResult> Mkdir([FromRoute] int serverId, [FromQuery] string path)
public async Task<ActionResult> MkdirAsync([FromRoute] int serverId, [FromQuery] string path)
{
var server = await GetServerById(serverId, ServerPermissionLevel.ReadWrite);
var server = await GetServerByIdAsync(serverId, ServerPermissionLevel.ReadWrite);
if (server.Value == null)
return server.Result ?? Problem("Unable to retrieve server");
await ServerFileSystemService.Mkdir(server.Value, path);
await ServerFileSystemService.MkdirAsync(server.Value, path);
return NoContent();
}
[HttpPost("touch")]
public async Task<ActionResult> Touch([FromRoute] int serverId, [FromQuery] string path)
public async Task<ActionResult> TouchAsync([FromRoute] int serverId, [FromQuery] string path)
{
var server = await GetServerById(serverId, ServerPermissionLevel.ReadWrite);
var server = await GetServerByIdAsync(serverId, ServerPermissionLevel.ReadWrite);
if (server.Value == null)
return server.Result ?? Problem("Unable to retrieve server");
await ServerFileSystemService.Mkdir(server.Value, path);
await ServerFileSystemService.MkdirAsync(server.Value, path);
return NoContent();
}
[HttpGet("upload")]
public async Task<ActionResult<ServerFilesUploadResponse>> Upload([FromRoute] int serverId)
public async Task<ActionResult<ServerFilesUploadResponse>> UploadAsync([FromRoute] int serverId)
{
var serverResult = await GetServerById(serverId, ServerPermissionLevel.ReadWrite);
var serverResult = await GetServerByIdAsync(serverId, ServerPermissionLevel.ReadWrite);
if (serverResult.Value == null)
return serverResult.Result ?? Problem("Unable to retrieve server");
@@ -137,9 +136,9 @@ public class FilesController : Controller
}
[HttpGet("download")]
public async Task<ActionResult<ServerFilesDownloadResponse>> Download([FromRoute] int serverId, [FromQuery] string path)
public async Task<ActionResult<ServerFilesDownloadResponse>> DownloadAsync([FromRoute] int serverId, [FromQuery] string path)
{
var serverResult = await GetServerById(serverId, ServerPermissionLevel.Read);
var serverResult = await GetServerByIdAsync(serverId, ServerPermissionLevel.Read);
if (serverResult.Value == null)
return serverResult.Result ?? Problem("Unable to retrieve server");
@@ -170,9 +169,9 @@ public class FilesController : Controller
}
[HttpPost("compress")]
public async Task<ActionResult> Compress([FromRoute] int serverId, [FromBody] ServerFilesCompressRequest request)
public async Task<ActionResult> CompressAsync([FromRoute] int serverId, [FromBody] ServerFilesCompressRequest request)
{
var server = await GetServerById(serverId, ServerPermissionLevel.ReadWrite);
var server = await GetServerByIdAsync(serverId, ServerPermissionLevel.ReadWrite);
if (server.Value == null)
return server.Result ?? Problem("Unable to retrieve server");
@@ -180,14 +179,14 @@ public class FilesController : Controller
if (!Enum.TryParse(request.Type, true, out CompressType type))
return Problem("Invalid compress type provided", statusCode: 400);
await ServerFileSystemService.Compress(server.Value, type, request.Items, request.Destination);
await ServerFileSystemService.CompressAsync(server.Value, type, request.Items, request.Destination);
return Ok();
}
[HttpPost("decompress")]
public async Task<ActionResult> Decompress([FromRoute] int serverId, [FromBody] ServerFilesDecompressRequest request)
public async Task<ActionResult> DecompressAsync([FromRoute] int serverId, [FromBody] ServerFilesDecompressRequest request)
{
var server = await GetServerById(serverId, ServerPermissionLevel.ReadWrite);
var server = await GetServerByIdAsync(serverId, ServerPermissionLevel.ReadWrite);
if (server.Value == null)
return server.Result ?? Problem("Unable to retrieve server");
@@ -195,11 +194,11 @@ public class FilesController : Controller
if (!Enum.TryParse(request.Type, true, out CompressType type))
return Problem("Invalid decompress type provided", statusCode: 400);
await ServerFileSystemService.Decompress(server.Value, type, request.Path, request.Destination);
await ServerFileSystemService.DecompressAsync(server.Value, type, request.Path, request.Destination);
return NoContent();
}
private async Task<ActionResult<Server>> GetServerById(int serverId, ServerPermissionLevel level)
private async Task<ActionResult<Server>> GetServerByIdAsync(int serverId, ServerPermissionLevel level)
{
var server = await ServerRepository
.Get()
@@ -209,7 +208,7 @@ public class FilesController : Controller
if (server == null)
return Problem("No server with this id found", statusCode: 404);
var authorizeResult = await AuthorizeService.Authorize(
var authorizeResult = await AuthorizeService.AuthorizeAsync(
User, server,
ServerPermissionConstants.Files,
level

View File

@@ -1,10 +1,7 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using MoonCore.Exceptions;
using MoonCore.Extended.Abstractions;
using MoonCore.Helpers;
using Moonlight.ApiServer.Database.Entities;
using MoonlightServers.ApiServer.Database.Entities;
using MoonlightServers.ApiServer.Services;
using MoonlightServers.Shared.Constants;
@@ -34,44 +31,44 @@ public class PowerController : Controller
[HttpPost("start")]
[Authorize]
public async Task<ActionResult> Start([FromRoute] int serverId)
public async Task<ActionResult> StartAsync([FromRoute] int serverId)
{
var server = await GetServerById(serverId);
var server = await GetServerByIdAsync(serverId);
if (server.Value == null)
return server.Result ?? Problem("Unable to retrieve server");
await ServerService.Start(server.Value);
await ServerService.StartAsync(server.Value);
return NoContent();
}
[HttpPost("stop")]
[Authorize]
public async Task<ActionResult> Stop([FromRoute] int serverId)
public async Task<ActionResult> StopAsync([FromRoute] int serverId)
{
var server = await GetServerById(serverId);
var server = await GetServerByIdAsync(serverId);
if (server.Value == null)
return server.Result ?? Problem("Unable to retrieve server");
await ServerService.Stop(server.Value);
await ServerService.StopAsync(server.Value);
return NoContent();
}
[HttpPost("kill")]
[Authorize]
public async Task<ActionResult> Kill([FromRoute] int serverId)
public async Task<ActionResult> KillAsync([FromRoute] int serverId)
{
var server = await GetServerById(serverId);
var server = await GetServerByIdAsync(serverId);
if (server.Value == null)
return server.Result ?? Problem("Unable to retrieve server");
await ServerService.Kill(server.Value);
await ServerService.KillAsync(server.Value);
return NoContent();
}
private async Task<ActionResult<Server>> GetServerById(int serverId)
private async Task<ActionResult<Server>> GetServerByIdAsync(int serverId)
{
var server = await ServerRepository
.Get()
@@ -81,7 +78,7 @@ public class PowerController : Controller
if (server == null)
return Problem("No server with this id found", statusCode: 404);
var authorizeResult = await AuthorizeService.Authorize(
var authorizeResult = await AuthorizeService.AuthorizeAsync(
User, server,
ServerPermissionConstants.Power,
ServerPermissionLevel.ReadWrite

View File

@@ -1,24 +1,19 @@
using System.ComponentModel.DataAnnotations;
using System.Security.Claims;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using MoonCore.Exceptions;
using MoonCore.Extended.Abstractions;
using MoonCore.Extended.Models;
using MoonCore.Models;
using Moonlight.ApiServer.Database.Entities;
using MoonlightServers.ApiServer.Database.Entities;
using MoonlightServers.ApiServer.Extensions;
using MoonlightServers.ApiServer.Mappers;
using MoonlightServers.ApiServer.Models;
using MoonlightServers.ApiServer.Services;
using MoonlightServers.Shared.Constants;
using MoonlightServers.Shared.Enums;
using MoonlightServers.Shared.Http.Requests.Client.Servers;
using MoonlightServers.Shared.Http.Responses.Client.Servers;
using MoonlightServers.Shared.Http.Responses.Client.Servers.Allocations;
using MoonlightServers.Shared.Models;
namespace MoonlightServers.ApiServer.Http.Controllers.Client;
@@ -52,8 +47,14 @@ public class ServersController : Controller
}
[HttpGet]
public async Task<ActionResult<PagedData<ServerDetailResponse>>> GetAll([FromQuery] PagedOptions options)
public async Task<ActionResult<CountedData<ServerDetailResponse>>> GetAllAsync(
[FromQuery] int startIndex,
[FromQuery] int count
)
{
if (count > 100)
return Problem("Only 100 items can be fetched at a time", statusCode: 400);
var userIdClaim = User.FindFirstValue("UserId");
if (string.IsNullOrEmpty(userIdClaim))
@@ -68,12 +69,12 @@ public class ServersController : Controller
.Include(x => x.Node)
.Where(x => x.OwnerId == userId);
var count = await query.CountAsync();
var totalCount = await query.CountAsync();
var items = await query
.OrderBy(x => x.Id)
.Skip(options.Page * options.PageSize)
.Take(options.PageSize)
.Skip(startIndex)
.Take(count)
.AsNoTracking()
.ToArrayAsync();
@@ -94,19 +95,22 @@ public class ServersController : Controller
}).ToArray()
}).ToArray();
return new PagedData<ServerDetailResponse>()
return new CountedData<ServerDetailResponse>()
{
Items = mappedItems,
CurrentPage = options.Page,
TotalItems = count,
PageSize = options.PageSize,
TotalPages = (int)Math.Ceiling(Math.Max(0, count) / (double)options.PageSize)
TotalCount = totalCount
};
}
[HttpGet("shared")]
public async Task<ActionResult<PagedData<ServerDetailResponse>>> GetAllShared([FromQuery] PagedOptions options)
public async Task<ActionResult<CountedData<ServerDetailResponse>>> GetAllSharedAsync(
[FromQuery] int startIndex,
[FromQuery] int count
)
{
if (count > 100)
return Problem("Only 100 items can be fetched at a time", statusCode: 400);
var userIdClaim = User.FindFirstValue("UserId");
if (string.IsNullOrEmpty(userIdClaim))
@@ -124,12 +128,12 @@ public class ServersController : Controller
.ThenInclude(x => x.Allocations)
.Where(x => x.UserId == userId);
var count = await query.CountAsync();
var totalCount = await query.CountAsync();
var items = await query
.OrderBy(x => x.Id)
.Skip(options.Page * options.PageSize)
.Take(options.PageSize)
.Skip(startIndex)
.Take(count)
.ToArrayAsync();
var ownerIds = items
@@ -164,18 +168,15 @@ public class ServersController : Controller
}
}).ToArray();
return new PagedData<ServerDetailResponse>()
return new CountedData<ServerDetailResponse>()
{
Items = mappedItems,
CurrentPage = options.Page,
TotalItems = count,
PageSize = options.PageSize,
TotalPages = (int)Math.Ceiling(Math.Max(0, count) / (double)options.PageSize)
TotalCount = totalCount
};
}
[HttpGet("{serverId:int}")]
public async Task<ActionResult<ServerDetailResponse>> Get([FromRoute] int serverId)
public async Task<ActionResult<ServerDetailResponse>> GetAsync([FromRoute] int serverId)
{
var server = await ServerRepository
.Get()
@@ -187,7 +188,7 @@ public class ServersController : Controller
if (server == null)
return Problem("No server with this id found", statusCode: 404);
var authorizationResult = await AuthorizeService.Authorize(
var authorizationResult = await AuthorizeService.AuthorizeAsync(
User,
server,
String.Empty,
@@ -238,9 +239,9 @@ public class ServersController : Controller
}
[HttpGet("{serverId:int}/status")]
public async Task<ActionResult<ServerStatusResponse>> GetStatus([FromRoute] int serverId)
public async Task<ActionResult<ServerStatusResponse>> GetStatusAsync([FromRoute] int serverId)
{
var server = await GetServerById(
var server = await GetServerByIdAsync(
serverId,
ServerPermissionConstants.Console,
ServerPermissionLevel.None
@@ -249,7 +250,7 @@ public class ServersController : Controller
if (server.Value == null)
return server.Result ?? Problem("Unable to retrieve server");
var status = await ServerService.GetStatus(server.Value);
var status = await ServerService.GetStatusAsync(server.Value);
return new ServerStatusResponse()
{
@@ -258,9 +259,9 @@ public class ServersController : Controller
}
[HttpGet("{serverId:int}/ws")]
public async Task<ActionResult<ServerWebSocketResponse>> GetWebSocket([FromRoute] int serverId)
public async Task<ActionResult<ServerWebSocketResponse>> GetWebSocketAsync([FromRoute] int serverId)
{
var serverResult = await GetServerById(
var serverResult = await GetServerByIdAsync(
serverId,
ServerPermissionConstants.Console,
ServerPermissionLevel.Read
@@ -292,9 +293,9 @@ public class ServersController : Controller
}
[HttpGet("{serverId:int}/logs")]
public async Task<ActionResult<ServerLogsResponse>> GetLogs([FromRoute] int serverId)
public async Task<ActionResult<ServerLogsResponse>> GetLogsAsync([FromRoute] int serverId)
{
var server = await GetServerById(
var server = await GetServerByIdAsync(
serverId,
ServerPermissionConstants.Console,
ServerPermissionLevel.Read
@@ -303,7 +304,7 @@ public class ServersController : Controller
if (server.Value == null)
return server.Result ?? Problem("Unable to retrieve server");
var logs = await ServerService.GetLogs(server.Value);
var logs = await ServerService.GetLogsAsync(server.Value);
return new ServerLogsResponse()
{
@@ -312,9 +313,9 @@ public class ServersController : Controller
}
[HttpGet("{serverId:int}/stats")]
public async Task<ActionResult<ServerStatsResponse>> GetStats([FromRoute] int serverId)
public async Task<ActionResult<ServerStatsResponse>> GetStatsAsync([FromRoute] int serverId)
{
var server = await GetServerById(
var server = await GetServerByIdAsync(
serverId,
ServerPermissionConstants.Console,
ServerPermissionLevel.Read
@@ -323,7 +324,7 @@ public class ServersController : Controller
if (server.Value == null)
return server.Result ?? Problem("Unable to retrieve server");
var stats = await ServerService.GetStats(server.Value);
var stats = await ServerService.GetStatsAsync(server.Value);
return new ServerStatsResponse()
{
@@ -337,9 +338,9 @@ public class ServersController : Controller
}
[HttpPost("{serverId:int}/command")]
public async Task<ActionResult> Command([FromRoute] int serverId, [FromBody] ServerCommandRequest request)
public async Task<ActionResult> CommandAsync([FromRoute] int serverId, [FromBody] ServerCommandRequest request)
{
var server = await GetServerById(
var server = await GetServerByIdAsync(
serverId,
ServerPermissionConstants.Console,
ServerPermissionLevel.ReadWrite
@@ -348,12 +349,13 @@ public class ServersController : Controller
if (server.Value == null)
return server.Result ?? Problem("Unable to retrieve server");
await ServerService.RunCommand(server.Value, request.Command);
await ServerService.RunCommandAsync(server.Value, request.Command);
return NoContent();
}
private async Task<ActionResult<Server>> GetServerById(int serverId, string permissionId, ServerPermissionLevel level)
private async Task<ActionResult<Server>> GetServerByIdAsync(int serverId, string permissionId,
ServerPermissionLevel level)
{
var server = await ServerRepository
.Get()
@@ -363,7 +365,7 @@ public class ServersController : Controller
if (server == null)
return Problem("No server with this id found", statusCode: 404);
var authorizeResult = await AuthorizeService.Authorize(User, server, permissionId, level);
var authorizeResult = await AuthorizeService.AuthorizeAsync(User, server, permissionId, level);
if (!authorizeResult.Succeeded)
{

View File

@@ -1,7 +1,6 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using MoonCore.Exceptions;
using MoonCore.Extended.Abstractions;
using MoonlightServers.ApiServer.Database.Entities;
using MoonlightServers.ApiServer.Services;
@@ -32,18 +31,18 @@ public class SettingsController : Controller
[HttpPost("{serverId:int}/install")]
[Authorize]
public async Task<ActionResult> Install([FromRoute] int serverId)
public async Task<ActionResult> InstallAsync([FromRoute] int serverId)
{
var server = await GetServerById(serverId);
var server = await GetServerByIdAsync(serverId);
if (server.Value == null)
return server.Result ?? Problem("Unable to retrieve server");
await ServerService.Install(server.Value);
await ServerService.InstallAsync(server.Value);
return NoContent();
}
private async Task<ActionResult<Server>> GetServerById(int serverId)
private async Task<ActionResult<Server>> GetServerByIdAsync(int serverId)
{
var server = await ServerRepository
.Get()
@@ -53,7 +52,7 @@ public class SettingsController : Controller
if (server == null)
return Problem("No server with this id found", statusCode: 404);
var authorizeResult = await AuthorizeService.Authorize(
var authorizeResult = await AuthorizeService.AuthorizeAsync(
User, server,
ServerPermissionConstants.Settings,
ServerPermissionLevel.ReadWrite

View File

@@ -1,15 +1,11 @@
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using MoonCore.Exceptions;
using MoonCore.Extended.Abstractions;
using MoonCore.Extended.Models;
using MoonCore.Models;
using Moonlight.ApiServer.Database.Entities;
using MoonlightServers.ApiServer.Database.Entities;
using MoonlightServers.ApiServer.Mappers;
using MoonlightServers.ApiServer.Models;
using MoonlightServers.ApiServer.Services;
using MoonlightServers.Shared.Constants;
using MoonlightServers.Shared.Enums;
@@ -42,12 +38,16 @@ public class SharesController : Controller
}
[HttpGet]
public async Task<ActionResult<IPagedData<ServerShareResponse>>> GetAll(
public async Task<ActionResult<CountedData<ServerShareResponse>>> GetAllAsync(
[FromRoute] int serverId,
[FromQuery] PagedOptions options
[FromQuery] int startIndex,
[FromQuery] int count
)
{
var server = await GetServerById(serverId);
if (count > 100)
return Problem("Only 100 items can be fetched at a time", statusCode: 400);
var server = await GetServerByIdAsync(serverId);
if (server.Value == null)
return server.Result ?? Problem("Unable to retrieve server");
@@ -56,12 +56,12 @@ public class SharesController : Controller
.Get()
.Where(x => x.Server.Id == server.Value.Id);
var count = await query.CountAsync();
var totalCount = await query.CountAsync();
var items = await query
.OrderBy(x => x.Id)
.Skip(options.Page * options.PageSize)
.Take(options.PageSize)
.Skip(startIndex)
.Take(count)
.ToArrayAsync();
var userIds = items
@@ -81,23 +81,20 @@ public class SharesController : Controller
Permissions = ShareMapper.MapToPermissionLevels(x.Content)
}).ToArray();
return new PagedData<ServerShareResponse>()
return new CountedData<ServerShareResponse>()
{
Items = mappedItems,
CurrentPage = options.Page,
PageSize = options.PageSize,
TotalItems = count,
TotalPages = (int)Math.Ceiling(Math.Max(0, count) / (double)options.PageSize)
TotalCount = totalCount
};
}
[HttpGet("{id:int}")]
public async Task<ActionResult<ServerShareResponse>> Get(
public async Task<ActionResult<ServerShareResponse>> GetAsync(
[FromRoute] int serverId,
[FromRoute] int id
)
{
var server = await GetServerById(serverId);
var server = await GetServerByIdAsync(serverId);
if (server.Value == null)
return server.Result ?? Problem("Unable to retrieve server");
@@ -124,12 +121,12 @@ public class SharesController : Controller
}
[HttpPost]
public async Task<ActionResult<ServerShareResponse>> Create(
public async Task<ActionResult<ServerShareResponse>> CreateAsync(
[FromRoute] int serverId,
[FromBody] CreateShareRequest request
)
{
var server = await GetServerById(serverId);
var server = await GetServerByIdAsync(serverId);
if (server.Value == null)
return server.Result ?? Problem("Unable to retrieve server");
@@ -150,7 +147,7 @@ public class SharesController : Controller
UserId = user.Id
};
var finalShare = await ShareRepository.Add(share);
var finalShare = await ShareRepository.AddAsync(share);
var mappedItem = new ServerShareResponse()
{
@@ -163,13 +160,13 @@ public class SharesController : Controller
}
[HttpPatch("{id:int}")]
public async Task<ActionResult<ServerShareResponse>> Update(
public async Task<ActionResult<ServerShareResponse>> UpdateAsync(
[FromRoute] int serverId,
[FromRoute] int id,
[FromBody] UpdateShareRequest request
)
{
var server = await GetServerById(serverId);
var server = await GetServerByIdAsync(serverId);
if (server.Value == null)
return server.Result ?? Problem("Unable to retrieve server");
@@ -185,7 +182,7 @@ public class SharesController : Controller
share.UpdatedAt = DateTime.UtcNow;
await ShareRepository.Update(share);
await ShareRepository.UpdateAsync(share);
var user = await UserRepository
.Get()
@@ -205,12 +202,12 @@ public class SharesController : Controller
}
[HttpDelete("{id:int}")]
public async Task<ActionResult> Delete(
public async Task<ActionResult> DeleteAsync(
[FromRoute] int serverId,
[FromRoute] int id
)
{
var server = await GetServerById(serverId);
var server = await GetServerByIdAsync(serverId);
if (server.Value == null)
return server.Result ?? Problem("Unable to retrieve server");
@@ -222,11 +219,11 @@ public class SharesController : Controller
if (share == null)
return Problem("A share with that id cannot be found", statusCode: 404);
await ShareRepository.Remove(share);
await ShareRepository.RemoveAsync(share);
return NoContent();
}
private async Task<ActionResult<Server>> GetServerById(int serverId)
private async Task<ActionResult<Server>> GetServerByIdAsync(int serverId)
{
var server = await ServerRepository
.Get()
@@ -235,7 +232,7 @@ public class SharesController : Controller
if (server == null)
return Problem("No server with this id found", statusCode: 404);
var authorizeResult = await AuthorizeService.Authorize(
var authorizeResult = await AuthorizeService.AuthorizeAsync(
User, server,
ServerPermissionConstants.Shares,
ServerPermissionLevel.ReadWrite

View File

@@ -1,18 +1,14 @@
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using MoonCore.Exceptions;
using MoonCore.Extended.Abstractions;
using MoonCore.Extended.Models;
using MoonCore.Models;
using Moonlight.ApiServer.Database.Entities;
using MoonlightServers.ApiServer.Database.Entities;
using MoonlightServers.ApiServer.Services;
using MoonlightServers.Shared.Constants;
using MoonlightServers.Shared.Enums;
using MoonlightServers.Shared.Http.Requests.Client.Servers.Variables;
using MoonlightServers.Shared.Http.Responses.Client.Servers.Shares;
using MoonlightServers.Shared.Http.Responses.Client.Servers.Variables;
namespace MoonlightServers.ApiServer.Http.Controllers.Client;
@@ -41,12 +37,16 @@ public class VariablesController : Controller
}
[HttpGet]
public async Task<ActionResult<PagedData<ServerVariableDetailResponse>>> Get(
public async Task<ActionResult<CountedData<ServerVariableDetailResponse>>> GetAsync(
[FromRoute] int serverId,
[FromQuery] PagedOptions options
[FromQuery] int startIndex,
[FromQuery] int count
)
{
var server = await GetServerById(serverId, ServerPermissionLevel.Read);
if (count > 100)
return Problem("Only 100 items can be fetched at a time", statusCode: 400);
var server = await GetServerByIdAsync(serverId, ServerPermissionLevel.Read);
if (server.Value == null)
return server.Result ?? Problem("Unable to retrieve server");
@@ -55,12 +55,12 @@ public class VariablesController : Controller
.Get()
.Where(x => x.Star.Id == server.Value.Star.Id);
var count = await query.CountAsync();
var totalCount = await query.CountAsync();
var starVariables = await query
.OrderBy(x => x.Id)
.Skip(options.Page * options.PageSize)
.Take(options.PageSize)
.Skip(startIndex)
.Take(count)
.ToArrayAsync();
var starVariableKeys = starVariables
@@ -87,25 +87,22 @@ public class VariablesController : Controller
};
}).ToArray();
return new PagedData<ServerVariableDetailResponse>()
return new CountedData<ServerVariableDetailResponse>()
{
Items = responses,
CurrentPage = options.Page,
PageSize = options.PageSize,
TotalItems = count,
TotalPages = (int)Math.Ceiling(Math.Max(0, count) / (double)options.PageSize)
TotalCount = totalCount
};
}
[HttpPut]
public async Task<ActionResult<ServerVariableDetailResponse>> UpdateSingle(
public async Task<ActionResult<ServerVariableDetailResponse>> UpdateSingleAsync(
[FromRoute] int serverId,
[FromBody] UpdateServerVariableRequest request
)
{
// TODO: Handle filter
var serverResult = await GetServerById(serverId, ServerPermissionLevel.ReadWrite);
var serverResult = await GetServerByIdAsync(serverId, ServerPermissionLevel.ReadWrite);
if (serverResult.Value == null)
return serverResult.Result ?? Problem("Unable to retrieve server");
@@ -119,7 +116,7 @@ public class VariablesController : Controller
throw new HttpApiException($"No variable with the key found: {request.Key}", 400);
serverVariable.Value = request.Value;
await ServerRepository.Update(server);
await ServerRepository.UpdateAsync(server);
return new ServerVariableDetailResponse()
{
@@ -133,12 +130,12 @@ public class VariablesController : Controller
}
[HttpPatch]
public async Task<ActionResult<ServerVariableDetailResponse[]>> Update(
public async Task<ActionResult<ServerVariableDetailResponse[]>> UpdateAsync(
[FromRoute] int serverId,
[FromBody] UpdateServerVariableRangeRequest request
)
{
var serverResult = await GetServerById(serverId, ServerPermissionLevel.ReadWrite);
var serverResult = await GetServerByIdAsync(serverId, ServerPermissionLevel.ReadWrite);
if (serverResult.Value == null)
return serverResult.Result ?? Problem("Unable to retrieve server");
@@ -158,7 +155,7 @@ public class VariablesController : Controller
serverVariable.Value = variable.Value;
}
await ServerRepository.Update(server);
await ServerRepository.UpdateAsync(server);
return request.Variables.Select(requestVariable =>
{
@@ -177,7 +174,7 @@ public class VariablesController : Controller
}).ToArray();
}
private async Task<ActionResult<Server>> GetServerById(int serverId, ServerPermissionLevel level)
private async Task<ActionResult<Server>> GetServerByIdAsync(int serverId, ServerPermissionLevel level)
{
var server = await ServerRepository
.Get()
@@ -189,7 +186,7 @@ public class VariablesController : Controller
if (server == null)
return Problem("No server with this id found", statusCode: 404);
var authorizeResult = await AuthorizeService.Authorize(
var authorizeResult = await AuthorizeService.AuthorizeAsync(
User, server,
ServerPermissionConstants.Variables,
level

View File

@@ -9,5 +9,5 @@ namespace MoonlightServers.ApiServer.Http.Controllers.Remote.Nodes;
public class NodeTripController : Controller
{
[HttpGet("trip")]
public Task Get() => Task.CompletedTask;
public Task GetAsync() => Task.CompletedTask;
}

View File

@@ -31,8 +31,14 @@ public class ServersController : Controller
}
[HttpGet]
public async Task<PagedData<ServerDataResponse>> Get([FromQuery] int page, [FromQuery] int pageSize)
public async Task<ActionResult<CountedData<ServerDataResponse>>> GetAsync(
[FromQuery] int startIndex,
[FromQuery] int count
)
{
if (count > 100)
return Problem("Only 100 items can be fetched at a time", statusCode: 400);
// Load the node via the id
var nodeId = int.Parse(User.Claims.First(x => x.Type == "nodeId").Value);
@@ -52,8 +58,8 @@ public class ServersController : Controller
.ThenInclude(x => x.DockerImages)
.Include(x => x.Variables)
.Include(x => x.Allocations)
.Skip(page * pageSize)
.Take(pageSize)
.Skip(startIndex)
.Take(count)
.ToArrayAsync();
var serverData = new List<ServerDataResponse>();
@@ -68,18 +74,15 @@ public class ServersController : Controller
serverData.Add(convertedData);
}
return new PagedData<ServerDataResponse>()
return new CountedData<ServerDataResponse>()
{
Items = serverData.ToArray(),
CurrentPage = page,
PageSize = pageSize,
TotalItems = total,
TotalPages = total == 0 ? 0 : total / pageSize
TotalCount = total
};
}
[HttpGet("{id:int}")]
public async Task<ServerDataResponse> Get([FromRoute] int id)
public async Task<ServerDataResponse> GetAsync([FromRoute] int id)
{
// Load the node via the id
var nodeId = int.Parse(User.Claims.First(x => x.Type == "nodeId").Value);
@@ -111,7 +114,7 @@ public class ServersController : Controller
}
[HttpGet("{id:int}/install")]
public async Task<ServerInstallDataResponse> GetInstall([FromRoute] int id)
public async Task<ServerInstallDataResponse> GetInstallAsync([FromRoute] int id)
{
// Load the node via the id
var nodeId = int.Parse(User.Claims.First(x => x.Type == "nodeId").Value);
@@ -180,7 +183,6 @@ public class ServersController : Controller
Port = x.Port
}).ToArray(),
Variables = server.Variables.ToDictionary(x => x.Key, x => x.Value),
Bandwidth = server.Bandwidth,
Cpu = server.Cpu,
Disk = server.Disk,
Memory = server.Memory,
@@ -189,7 +191,6 @@ public class ServersController : Controller
PullDockerImage = dockerImage.AutoPulling,
ParseConiguration = server.Star.ParseConfiguration,
StopCommand = server.Star.StopCommand,
UseVirtualDisk = server.UseVirtualDisk
};
}
}

View File

@@ -1,11 +1,9 @@
using System.Security.Claims;
using Microsoft.AspNetCore.Authorization;
using MoonCore.Attributes;
using MoonlightServers.ApiServer.Database.Entities;
using MoonlightServers.ApiServer.Interfaces;
using MoonlightServers.ApiServer.Models;
using MoonlightServers.Shared.Enums;
using MoonlightServers.Shared.Models;
namespace MoonlightServers.ApiServer.Implementations.ServerAuthFilters;
@@ -20,7 +18,7 @@ public class AdminAuthFilter : IServerAuthorizationFilter
AuthorizationService = authorizationService;
}
public async Task<ServerAuthorizationResult?> Process(
public async Task<ServerAuthorizationResult?> ProcessAsync(
ClaimsPrincipal user,
Server server,
string permissionId,

View File

@@ -1,10 +1,8 @@
using System.Security.Claims;
using MoonCore.Attributes;
using MoonlightServers.ApiServer.Database.Entities;
using MoonlightServers.ApiServer.Interfaces;
using MoonlightServers.ApiServer.Models;
using MoonlightServers.Shared.Enums;
using MoonlightServers.Shared.Models;
namespace MoonlightServers.ApiServer.Implementations.ServerAuthFilters;
@@ -12,7 +10,7 @@ public class OwnerAuthFilter : IServerAuthorizationFilter
{
public int Priority => 0;
public Task<ServerAuthorizationResult?> Process(
public Task<ServerAuthorizationResult?> ProcessAsync(
ClaimsPrincipal user,
Server server,
string permissionId,

View File

@@ -1,12 +1,10 @@
using System.Security.Claims;
using Microsoft.EntityFrameworkCore;
using MoonCore.Attributes;
using MoonCore.Extended.Abstractions;
using MoonlightServers.ApiServer.Database.Entities;
using MoonlightServers.ApiServer.Interfaces;
using MoonlightServers.ApiServer.Models;
using MoonlightServers.Shared.Enums;
using MoonlightServers.Shared.Models;
namespace MoonlightServers.ApiServer.Implementations.ServerAuthFilters;
@@ -21,7 +19,7 @@ public class ShareAuthFilter : IServerAuthorizationFilter
public int Priority => 0;
public async Task<ServerAuthorizationResult?> Process(
public async Task<ServerAuthorizationResult?> ProcessAsync(
ClaimsPrincipal user,
Server server,
string permissionId,

View File

@@ -12,7 +12,7 @@ public interface IServerAuthorizationFilter
public int Priority { get; }
public Task<ServerAuthorizationResult?> Process(
public Task<ServerAuthorizationResult?> ProcessAsync(
ClaimsPrincipal user,
Server server,
string permissionId,

View File

@@ -1,7 +1,6 @@
using MoonlightServers.ApiServer.Database.Entities;
using MoonlightServers.Shared.Http.Requests.Admin.Servers;
using MoonlightServers.Shared.Http.Responses.Admin.Servers;
using MoonlightServers.Shared.Http.Responses.Client.Servers;
using Riok.Mapperly.Abstractions;
namespace MoonlightServers.ApiServer.Mappers;

View File

@@ -1,5 +1,4 @@
using MoonlightServers.ApiServer.Database.Entities;
using MoonlightServers.Shared.Http.Requests.Admin.StarDockerImages;
using MoonlightServers.Shared.Http.Requests.Admin.Stars;
using MoonlightServers.Shared.Http.Responses.Admin.Stars;
using Riok.Mapperly.Abstractions;

View File

@@ -16,7 +16,7 @@
<ItemGroup>
<PackageReference Include="Moonlight.ApiServer" Version="2.1.*" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.7"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.9"/>
</ItemGroup>
<ItemGroup>

View File

@@ -1,9 +1,7 @@
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
using System.Text;
using Microsoft.IdentityModel.Tokens;
using MoonCore.Attributes;
using MoonCore.Extended.Helpers;
using MoonCore.Helpers;
using MoonlightServers.ApiServer.Database.Entities;
using MoonlightServers.DaemonShared.DaemonSide.Http.Responses.Statistics;
@@ -41,7 +39,7 @@ public class NodeService
return jwtSecurityTokenHandler.WriteToken(securityToken);
}
public async Task<SystemStatusResponse> GetSystemStatus(Node node)
public async Task<SystemStatusResponse> GetSystemStatusAsync(Node node)
{
using var apiClient = CreateApiClient(node);
return await apiClient.GetJson<SystemStatusResponse>("api/system/status");
@@ -49,13 +47,13 @@ public class NodeService
#region Statistics
public async Task<StatisticsResponse> GetStatistics(Node node)
public async Task<StatisticsResponse> GetStatisticsAsync(Node node)
{
using var apiClient = CreateApiClient(node);
return await apiClient.GetJson<StatisticsResponse>("api/statistics");
}
public async Task<StatisticsDockerResponse> GetDockerStatistics(Node node)
public async Task<StatisticsDockerResponse> GetDockerStatisticsAsync(Node node)
{
using var apiClient = CreateApiClient(node);
return await apiClient.GetJson<StatisticsDockerResponse>("api/statistics/docker");

View File

@@ -19,7 +19,7 @@ public class ServerAuthorizeService
AuthorizationFilters = authorizationFilters.ToArray();
}
public async Task<ServerAuthorizationResult> Authorize(
public async Task<ServerAuthorizationResult> AuthorizeAsync(
ClaimsPrincipal user,
Server server,
string permissionIdentifier,
@@ -28,7 +28,7 @@ public class ServerAuthorizeService
{
foreach (var authorizationFilter in AuthorizationFilters)
{
var result = await authorizationFilter.Process(
var result = await authorizationFilter.ProcessAsync(
user,
server,
permissionIdentifier,

View File

@@ -24,54 +24,54 @@ public class ServerFileSystemService
ServerRepository = serverRepository;
}
public async Task<ServerFileSystemResponse[]> List(Server server, string path)
public async Task<ServerFileSystemResponse[]> ListAsync(Server server, string path)
{
using var apiClient = await GetApiClient(server);
using var apiClient = await GetApiClientAsync(server);
return await apiClient.GetJson<ServerFileSystemResponse[]>(
$"api/servers/{server.Id}/files/list?path={path}"
);
}
public async Task Move(Server server, string oldPath, string newPath)
public async Task MoveAsync(Server server, string oldPath, string newPath)
{
using var apiClient = await GetApiClient(server);
using var apiClient = await GetApiClientAsync(server);
await apiClient.Post(
$"api/servers/{server.Id}/files/move?oldPath={oldPath}&newPath={newPath}"
);
}
public async Task Delete(Server server, string path)
public async Task DeleteAsync(Server server, string path)
{
using var apiClient = await GetApiClient(server);
using var apiClient = await GetApiClientAsync(server);
await apiClient.Delete(
$"api/servers/{server.Id}/files/delete?path={path}"
);
}
public async Task Mkdir(Server server, string path)
public async Task MkdirAsync(Server server, string path)
{
using var apiClient = await GetApiClient(server);
using var apiClient = await GetApiClientAsync(server);
await apiClient.Post(
$"api/servers/{server.Id}/files/mkdir?path={path}"
);
}
public async Task Touch(Server server, string path)
public async Task TouchAsync(Server server, string path)
{
using var apiClient = await GetApiClient(server);
using var apiClient = await GetApiClientAsync(server);
await apiClient.Post(
$"api/servers/{server.Id}/files/touch?path={path}"
);
}
public async Task Compress(Server server, CompressType type, string[] items, string destination)
public async Task CompressAsync(Server server, CompressType type, string[] items, string destination)
{
using var apiClient = await GetApiClient(server);
using var apiClient = await GetApiClientAsync(server);
await apiClient.Post(
$"api/servers/{server.Id}/files/compress",
@@ -84,9 +84,9 @@ public class ServerFileSystemService
);
}
public async Task Decompress(Server server, CompressType type, string path, string destination)
public async Task DecompressAsync(Server server, CompressType type, string path, string destination)
{
using var apiClient = await GetApiClient(server);
using var apiClient = await GetApiClientAsync(server);
await apiClient.Post(
$"api/servers/{server.Id}/files/decompress",
@@ -101,7 +101,7 @@ public class ServerFileSystemService
#region Helpers
private async Task<HttpApiClient> GetApiClient(Server server)
private async Task<HttpApiClient> GetApiClientAsync(Server server)
{
var serverWithNode = server;

View File

@@ -1,4 +1,3 @@
using System.Text.Json;
using Microsoft.EntityFrameworkCore;
using MoonCore.Attributes;
using MoonCore.Exceptions;
@@ -25,11 +24,11 @@ public class ServerService
#region Power Actions
public async Task Start(Server server)
public async Task StartAsync(Server server)
{
try
{
using var apiClient = await GetApiClient(server);
using var apiClient = await GetApiClientAsync(server);
await apiClient.Post($"api/servers/{server.Id}/start");
}
catch (HttpRequestException e)
@@ -38,11 +37,11 @@ public class ServerService
}
}
public async Task Stop(Server server)
public async Task StopAsync(Server server)
{
try
{
using var apiClient = await GetApiClient(server);
using var apiClient = await GetApiClientAsync(server);
await apiClient.Post($"api/servers/{server.Id}/stop");
}
catch (HttpRequestException e)
@@ -51,11 +50,11 @@ public class ServerService
}
}
public async Task Kill(Server server)
public async Task KillAsync(Server server)
{
try
{
using var apiClient = await GetApiClient(server);
using var apiClient = await GetApiClientAsync(server);
await apiClient.Post($"api/servers/{server.Id}/kill");
}
catch (HttpRequestException e)
@@ -66,11 +65,11 @@ public class ServerService
#endregion
public async Task Install(Server server)
public async Task InstallAsync(Server server)
{
try
{
using var apiClient = await GetApiClient(server);
using var apiClient = await GetApiClientAsync(server);
await apiClient.Post($"api/servers/{server.Id}/install");
}
catch (HttpRequestException e)
@@ -79,11 +78,11 @@ public class ServerService
}
}
public async Task Sync(Server server)
public async Task SyncAsync(Server server)
{
try
{
using var apiClient = await GetApiClient(server);
using var apiClient = await GetApiClientAsync(server);
await apiClient.Post($"api/servers/{server.Id}/sync");
}
catch (HttpRequestException e)
@@ -92,11 +91,11 @@ public class ServerService
}
}
public async Task SyncDelete(Server server)
public async Task SyncDeleteAsync(Server server)
{
try
{
using var apiClient = await GetApiClient(server);
using var apiClient = await GetApiClientAsync(server);
await apiClient.Delete($"api/servers/{server.Id}");
}
catch (HttpRequestException e)
@@ -105,11 +104,11 @@ public class ServerService
}
}
public async Task<ServerStatusResponse> GetStatus(Server server)
public async Task<ServerStatusResponse> GetStatusAsync(Server server)
{
try
{
using var apiClient = await GetApiClient(server);
using var apiClient = await GetApiClientAsync(server);
return await apiClient.GetJson<ServerStatusResponse>($"api/servers/{server.Id}/status");
}
catch (HttpRequestException e)
@@ -118,11 +117,11 @@ public class ServerService
}
}
public async Task<ServerLogsResponse> GetLogs(Server server)
public async Task<ServerLogsResponse> GetLogsAsync(Server server)
{
try
{
using var apiClient = await GetApiClient(server);
using var apiClient = await GetApiClientAsync(server);
return await apiClient.GetJson<ServerLogsResponse>($"api/servers/{server.Id}/logs");
}
catch (HttpRequestException e)
@@ -131,11 +130,11 @@ public class ServerService
}
}
public async Task<ServerStatsResponse> GetStats(Server server)
public async Task<ServerStatsResponse> GetStatsAsync(Server server)
{
try
{
using var apiClient = await GetApiClient(server);
using var apiClient = await GetApiClientAsync(server);
return await apiClient.GetJson<ServerStatsResponse>($"api/servers/{server.Id}/stats");
}
catch (HttpRequestException)
@@ -144,11 +143,11 @@ public class ServerService
}
}
public async Task RunCommand(Server server, string command)
public async Task RunCommandAsync(Server server, string command)
{
try
{
using var apiClient = await GetApiClient(server);
using var apiClient = await GetApiClientAsync(server);
await apiClient.Post(
$"api/servers/{server.Id}/command",
@@ -174,7 +173,7 @@ public class ServerService
return PermissionHelper.HasPermission(user.Permissions, "admin.servers.get");
}
private async Task<HttpApiClient> GetApiClient(Server server)
private async Task<HttpApiClient> GetApiClientAsync(Server server)
{
var serverWithNode = server;

View File

@@ -23,7 +23,7 @@ public class StarImportExportService
Logger = logger;
}
public async Task<string> Export(int id)
public async Task<string> ExportAsync(int id)
{
var star = StarRepository
.Get()
@@ -78,20 +78,20 @@ public class StarImportExportService
return json;
}
public async Task<Star> Import(string json)
public async Task<Star> ImportAsync(string json)
{
// Determine which importer to use based on simple patterns
if (json.Contains("RequiredAllocations"))
return await ImportStar(json);
return await ImportStarAsync(json);
else if (json.Contains("AllocationsNeeded"))
return await ImportImage(json);
return await ImportImageAsync(json);
else if (json.Contains("_comment"))
return await ImportEgg(json);
return await ImportEggAsync(json);
else
throw new HttpApiException("Unable to determine the format of the imported star/image/egg", 400);
}
public async Task<Star> ImportStar(string json)
public async Task<Star> ImportStarAsync(string json)
{
try
{
@@ -138,7 +138,7 @@ public class StarImportExportService
}).ToList()
};
var finalStar = await StarRepository.Add(star);
var finalStar = await StarRepository.AddAsync(star);
return finalStar;
}
@@ -149,7 +149,7 @@ public class StarImportExportService
}
}
public async Task<Star> ImportImage(string json)
public async Task<Star> ImportImageAsync(string json)
{
try
{
@@ -235,7 +235,7 @@ public class StarImportExportService
#endregion
var finalStar = await StarRepository.Add(star);
var finalStar = await StarRepository.AddAsync(star);
return finalStar;
}
@@ -246,7 +246,7 @@ public class StarImportExportService
}
}
public async Task<Star> ImportEgg(string json)
public async Task<Star> ImportEggAsync(string json)
{
// Create result
var star = new Star();
@@ -403,7 +403,7 @@ public class StarImportExportService
star.AllowDockerImageChange = true;
// Finally save it to the db
var finalStar = await StarRepository.Add(star);
var finalStar = await StarRepository.AddAsync(star);
return finalStar;
}

View File

@@ -15,7 +15,7 @@ namespace MoonlightServers.ApiServer.Startup;
public class PluginStartup : IPluginStartup
{
public Task BuildApplication(IServiceProvider serviceProvider, IHostApplicationBuilder builder)
public Task BuildApplicationAsync(IServiceProvider serviceProvider, IHostApplicationBuilder builder)
{
// Scan the current plugin assembly for di services
builder.Services.AutoAddServices<PluginStartup>();
@@ -51,9 +51,9 @@ public class PluginStartup : IPluginStartup
return Task.CompletedTask;
}
public Task ConfigureApplication(IServiceProvider serviceProvider, IApplicationBuilder app)
public Task ConfigureApplicationAsync(IServiceProvider serviceProvider, IApplicationBuilder app)
=> Task.CompletedTask;
public Task ConfigureEndpoints(IServiceProvider serviceProvider, IEndpointRouteBuilder routeBuilder)
public Task ConfigureEndpointsAsync(IServiceProvider serviceProvider, IEndpointRouteBuilder routeBuilder)
=> Task.CompletedTask;
}

View File

@@ -1,5 +1,3 @@
using MoonCore.Helpers;
namespace MoonlightServers.Daemon.Configuration;
public class AppConfiguration

View File

@@ -23,8 +23,6 @@ public static class ServerConfigurationExtensions
Variables = response.Variables,
OnlineDetection = response.OnlineDetection,
DockerImage = response.DockerImage,
UseVirtualDisk = response.UseVirtualDisk,
Bandwidth = response.Bandwidth,
Cpu = response.Cpu,
Disk = response.Disk,
Memory = response.Memory,

View File

@@ -57,18 +57,18 @@ public class HostSystemHelper
#region CPU Usage
public async Task<CpuUsageDetails> GetCpuUsage()
public async Task<CpuUsageDetails> GetCpuUsageAsync()
{
var result = new CpuUsageDetails();
var perCoreUsages = new List<double>();
// Initial read
var (cpuLastStats, cpuLastSums) = await ReadAllCpuStats();
var (cpuLastStats, cpuLastSums) = await ReadAllCpuStatsAsync();
await Task.Delay(1000);
// Second read
var (cpuNowStats, cpuNowSums) = await ReadAllCpuStats();
var (cpuNowStats, cpuNowSums) = await ReadAllCpuStatsAsync();
for (var i = 0; i < cpuNowStats.Length; i++)
{
@@ -94,7 +94,7 @@ public class HostSystemHelper
return result;
}
private async Task<(long[][] cpuStatsList, long[] cpuSums)> ReadAllCpuStats()
private async Task<(long[][] cpuStatsList, long[] cpuSums)> ReadAllCpuStatsAsync()
{
var lines = await File.ReadAllLinesAsync("/proc/stat");
@@ -128,12 +128,12 @@ public class HostSystemHelper
#region Memory
public async Task ClearCachedMemory()
public async Task ClearCachedMemoryAsync()
{
await File.WriteAllTextAsync("/proc/sys/vm/drop_caches", "3");
}
public async Task<MemoryUsageDetails> GetMemoryUsage()
public async Task<MemoryUsageDetails> GetMemoryUsageAsync()
{
var details = new MemoryUsageDetails();
@@ -194,7 +194,7 @@ public class HostSystemHelper
#region Disks
public async Task<DiskUsageDetails[]> GetDiskUsages()
public async Task<DiskUsageDetails[]> GetDiskUsagesAsync()
{
var details = new List<DiskUsageDetails>();

View File

@@ -3,7 +3,6 @@ using ICSharpCode.SharpZipLib.GZip;
using ICSharpCode.SharpZipLib.Tar;
using ICSharpCode.SharpZipLib.Zip;
using Mono.Unix.Native;
using MoonCore.Unix.Exceptions;
using MoonCore.Unix.SecureFs;
using MoonlightServers.DaemonShared.DaemonSide.Http.Responses.Servers;
using MoonlightServers.DaemonShared.Enums;
@@ -19,7 +18,7 @@ public class ServerFileSystem
FileSystem = fileSystem;
}
public Task<ServerFileSystemResponse[]> List(string inputPath)
public Task<ServerFileSystemResponse[]> ListAsync(string inputPath)
{
var path = Normalize(inputPath);
var entries = FileSystem.ReadDir(path);
@@ -45,7 +44,7 @@ public class ServerFileSystem
return Task.FromResult(result);
}
public Task Move(string inputOldPath, string inputNewPath)
public Task MoveAsync(string inputOldPath, string inputNewPath)
{
var oldPath = Normalize(inputOldPath);
var newPath = Normalize(inputNewPath);
@@ -55,7 +54,7 @@ public class ServerFileSystem
return Task.CompletedTask;
}
public Task Delete(string inputPath)
public Task DeleteAsync(string inputPath)
{
var path = Normalize(inputPath);
@@ -64,7 +63,7 @@ public class ServerFileSystem
return Task.CompletedTask;
}
public Task Mkdir(string inputPath)
public Task MkdirAsync(string inputPath)
{
var path = Normalize(inputPath);
@@ -73,7 +72,7 @@ public class ServerFileSystem
return Task.CompletedTask;
}
public Task Touch(string inputPath)
public Task TouchAsync(string inputPath)
{
var path = Normalize(inputPath);
@@ -91,7 +90,7 @@ public class ServerFileSystem
return Task.CompletedTask;
}
public Task CreateChunk(string inputPath, long totalSize, long positionToSkip, Stream chunkStream)
public Task CreateChunkAsync(string inputPath, long totalSize, long positionToSkip, Stream chunkStream)
{
var path = Normalize(inputPath);
@@ -114,7 +113,7 @@ public class ServerFileSystem
return Task.CompletedTask;
}
public Task Create(string inputPath, Stream dataStream)
public Task CreateAsync(string inputPath, Stream dataStream)
{
var path = Normalize(inputPath);
@@ -134,7 +133,7 @@ public class ServerFileSystem
return Task.CompletedTask;
}
public Task Read(string inputPath, Func<Stream, Task> onHandle)
public Task ReadAsync(string inputPath, Func<Stream, Task> onHandle)
{
var path = Normalize(inputPath);
@@ -149,7 +148,7 @@ public class ServerFileSystem
#region Compression
public Task Compress(string[] itemsInput, string destinationInput, CompressType type)
public Task CompressAsync(string[] itemsInput, string destinationInput, CompressType type)
{
var destination = Normalize(destinationInput);
var items = itemsInput.Select(Normalize);
@@ -191,7 +190,7 @@ public class ServerFileSystem
return Task.CompletedTask;
}
public Task Decompress(string pathInput, string destinationInput, CompressType type)
public Task DecompressAsync(string pathInput, string destinationInput, CompressType type)
{
var path = Normalize(pathInput);
var destination = Normalize(destinationInput);

View File

@@ -17,7 +17,7 @@ public class UnsafeDockerClient
Configuration = configuration;
}
public Task<HttpClient> CreateHttpClient()
public Task<HttpClient> CreateHttpClientAsync()
{
var client = new HttpClient(new SocketsHttpHandler()
{
@@ -35,9 +35,9 @@ public class UnsafeDockerClient
return Task.FromResult(client);
}
public async Task<DataUsageResponse> GetDataUsage()
public async Task<DataUsageResponse> GetDataUsageAsync()
{
using var client = await CreateHttpClient();
using var client = await CreateHttpClientAsync();
var responseJson = await client.GetStringAsync("http://some.random.domain/v1.47/system/df");
var response = JsonSerializer.Deserialize<DataUsageResponse>(responseJson)!;

View File

@@ -16,7 +16,7 @@ public class PowerController : Controller
}
[HttpPost("start")]
public async Task<ActionResult> Start([FromRoute] int id)
public async Task<ActionResult> StartAsync([FromRoute] int id)
{
var server = ServerService.GetById(id);
@@ -31,7 +31,7 @@ public class PowerController : Controller
}
[HttpPost("stop")]
public async Task<ActionResult> Stop([FromRoute] int id)
public async Task<ActionResult> StopAsync([FromRoute] int id)
{
var server = ServerService.GetById(id);
@@ -46,7 +46,7 @@ public class PowerController : Controller
}
[HttpPost("kill")]
public async Task<ActionResult> Kill([FromRoute] int id)
public async Task<ActionResult> KillAsync([FromRoute] int id)
{
var server = ServerService.GetById(id);
@@ -61,7 +61,7 @@ public class PowerController : Controller
}
[HttpPost("install")]
public async Task<ActionResult> Install([FromRoute] int id)
public async Task<ActionResult> InstallAsync([FromRoute] int id)
{
var server = ServerService.GetById(id);

View File

@@ -3,7 +3,6 @@ using MoonlightServers.Daemon.Mappers;
using MoonlightServers.Daemon.Services;
using MoonlightServers.DaemonShared.DaemonSide.Http.Responses.Servers;
using MoonlightServers.DaemonShared.Enums;
using MoonlightServers.DaemonShared.PanelSide.Http.Responses;
namespace MoonlightServers.Daemon.Http.Controllers.Servers;
@@ -21,14 +20,14 @@ public class ServersController : Controller
}
[HttpPost("sync")]
public async Task<ActionResult> Sync([FromRoute] int id)
public async Task<ActionResult> SyncAsync([FromRoute] int id)
{
await ServerService.InitializeById(id);
await ServerService.InitializeByIdAsync(id);
return NoContent();
}
[HttpGet("status")]
public async Task<ActionResult<ServerStatusResponse>> Status([FromRoute] int id)
public async Task<ActionResult<ServerStatusResponse>> StatusAsync([FromRoute] int id)
{
var server = ServerService.GetById(id);
@@ -42,7 +41,7 @@ public class ServersController : Controller
}
[HttpGet("logs")]
public async Task<ActionResult<ServerLogsResponse>> Logs([FromRoute] int id)
public async Task<ActionResult<ServerLogsResponse>> LogsAsync([FromRoute] int id)
{
var server = ServerService.GetById(id);
@@ -58,7 +57,7 @@ public class ServersController : Controller
}
[HttpGet("stats")]
public async Task<ServerStatsResponse> GetStats([FromRoute] int id)
public async Task<ServerStatsResponse> GetStatsAsync([FromRoute] int id)
{
return new ServerStatsResponse()
{

View File

@@ -18,17 +18,17 @@ public class StatisticsController : Controller
}
[HttpGet]
public async Task<StatisticsResponse> Get()
public async Task<StatisticsResponse> GetAsync()
{
var response = new StatisticsResponse();
var cpuUsage = await HostSystemHelper.GetCpuUsage();
var cpuUsage = await HostSystemHelper.GetCpuUsageAsync();
response.Cpu.Model = cpuUsage.Model;
response.Cpu.Usage = cpuUsage.OverallUsage;
response.Cpu.UsagePerCore = cpuUsage.PerCoreUsage;
var memoryUsage = await HostSystemHelper.GetMemoryUsage();
var memoryUsage = await HostSystemHelper.GetMemoryUsageAsync();
response.Memory.Available = memoryUsage.Available;
response.Memory.Cached = memoryUsage.Cached;
@@ -37,7 +37,7 @@ public class StatisticsController : Controller
response.Memory.SwapTotal = memoryUsage.SwapTotal;
response.Memory.SwapFree = memoryUsage.SwapFree;
var diskDetails = await HostSystemHelper.GetDiskUsages();
var diskDetails = await HostSystemHelper.GetDiskUsagesAsync();
response.Disks = diskDetails.Select(x => new StatisticsResponse.DiskData()
{

View File

@@ -20,13 +20,13 @@ public class StatisticsDockerController : Controller
}
[HttpGet]
public async Task<StatisticsDockerResponse> Get()
public async Task<StatisticsDockerResponse> GetAsync()
{
var usage = await DockerInfoService.GetDataUsage();
var usage = await DockerInfoService.GetDataUsageAsync();
return new StatisticsDockerResponse
{
Version = await DockerInfoService.GetDockerVersion(),
Version = await DockerInfoService.GetDockerVersionAsync(),
ContainersReclaimable = usage.Containers.Reclaimable,
ContainersUsed = usage.Containers.Used,
BuildCacheReclaimable = usage.BuildCache.Reclaimable,

View File

@@ -18,7 +18,7 @@ public class SystemStatusController : Controller
RemoteService = remoteService;
}
public async Task<SystemStatusResponse> Get()
public async Task<SystemStatusResponse> GetAsync()
{
SystemStatusResponse response;
@@ -27,7 +27,7 @@ public class SystemStatusController : Controller
try
{
await RemoteService.GetStatus();
await RemoteService.GetStatusAsync();
sw.Stop();

View File

@@ -30,8 +30,6 @@ public class ServerConfigurationMapper
Variables = response.Variables,
OnlineDetection = response.OnlineDetection,
DockerImage = response.DockerImage,
UseVirtualDisk = response.UseVirtualDisk,
Bandwidth = response.Bandwidth,
Cpu = response.Cpu,
Disk = response.Disk,
Memory = response.Memory,

View File

@@ -8,8 +8,6 @@ public class ServerConfiguration
public int Cpu { get; set; }
public int Memory { get; set; }
public int Disk { get; set; }
public int Bandwidth { get; set; }
public bool UseVirtualDisk { get; set; }
// Start, Stop & Status
public string StartupCommand { get; set; }

View File

@@ -14,7 +14,7 @@ public class ServerConsole
MaxMessagesInCache = maxMessagesInCache;
}
public async Task WriteToOutput(string content)
public async Task WriteToOutputAsync(string content)
{
lock (MessageCache)
{
@@ -32,7 +32,7 @@ public class ServerConsole
}
}
public async Task WriteToInput(string content)
public async Task WriteToInputAsync(string content)
{
if (OnInput != null)
await OnInput.Invoke(content);

View File

@@ -8,9 +8,10 @@
<ItemGroup>
<PackageReference Include="Docker.DotNet" Version="3.125.15" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="9.0.9" />
<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.2.0" />
<PackageReference Include="MoonCore" Version="1.9.7" />
<PackageReference Include="MoonCore.Extended" Version="1.3.7" />
<PackageReference Include="MoonCore" Version="2.0.1" />
<PackageReference Include="MoonCore.Extended" Version="1.4.0" />
<PackageReference Include="MoonCore.Unix" Version="1.0.8" />
<PackageReference Include="SharpZipLib" Version="1.4.2" />
<PackageReference Include="Stateless" Version="5.19.0" />

View File

@@ -2,4 +2,4 @@ using MoonlightServers.Daemon;
var startup = new Startup();
await startup.Run(args);
await startup.RunAsync(args);

View File

@@ -57,17 +57,17 @@ public class DockerConsole : IConsole
{
var containerName = string.Format(DockerConstants.RuntimeNameTemplate, Context.Configuration.Id);
await AttachToContainer(containerName);
await AttachToContainerAsync(containerName);
}
public async Task AttachInstallationAsync()
{
var containerName = string.Format(DockerConstants.InstallationNameTemplate, Context.Configuration.Id);
await AttachToContainer(containerName);
await AttachToContainerAsync(containerName);
}
private async Task AttachToContainer(string containerName)
private async Task AttachToContainerAsync(string containerName)
{
var cts = new CancellationTokenSource();
@@ -171,17 +171,17 @@ public class DockerConsole : IConsole
{
var containerName = string.Format(DockerConstants.RuntimeNameTemplate, Context.Configuration.Id);
await FetchFromContainer(containerName);
await FetchFromContainerAsync(containerName);
}
public async Task FetchInstallationAsync()
{
var containerName = string.Format(DockerConstants.InstallationNameTemplate, Context.Configuration.Id);
await FetchFromContainer(containerName);
await FetchFromContainerAsync(containerName);
}
private async Task FetchFromContainer(string containerName)
private async Task FetchFromContainerAsync(string containerName)
{
var logStream = await DockerClient.Containers.GetContainerLogsAsync(containerName, true, new()
{

View File

@@ -104,7 +104,7 @@ public class DockerInstallation : IInstallation
// Docker image
await Reporter.StatusAsync("Downloading docker image");
await ImageService.Download(data.DockerImage, async status => { await Reporter.StatusAsync(status); });
await ImageService.DownloadAsync(data.DockerImage, async status => { await Reporter.StatusAsync(status); });
await Reporter.StatusAsync("Downloaded docker image");
@@ -159,7 +159,7 @@ public class DockerInstallation : IInstallation
}
}
public async Task<IAsyncDisposable> SubscribeExited(Func<int, ValueTask> callback)
public async Task<IAsyncDisposable> SubscribeExitedAsync(Func<int, ValueTask> callback)
=> await ExitEventSource.SubscribeAsync(callback);
public async Task RestoreAsync()

View File

@@ -96,7 +96,7 @@ public class DockerRuntime : IRuntime
// Docker image
await Reporter.StatusAsync("Downloading docker image");
await ImageService.Download(
await ImageService.DownloadAsync(
Context.Configuration.DockerImage,
async status => { await Reporter.StatusAsync(status); }
);
@@ -152,7 +152,7 @@ public class DockerRuntime : IRuntime
}
}
public async Task<IAsyncDisposable> SubscribeExited(Func<int, ValueTask> callback)
public async Task<IAsyncDisposable> SubscribeExitedAsync(Func<int, ValueTask> callback)
=> await ExitEventSource.SubscribeAsync(callback);
public async Task RestoreAsync()

View File

@@ -80,7 +80,7 @@ public class InstallationHandler : IServerStateHandler
await Server.Installation.CreateAsync(runtimePath, installationPath, installData);
if (ExitSubscription == null)
ExitSubscription = await Server.Installation.SubscribeExited(OnInstallationExited);
ExitSubscription = await Server.Installation.SubscribeExitedAsync(OnInstallationExited);
// 6. Attach console

View File

@@ -58,7 +58,7 @@ public class StartupHandler : IServerStateHandler
await Server.Runtime.CreateAsync(hostPath);
if (ExitSubscription == null)
ExitSubscription = await Server.Runtime.SubscribeExited(OnRuntimeExited);
ExitSubscription = await Server.Runtime.SubscribeExitedAsync(OnRuntimeExited);
// 6. Attach console

View File

@@ -42,7 +42,7 @@ public interface IInstallation : IServerComponent
/// </summary>
/// <param name="callback">Callback to invoke whenever the installation exists</param>
/// <returns>Subscription disposable to unsubscribe from the event</returns>
public Task<IAsyncDisposable> SubscribeExited(Func<int, ValueTask> callback);
public Task<IAsyncDisposable> SubscribeExitedAsync(Func<int, ValueTask> callback);
/// <summary>
/// Connects an existing installation to this abstraction in order to restore it.

View File

@@ -44,7 +44,7 @@ public interface IRuntime : IServerComponent
/// </summary>
/// <param name="callback">Callback gets invoked whenever the runtime exites</param>
/// <returns>Subscription disposable to unsubscribe from the event</returns>
public Task<IAsyncDisposable> SubscribeExited(Func<int, ValueTask> callback);
public Task<IAsyncDisposable> SubscribeExitedAsync(Func<int, ValueTask> callback);
/// <summary>
/// Connects an existing runtime to this abstraction in order to restore it.

View File

@@ -1,5 +1,4 @@
using MoonlightServers.Daemon.Models.Cache;
using MoonlightServers.Daemon.ServerSystem.Interfaces;
namespace MoonlightServers.Daemon.ServerSystem.Models;

View File

@@ -1,4 +1,3 @@
using System.Collections;
using MoonlightServers.Daemon.ServerSystem.Enums;
using MoonlightServers.Daemon.ServerSystem.Interfaces;
using MoonlightServers.Daemon.ServerSystem.Models;

View File

@@ -1,11 +1,6 @@
using System.Reactive.Concurrency;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using Docker.DotNet;
using Docker.DotNet.Models;
using MoonCore.Events;
using MoonCore.Observability;
using MoonlightServers.Daemon.Helpers;
namespace MoonlightServers.Daemon.Services;

View File

@@ -25,7 +25,7 @@ public class DockerImageService
Logger = logger;
}
public async Task Download(string name, Action<string>? onProgressUpdated = null)
public async Task DownloadAsync(string name, Action<string>? onProgressUpdated = null)
{
// If there is already a download for this image occuring, we want to wait for this to complete instead
// of calling docker to download it again

View File

@@ -17,16 +17,16 @@ public class DockerInfoService
UnsafeDockerClient = unsafeDockerClient;
}
public async Task<string> GetDockerVersion()
public async Task<string> GetDockerVersionAsync()
{
var version = await DockerClient.System.GetVersionAsync();
return $"{version.Version} commit {version.GitCommit} ({version.APIVersion})";
}
public async Task<UsageDataReport> GetDataUsage()
public async Task<UsageDataReport> GetDataUsageAsync()
{
var response = await UnsafeDockerClient.GetDataUsage();
var response = await UnsafeDockerClient.GetDataUsageAsync();
var report = new UsageDataReport()
{

View File

@@ -1,6 +1,3 @@
using System.IdentityModel.Tokens.Jwt;
using System.Text;
using Microsoft.IdentityModel.Tokens;
using MoonCore.Attributes;
using MoonCore.Helpers;
using MoonCore.Models;
@@ -19,26 +16,26 @@ public class RemoteService
ApiClient = CreateHttpClient(configuration);
}
public async Task GetStatus()
public async Task GetStatusAsync()
{
await ApiClient.Get("api/remote/servers/node/trip");
}
public async Task<PagedData<ServerDataResponse>> GetServers(int page, int perPage)
public async Task<CountedData<ServerDataResponse>> GetServersAsync(int startIndex, int count)
{
return await ApiClient.GetJson<PagedData<ServerDataResponse>>(
$"api/remote/servers?page={page}&pageSize={perPage}"
return await ApiClient.GetJson<CountedData<ServerDataResponse>>(
$"api/remote/servers?startIndex={startIndex}&count={count}"
);
}
public async Task<ServerDataResponse> GetServer(int serverId)
public async Task<ServerDataResponse> GetServerAsync(int serverId)
{
return await ApiClient.GetJson<ServerDataResponse>(
$"api/remote/servers/{serverId}"
);
}
public async Task<ServerInstallDataResponse> GetServerInstallation(int serverId)
public async Task<ServerInstallDataResponse> GetServerInstallationAsync(int serverId)
{
return await ApiClient.GetJson<ServerInstallDataResponse>(
$"api/remote/servers/{serverId}/install"

View File

@@ -1,5 +1,4 @@
using System.Collections.Concurrent;
using MoonCore.Helpers;
using MoonCore.Models;
using MoonlightServers.Daemon.Mappers;
using MoonlightServers.Daemon.Models.Cache;
@@ -32,7 +31,7 @@ public class ServerService : IHostedLifecycleService
public Server? GetById(int id)
=> Servers.GetValueOrDefault(id);
public async Task Initialize(ServerConfiguration configuration)
public async Task InitializeAsync(ServerConfiguration configuration)
{
var existingServer = Servers.GetValueOrDefault(configuration.Id);
@@ -50,20 +49,20 @@ public class ServerService : IHostedLifecycleService
}
}
public async Task InitializeById(int id)
public async Task InitializeByIdAsync(int id)
{
var serverData = await RemoteService.GetServer(id);
var serverData = await RemoteService.GetServerAsync(id);
var config = ConfigurationMapper.FromServerDataResponse(serverData);
await Initialize(config);
await InitializeAsync(config);
}
private async Task InitializeAll()
private async Task InitializeAllAsync()
{
Logger.LogDebug("Initialing servers from panel");
var servers = await PagedData<ServerDataResponse>.All(async (page, pageSize) =>
await RemoteService.GetServers(page, pageSize)
var servers = await CountedData<ServerDataResponse>.LoadAllAsync(async (startIndex, count) =>
await RemoteService.GetServersAsync(startIndex, count)
);
foreach (var serverData in servers)
@@ -72,7 +71,7 @@ public class ServerService : IHostedLifecycleService
{
var config = ConfigurationMapper.FromServerDataResponse(serverData);
await Initialize(config);
await InitializeAsync(config);
}
catch (Exception e)
{
@@ -91,7 +90,7 @@ public class ServerService : IHostedLifecycleService
public async Task StartedAsync(CancellationToken cancellationToken)
{
await InitializeAll();
await InitializeAllAsync();
}
public Task StartingAsync(CancellationToken cancellationToken)

View File

@@ -14,11 +14,7 @@ using MoonlightServers.Daemon.Http.Hubs;
using MoonlightServers.Daemon.Mappers;
using MoonlightServers.Daemon.Models.Cache;
using MoonlightServers.Daemon.ServerSystem;
using MoonlightServers.Daemon.ServerSystem.Docker;
using MoonlightServers.Daemon.ServerSystem.Enums;
using MoonlightServers.Daemon.ServerSystem.FileSystems;
using MoonlightServers.Daemon.ServerSystem.Handlers;
using MoonlightServers.Daemon.ServerSystem.Implementations;
using MoonlightServers.Daemon.ServerSystem.Models;
using MoonlightServers.Daemon.Services;
@@ -40,35 +36,35 @@ public class Startup
private WebApplication WebApplication;
private WebApplicationBuilder WebApplicationBuilder;
public async Task Run(string[] args)
public async Task RunAsync(string[] args)
{
Args = args;
await SetupStorage();
await SetupAppConfiguration();
await SetupLogging();
await SetupStorageAsync();
await SetupAppConfigurationAsync();
await SetupLoggingAsync();
await CreateWebApplicationBuilder();
await CreateWebApplicationBuilderAsync();
await ConfigureKestrel();
await RegisterAppConfiguration();
await RegisterLogging();
await RegisterBase();
await RegisterAuth();
await RegisterDocker();
await RegisterServers();
await RegisterSignalR();
await RegisterCors();
await ConfigureKestrelAsync();
await RegisterAppConfigurationAsync();
await RegisterLoggingAsync();
await RegisterBaseAsync();
await RegisterAuthAsync();
await RegisterDockerAsync();
await RegisterServersAsync();
await RegisterSignalRAsync();
await RegisterCorsAsync();
await BuildWebApplication();
await BuildWebApplicationAsync();
await UseBase();
await UseCors();
await UseAuth();
await UseBaseMiddleware();
await UseBaseAsync();
await UseCorsAsync();
await UseAuthAsync();
await UseBaseMiddlewareAsync();
await MapBase();
await MapHubs();
await MapBaseAsync();
await MapHubsAsync();
Task.Run(async () =>
{
@@ -93,8 +89,6 @@ public class Startup
"java -Xms128M -Xmx{{SERVER_MEMORY}}M -Dterminal.jline=false -Dterminal.ansi=true -jar {{SERVER_JARFILE}}",
DockerImage = "ghcr.io/nexocrew-hq/moonlightdockerimages:java21",
StopCommand = "stop",
UseVirtualDisk = false,
Bandwidth = 0,
Variables = new Dictionary<string, string>()
{
{ "SERVER_JARFILE", "server.jar" },
@@ -139,7 +133,7 @@ public class Startup
await WebApplication.RunAsync();
}
private Task SetupStorage()
private Task SetupStorageAsync()
{
Directory.CreateDirectory("storage");
Directory.CreateDirectory(Path.Combine("storage", "logs"));
@@ -149,7 +143,7 @@ public class Startup
#region Base
private Task RegisterBase()
private Task RegisterBaseAsync()
{
WebApplicationBuilder.Services.AutoAddServices<Startup>();
WebApplicationBuilder.Services.AddControllers();
@@ -159,7 +153,7 @@ public class Startup
return Task.CompletedTask;
}
private Task ConfigureKestrel()
private Task ConfigureKestrelAsync()
{
WebApplicationBuilder.WebHost.ConfigureKestrel(options =>
{
@@ -170,7 +164,7 @@ public class Startup
return Task.CompletedTask;
}
private Task UseBase()
private Task UseBaseAsync()
{
WebApplication.UseRouting();
WebApplication.UseExceptionHandler();
@@ -178,12 +172,12 @@ public class Startup
return Task.CompletedTask;
}
private Task UseBaseMiddleware()
private Task UseBaseMiddlewareAsync()
{
return Task.CompletedTask;
}
private Task MapBase()
private Task MapBaseAsync()
{
WebApplication.MapControllers();
@@ -194,7 +188,7 @@ public class Startup
#region Docker
private Task RegisterDocker()
private Task RegisterDockerAsync()
{
var dockerClient = new DockerClientConfiguration(
new Uri(Configuration.Docker.Uri)
@@ -213,7 +207,7 @@ public class Startup
#region Configurations
private async Task SetupAppConfiguration()
private async Task SetupAppConfigurationAsync()
{
var configurationBuilder = new ConfigurationBuilder();
@@ -235,7 +229,7 @@ public class Startup
Configuration = configurationRoot.Get<AppConfiguration>()!;
}
private Task RegisterAppConfiguration()
private Task RegisterAppConfigurationAsync()
{
WebApplicationBuilder.Services.AddSingleton(Configuration);
@@ -246,13 +240,13 @@ public class Startup
#region Web Application
private Task CreateWebApplicationBuilder()
private Task CreateWebApplicationBuilderAsync()
{
WebApplicationBuilder = WebApplication.CreateBuilder(Args);
return Task.CompletedTask;
}
private Task BuildWebApplication()
private Task BuildWebApplicationAsync()
{
WebApplication = WebApplicationBuilder.Build();
return Task.CompletedTask;
@@ -262,7 +256,7 @@ public class Startup
#region Logging
private Task SetupLogging()
private Task SetupLoggingAsync()
{
LoggerFactory = new LoggerFactory();
LoggerFactory.AddAnsiConsole();
@@ -272,7 +266,7 @@ public class Startup
return Task.CompletedTask;
}
private async Task RegisterLogging()
private async Task RegisterLoggingAsync()
{
// Configure application logging
WebApplicationBuilder.Logging.ClearProviders();
@@ -323,7 +317,7 @@ public class Startup
#region Servers
private Task RegisterServers()
private Task RegisterServersAsync()
{
WebApplicationBuilder.Services.AddScoped<ServerContext>();
WebApplicationBuilder.Services.AddSingleton<ServerFactory>();
@@ -335,7 +329,7 @@ public class Startup
return Task.CompletedTask;
}
private Task UseServers()
private Task UseServersAsync()
{
return Task.CompletedTask;
}
@@ -344,13 +338,13 @@ public class Startup
#region Hubs
private Task RegisterSignalR()
private Task RegisterSignalRAsync()
{
WebApplicationBuilder.Services.AddSignalR();
return Task.CompletedTask;
}
private Task MapHubs()
private Task MapHubsAsync()
{
WebApplication.MapHub<ServerWebSocketHub>("api/servers/ws", options =>
{
@@ -365,7 +359,7 @@ public class Startup
#region Cors
private Task RegisterCors()
private Task RegisterCorsAsync()
{
//TODO: IMPORTANT: CHANGE !!!
WebApplicationBuilder.Services.AddCors(x =>
@@ -380,7 +374,7 @@ public class Startup
return Task.CompletedTask;
}
private Task UseCors()
private Task UseCorsAsync()
{
WebApplication.UseCors();
return Task.CompletedTask;
@@ -390,7 +384,7 @@ public class Startup
#region Authentication
private Task RegisterAuth()
private Task RegisterAuthAsync()
{
WebApplicationBuilder.Services
.AddAuthentication("token")
@@ -461,7 +455,7 @@ public class Startup
return Task.CompletedTask;
}
private Task UseAuth()
private Task UseAuthAsync()
{
WebApplication.UseAuthentication();
WebApplication.UseAuthorization();

View File

@@ -14,9 +14,6 @@ public class ServerDataResponse
public int Memory { get; set; }
public int Disk { get; set; }
public bool UseVirtualDisk { get; set; }
public int Bandwidth { get; set; }
public AllocationDataResponse[] Allocations { get; set; }
public Dictionary<string, string> Variables { get; set; }
}

View File

@@ -7,8 +7,8 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="9.0.5"/>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="9.0.5" PrivateAssets="all"/>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="9.0.9"/>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="9.0.9" PrivateAssets="all"/>
<PackageReference Include="MoonCore.PluginFramework" Version="1.0.8" />
<PackageReference Include="MoonCore.PluginFramework.Generator" Version="1.0.2" />
</ItemGroup>

View File

@@ -7,14 +7,14 @@ pluginLoader.Initialize();
var startup = new Startup();
await startup.Initialize(pluginLoader.Instances);
await startup.InitializeAsync(pluginLoader.Instances);
var wasmHostBuilder = WebAssemblyHostBuilder.CreateDefault(args);
await startup.AddMoonlight(wasmHostBuilder);
await startup.AddMoonlightAsync(wasmHostBuilder);
var wasmApp = wasmHostBuilder.Build();
await startup.AddMoonlight(wasmApp);
await startup.AddMoonlightAsync(wasmApp);
await wasmApp.RunAsync();

View File

@@ -21,8 +21,8 @@ module.exports = (opts = {}) => {
fs.mkdirSync("../../MoonlightServers.Frontend/Styles/mappings");
}
fs.writeFileSync('../../MoonlightServers.Frontend/mappings/classes.map', classArray.join('\n'));
console.log(`Extracted ${classArray.length} Tailwind classes to tailwind-classes.txt`);
fs.writeFileSync('../../MoonlightServers.Frontend/Styles/mappings/classes.map', classArray.join('\n'));
console.log(`Extracted ${classArray.length} Tailwind classes`);
}
};
};

View File

@@ -114,4 +114,24 @@
.dropdown-menu {
@apply bg-base-150;
}
.advance-select-menu {
@apply !border-base-content/20 border-2 ring-0! outline-0! bg-base-200/50 !px-0;
}
.advance-select-option {
@apply !rounded-none hover:!bg-primary;
}
.advance-select-option.selected {
@apply !bg-primary !text-primary-content;
}
.advance-select-toggle {
@apply !border-base-content/20 border-2 ring-0! outline-0! focus:border-primary! focus-within:border-primary! bg-base-200/50;
}
.table thead {
@apply !normal-case;
}
}

View File

@@ -15,15 +15,15 @@ public class ServerFsAccess : IFsAccess
FileSystemService = fileSystemService;
}
public Task CreateFile(string path)
=> FileSystemService.Touch(Id, path);
public Task CreateFileAsync(string path)
=> FileSystemService.TouchAsync(Id, path);
public Task CreateDirectory(string path)
=> FileSystemService.Mkdir(Id, path);
public Task CreateDirectoryAsync(string path)
=> FileSystemService.MkdirAsync(Id, path);
public async Task<FsEntry[]> List(string path)
public async Task<FsEntry[]> ListAsync(string path)
{
var entries = await FileSystemService.List(Id, path);
var entries = await FileSystemService.ListAsync(Id, path);
return entries.Select(x => new FsEntry()
{
@@ -35,28 +35,28 @@ public class ServerFsAccess : IFsAccess
}).ToArray();
}
public Task Move(string oldPath, string newPath)
=> FileSystemService.Move(Id, oldPath, newPath);
public Task MoveAsync(string oldPath, string newPath)
=> FileSystemService.MoveAsync(Id, oldPath, newPath);
public Task Read(string path, Func<Stream, Task> onHandleData)
public Task ReadAsync(string path, Func<Stream, Task> onHandleData)
{
throw new NotImplementedException();
}
public Task Write(string path, Stream dataStream)
public Task WriteAsync(string path, Stream dataStream)
{
throw new NotImplementedException();
}
public Task Delete(string path)
=> FileSystemService.Delete(Id, path);
public Task DeleteAsync(string path)
=> FileSystemService.DeleteAsync(Id, path);
public Task UploadChunk(string path, int chunkId, long chunkSize, long totalSize, byte[] data)
public Task UploadChunkAsync(string path, int chunkId, long chunkSize, long totalSize, byte[] data)
{
throw new NotImplementedException();
}
public Task<byte[]> DownloadChunk(string path, int chunkId, long chunkSize)
public Task<byte[]> DownloadChunkAsync(string path, int chunkId, long chunkSize)
{
throw new NotImplementedException();
}

View File

@@ -7,7 +7,7 @@ namespace MoonlightServers.Frontend.Implementations;
public class DefaultPermissionProvider : IServerPermissionProvider
{
public Task<ServerPermission[]> GetPermissions(ServerDetailResponse server)
public Task<ServerPermission[]> GetPermissionsAsync(ServerDetailResponse server)
{
ServerPermission[] permissions = [
new()

View File

@@ -9,7 +9,7 @@ namespace MoonlightServers.Frontend.Implementations;
public class DefaultServerTabProvider : IServerTabProvider
{
public Task<ServerTab[]> GetTabs(ServerDetailResponse server)
public Task<ServerTab[]> GetTabsAsync(ServerDetailResponse server)
{
ServerTab[] tabs =
[

View File

@@ -5,5 +5,5 @@ namespace MoonlightServers.Frontend.Interfaces;
public interface IServerPermissionProvider
{
public Task<ServerPermission[]> GetPermissions(ServerDetailResponse server);
public Task<ServerPermission[]> GetPermissionsAsync(ServerDetailResponse server);
}

View File

@@ -5,5 +5,5 @@ namespace MoonlightServers.Frontend.Interfaces;
public interface IServerTabProvider
{
public Task<ServerTab[]> GetTabs(ServerDetailResponse server);
public Task<ServerTab[]> GetTabsAsync(ServerDetailResponse server);
}

View File

@@ -1,6 +1,5 @@
using MoonlightServers.Frontend.UI.Components.Servers.ServerTabs;
using MoonlightServers.Shared.Enums;
using MoonlightServers.Shared.Models;
namespace MoonlightServers.Frontend.Models;

View File

@@ -15,7 +15,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="9.0.5" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="9.0.9" />
<PackageReference Include="Moonlight.Client" Version="2.1.*"/>
<PackageReference Include="XtermBlazor" Version="2.1.2" />
</ItemGroup>
@@ -31,7 +31,8 @@
</ItemGroup>
<ItemGroup>
<Folder Include="Styles\" />
<None Include="Styles/mappings/*.map" Pack="true" PackagePath="Styles/" />
<None Include="MoonlightServers.Frontend.targets" Pack="true" PackagePath="build/MoonlightServers.Frontend.targets" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,8 @@
<Project>
<ItemGroup>
<StylesFilesToCopy Include="$(MSBuildThisFileDirectory)../Styles/**/*.*"/>
</ItemGroup>
<Target Name="CopyContent" BeforeTargets="Build">
<Copy SourceFiles="@(StylesFilesToCopy)" DestinationFolder="$(ProjectDir)Styles/MoonlightServers.Frontend/%(RecursiveDir)" SkipUnchangedFiles="true" />
</Target>
</Project>

View File

@@ -15,19 +15,19 @@ public class NodeService
HttpApiClient = httpApiClient;
}
public async Task<NodeSystemStatusResponse> GetSystemStatus(int nodeId)
public async Task<NodeSystemStatusResponse> GetSystemStatusAsync(int nodeId)
{
return await HttpApiClient.GetJson<NodeSystemStatusResponse>($"api/admin/servers/nodes/{nodeId}/system/status");
}
public async Task<StatisticsResponse> GetStatistics(int nodeId)
public async Task<StatisticsResponse> GetStatisticsAsync(int nodeId)
{
return await HttpApiClient.GetJson<StatisticsResponse>(
$"api/admin/servers/nodes/{nodeId}/statistics"
);
}
public async Task<DockerStatisticsResponse> GetDockerStatistics(int nodeId)
public async Task<DockerStatisticsResponse> GetDockerStatisticsAsync(int nodeId)
{
return await HttpApiClient.GetJson<DockerStatisticsResponse>(
$"api/admin/servers/nodes/{nodeId}/statistics/docker"

View File

@@ -1,4 +1,3 @@
using System.Net;
using MoonCore.Attributes;
using MoonCore.Helpers;
using MoonlightServers.Shared.Http.Requests.Client.Servers.Files;
@@ -16,56 +15,56 @@ public class ServerFileSystemService
ApiClient = apiClient;
}
public async Task<ServerFilesEntryResponse[]> List(int serverId, string path)
public async Task<ServerFilesEntryResponse[]> ListAsync(int serverId, string path)
{
return await ApiClient.GetJson<ServerFilesEntryResponse[]>(
$"api/client/servers/{serverId}/files/list?path={path}"
);
}
public async Task Move(int serverId, string oldPath, string newPath)
public async Task MoveAsync(int serverId, string oldPath, string newPath)
{
await ApiClient.Post(
$"api/client/servers/{serverId}/files/move?oldPath={oldPath}&newPath={newPath}"
);
}
public async Task Delete(int serverId, string path)
public async Task DeleteAsync(int serverId, string path)
{
await ApiClient.Delete(
$"api/client/servers/{serverId}/files/delete?path={path}"
);
}
public async Task Mkdir(int serverId, string path)
public async Task MkdirAsync(int serverId, string path)
{
await ApiClient.Post(
$"api/client/servers/{serverId}/files/mkdir?path={path}"
);
}
public async Task Touch(int serverId, string path)
public async Task TouchAsync(int serverId, string path)
{
await ApiClient.Post(
$"api/client/servers/{serverId}/files/touch?path={path}"
);
}
public async Task<ServerFilesUploadResponse> Upload(int serverId)
public async Task<ServerFilesUploadResponse> UploadAsync(int serverId)
{
return await ApiClient.GetJson<ServerFilesUploadResponse>(
$"api/client/servers/{serverId}/files/upload"
);
}
public async Task<ServerFilesDownloadResponse> Download(int serverId, string path)
public async Task<ServerFilesDownloadResponse> DownloadAsync(int serverId, string path)
{
return await ApiClient.GetJson<ServerFilesDownloadResponse>(
$"api/client/servers/{serverId}/files/download?path={path}"
);
}
public async Task Compress(int serverId, string type, string[] items, string destination)
public async Task CompressAsync(int serverId, string type, string[] items, string destination)
{
await ApiClient.Post(
$"api/client/servers/{serverId}/files/compress",
@@ -78,7 +77,7 @@ public class ServerFileSystemService
);
}
public async Task Decompress(int serverId, string type, string path, string destination)
public async Task DecompressAsync(int serverId, string type, string path, string destination)
{
await ApiClient.Post(
$"api/client/servers/{serverId}/files/decompress",

View File

@@ -18,49 +18,49 @@ public class ServerService
HttpApiClient = httpApiClient;
}
public async Task<PagedData<ServerDetailResponse>> GetServers(int page, int perPage)
public async Task<CountedData<ServerDetailResponse>> GetServersAsync(int startIndex, int count)
{
return await HttpApiClient.GetJson<PagedData<ServerDetailResponse>>(
$"api/client/servers?page={page}&pageSize={perPage}"
return await HttpApiClient.GetJson<CountedData<ServerDetailResponse>>(
$"api/client/servers?startIndex={startIndex}&count={count}"
);
}
public async Task<PagedData<ServerDetailResponse>> GetSharedServers(int page, int perPage)
public async Task<CountedData<ServerDetailResponse>> GetSharedServersAsync(int startIndex, int count)
{
return await HttpApiClient.GetJson<PagedData<ServerDetailResponse>>(
$"api/client/servers/shared?page={page}&pageSize={perPage}"
return await HttpApiClient.GetJson<CountedData<ServerDetailResponse>>(
$"api/client/servers/shared?startIndex={startIndex}&count={count}"
);
}
public async Task<ServerDetailResponse> GetServer(int serverId)
public async Task<ServerDetailResponse> GetServerAsync(int serverId)
{
return await HttpApiClient.GetJson<ServerDetailResponse>(
$"api/client/servers/{serverId}"
);
}
public async Task<ServerStatusResponse> GetStatus(int serverId)
public async Task<ServerStatusResponse> GetStatusAsync(int serverId)
{
return await HttpApiClient.GetJson<ServerStatusResponse>(
$"api/client/servers/{serverId}/status"
);
}
public async Task<ServerLogsResponse> GetLogs(int serverId)
public async Task<ServerLogsResponse> GetLogsAsync(int serverId)
{
return await HttpApiClient.GetJson<ServerLogsResponse>(
$"api/client/servers/{serverId}/logs"
);
}
public async Task<ServerStatsResponse> GetStats(int serverId)
public async Task<ServerStatsResponse> GetStatsAsync(int serverId)
{
return await HttpApiClient.GetJson<ServerStatsResponse>(
$"api/client/servers/{serverId}/stats"
);
}
public async Task RunCommand(int serverId, string command)
public async Task RunCommandAsync(int serverId, string command)
{
await HttpApiClient.Post(
$"api/client/servers/{serverId}/command",
@@ -71,14 +71,14 @@ public class ServerService
);
}
public async Task<ServerWebSocketResponse> GetWebSocket(int serverId)
public async Task<ServerWebSocketResponse> GetWebSocketAsync(int serverId)
{
return await HttpApiClient.GetJson<ServerWebSocketResponse>(
$"api/client/servers/{serverId}/ws"
);
}
public async Task Install(int serverId)
public async Task InstallAsync(int serverId)
{
await HttpApiClient.Post(
$"api/client/servers/{serverId}/install"
@@ -87,21 +87,21 @@ public class ServerService
#region Power actions
public async Task Start(int serverId)
public async Task StartAsync(int serverId)
{
await HttpApiClient.Post(
$"api/client/servers/{serverId}/start"
);
}
public async Task Stop(int serverId)
public async Task StopAsync(int serverId)
{
await HttpApiClient.Post(
$"api/client/servers/{serverId}/stop"
);
}
public async Task Kill(int serverId)
public async Task KillAsync(int serverId)
{
await HttpApiClient.Post(
$"api/client/servers/{serverId}/kill"
@@ -112,14 +112,14 @@ public class ServerService
#region Variables
public async Task<PagedData<ServerVariableDetailResponse>> GetVariables(int serverId, int page, int pageSize)
public async Task<CountedData<ServerVariableDetailResponse>> GetVariablesAsync(int serverId, int startIndex, int count)
{
return await HttpApiClient.GetJson<PagedData<ServerVariableDetailResponse>>(
$"api/client/servers/{serverId}/variables?page={page}&pageSize={pageSize}"
return await HttpApiClient.GetJson<CountedData<ServerVariableDetailResponse>>(
$"api/client/servers/{serverId}/variables?startIndex={startIndex}&count={count}"
);
}
public async Task UpdateVariables(int serverId, UpdateServerVariableRangeRequest request)
public async Task UpdateVariablesAsync(int serverId, UpdateServerVariableRangeRequest request)
{
await HttpApiClient.Patch(
$"api/client/servers/{serverId}/variables",
@@ -127,7 +127,7 @@ public class ServerService
);
}
public async Task UpdateVariable(int serverId, UpdateServerVariableRequest request)
public async Task UpdateVariableAsync(int serverId, UpdateServerVariableRequest request)
{
await HttpApiClient.Put(
$"api/client/servers/{serverId}/variables",

View File

@@ -16,19 +16,19 @@ public class ServerShareService
ApiClient = apiClient;
}
public async Task<PagedData<ServerShareResponse>> Get(int id, int page, int pageSize)
=> await ApiClient.GetJson<PagedData<ServerShareResponse>>(
$"api/client/servers/{id}/shares?page={page}&pageSize={pageSize}");
public async Task<CountedData<ServerShareResponse>> GetAsync(int id, int startIndex, int count)
=> await ApiClient.GetJson<CountedData<ServerShareResponse>>(
$"api/client/servers/{id}/shares?startIndex={startIndex}&count={count}");
public async Task<ServerShareResponse> Get(int id, int shareId)
public async Task<ServerShareResponse> GetAsync(int id, int shareId)
=> await ApiClient.GetJson<ServerShareResponse>($"api/client/servers/{id}/shares/{shareId}");
public async Task<ServerShareResponse> Create(int id, CreateShareRequest request)
public async Task<ServerShareResponse> CreateAsync(int id, CreateShareRequest request)
=> await ApiClient.PostJson<ServerShareResponse>($"api/client/servers/{id}/shares", request);
public async Task<ServerShareResponse> Update(int id, int shareId, UpdateShareRequest request)
public async Task<ServerShareResponse> UpdateAsync(int id, int shareId, UpdateShareRequest request)
=> await ApiClient.PatchJson<ServerShareResponse>($"api/client/servers/{id}/shares/{shareId}", request);
public async Task Delete(int id, int shareId)
public async Task DeleteAsync(int id, int shareId)
=> await ApiClient.Delete($"api/client/servers/{id}/shares/{shareId}");
}

View File

@@ -10,7 +10,7 @@ namespace MoonlightServers.Frontend.Startup;
public class PluginStartup : IPluginStartup
{
public Task BuildApplication(IServiceProvider serviceProvider, WebAssemblyHostBuilder builder)
public Task BuildApplicationAsync(IServiceProvider serviceProvider, WebAssemblyHostBuilder builder)
{
builder.Services.AddSingleton<ISidebarItemProvider, SidebarImplementation>();
builder.Services.AddSingleton<IServerTabProvider, DefaultServerTabProvider>();
@@ -21,7 +21,7 @@ public class PluginStartup : IPluginStartup
return Task.CompletedTask;
}
public Task ConfigureApplication(IServiceProvider serviceProvider, WebAssemblyHost app)
public Task ConfigureApplicationAsync(IServiceProvider serviceProvider, WebAssemblyHost app)
{
return Task.CompletedTask;
}

View File

@@ -9,7 +9,9 @@
!me-1.5
!ms-auto
!px-2.5
!py-0.5
!rounded-full
!rounded-xs
!text-sm
!w-2.5
*:[grid-area:1/1]
@@ -19,13 +21,17 @@
-ml-4
-translate-x-full
-translate-y-1/2
[animation-duration:0.8s]
[animation-timing-function:ease]
absolute
accordion
accordion-bordered
accordion-toggle
active
active-tab:bg-primary
active-tab:hover:text-primary-content
active-tab:text-base-content
active-tab:text-primary-content
advance-select-menu
advance-select-option
advance-select-tag
@@ -39,6 +45,7 @@ align-bottom
align-middle
animate-bounce
animate-ping
animate-spin
aria-[current='page']:text-bg-soft-primary
avatar
avatar-away-bottom
@@ -62,6 +69,7 @@ bg-background/60
bg-base-100
bg-base-150
bg-base-200
bg-base-200!
bg-base-200/50
bg-base-300
bg-base-300/45
@@ -85,9 +93,14 @@ block
blur
border
border-0
border-1
border-2
border-3
border-accent
border-b
border-b-2
border-b-base-content/20
border-b-primary
border-base-content
border-base-content/20
border-base-content/25
@@ -96,15 +109,26 @@ border-base-content/5
border-base-content/60
border-base-content/70
border-dashed
border-dotted
border-e-2
border-error/30
border-info/30
border-l-4
border-l-transparent
border-primary
border-r-transparent
border-solid
border-success
border-success/30
border-t
border-t-2
border-t-transparent
border-transparent
border-warning/30
bottom-0
bottom-full
breadcrumbs
breadcrumbs-separator
break-words
btn
btn-accent
@@ -164,8 +188,10 @@ diff
disabled
divide-base-150/60
divide-y
divider
drop-shadow
dropdown
dropdown-active
dropdown-disabled
dropdown-item
dropdown-menu
@@ -179,7 +205,9 @@ ease-linear
end-3
error-message
file-upload-complete:progress-success
fill-base-content
fill-black
fill-gray-200
filter
filter-reset
fixed
@@ -210,6 +238,8 @@ font-inter
font-medium
font-normal
font-semibold
footer
footer-center
from-violet-400
gap-0.5
gap-1
@@ -226,6 +256,7 @@ gap-x-6
gap-y-1
gap-y-1.5
gap-y-2
gap-y-2.5
gap-y-3
gap-y-8
grid
@@ -233,10 +264,12 @@ grid-cols-1
grid-cols-12
grid-cols-2
grid-cols-3
grid-cols-4
grid-flow-col
grow
grow-0
h-0
h-10
h-12
h-14
h-2
@@ -253,11 +286,14 @@ hidden
hover:bg-indigo-500
hover:bg-primary/5
hover:bg-transparent
hover:cursor-pointer
hover:text-base-content
hover:text-base-content/60
hover:text-indigo-500
hover:text-primary
image-full
indicator
indicator-item
inline
inline-block
inline-flex
@@ -294,6 +330,7 @@ leading-3.5
leading-6
leading-9
leading-[1.1]
leading-none
left-0
lg:bg-base-100/20
lg:flex
@@ -320,6 +357,7 @@ link-hover
link-primary
list-disc
list-inside
list-none
loading
loading-lg
loading-sm
@@ -332,7 +370,11 @@ mask
max-h-52
max-lg:flex-col
max-lg:hidden
max-md:flex-wrap
max-md:justify-center
max-sm:hidden
max-w-7xl
max-w-8
max-w-80
max-w-full
max-w-lg
@@ -376,6 +418,7 @@ min-w-28
min-w-48
min-w-60
min-w-[100px]
min-w-full
min-w-sm
mix-blend-exclusion
ml-3
@@ -387,10 +430,13 @@ modal-middle
modal-title
mr-2
mr-4
ms-0.5
ms-1
ms-1.5
ms-2
ms-2.5
ms-3
ms-auto
mt-1
mt-1.5
mt-10
@@ -398,6 +444,7 @@ mt-12
mt-2
mt-2.5
mt-3
mt-3.5
mt-4
mt-5
mt-6
@@ -407,9 +454,12 @@ mx-auto
my-2.5
my-3
my-5
my-8
my-auto
object-cover
opacity-0
opacity-100
opacity-75
open
origin-top-left
outline
@@ -430,6 +480,7 @@ p-4
p-5
p-6
p-8
pb-1
pe-1.5
pin-input
pin-input-underline
@@ -444,6 +495,7 @@ progress-primary
pt-0
pt-0.5
pt-1.5
pt-2
pt-3
px-1.5
px-2
@@ -459,10 +511,12 @@ py-12
py-2
py-2.5
py-6
radial-progress
radio
range
relative
resize
ring
ring-0
ring-1
ring-gray-700
@@ -543,10 +597,12 @@ sm:text-sm/5
sm:w-1/2
sm:w-full
space-x-1
space-x-2.5
space-y-1
space-y-4
space-y-6
sr-only
stack
stat
stat-actions
stat-desc
@@ -602,6 +658,7 @@ text-left
text-lg
text-primary
text-primary-content
text-right
text-slate-100
text-sm
text-sm/5
@@ -645,6 +702,7 @@ via-sky-400
w-0
w-0.5
w-12
w-13
w-32
w-4
w-56

View File

@@ -0,0 +1,790 @@
!bg-base-100
!border-base-content/40
!border-none
!flex
!font-medium
!font-semibold
!h-2.5
!justify-between
!me-1.5
!ms-auto
!px-2.5
!py-0.5
!rounded-full
!rounded-xs
!text-sm
!w-2.5
*:[grid-area:1/1]
*:first:rounded-tl-lg
*:last:rounded-tr-lg
-left-4
-mb-3
-ml-4
-translate-x-full
-translate-y-1/2
2xl:col-span-1
2xl:col-span-2
2xl:col-span-3
2xl:flex
[animation-duration:0.8s]
[animation-timing-function:ease]
absolute
accordion
accordion-bordered
accordion-toggle
active
active-tab:bg-primary
active-tab:hover:text-primary-content
active-tab:text-base-content
active-tab:text-primary-content
advance-select-menu
advance-select-option
advance-select-tag
advance-select-toggle
alert
alert-error
alert-outline
alert-primary
alert-soft
align-bottom
align-middle
animate-bounce
animate-ping
animate-spin
aria-[current='page']:text-bg-soft-primary
avatar
avatar-away-bottom
avatar-away-top
avatar-busy-bottom
avatar-busy-top
avatar-offline-bottom
avatar-offline-top
avatar-online-bottom
avatar-online-top
avatar-placeholder
badge
badge-error
badge-info
badge-outline
badge-primary
badge-soft
badge-success
bg-background
bg-background/60
bg-base-100
bg-base-150
bg-base-200
bg-base-200!
bg-base-200/50
bg-base-200/75
bg-base-300
bg-base-300/45
bg-base-300/50
bg-base-300/60
bg-base-content/10
bg-black
bg-clip-text
bg-error
bg-gradient-to-r
bg-gray-800
bg-gray-900
bg-indigo-600
bg-info
bg-primary
bg-primary/5
bg-red-500
bg-success
bg-transparent
bg-warning
bg-white/5
block
blur
border
border-0
border-1
border-2
border-3
border-accent
border-b
border-b-2
border-b-base-content/20
border-b-primary
border-base-content
border-base-content/10
border-base-content/20
border-base-content/25
border-base-content/40
border-base-content/5
border-base-content/60
border-base-content/70
border-base-content/80
border-dashed
border-dotted
border-e-2
border-error
border-error/30
border-gray-600
border-info/30
border-l-4
border-l-8
border-l-transparent
border-primary
border-r-transparent
border-solid
border-success
border-success/30
border-t
border-t-2
border-t-transparent
border-transparent
border-warning
border-warning/30
bottom-0
bottom-full
breadcrumbs
breadcrumbs-separator
break-words
btn
btn-accent
btn-active
btn-block
btn-circle
btn-disabled
btn-error
btn-gradient
btn-info
btn-lg
btn-outline
btn-primary
btn-secondary
btn-sm
btn-soft
btn-square
btn-success
btn-text
btn-warning
card
card-alert
card-body
card-border
card-footer
card-header
card-sm
card-title
carousel
carousel-body
carousel-next
carousel-prev
carousel-slide
chat
chat-avatar
chat-bubble
chat-footer
chat-header
chat-receiver
chat-sender
checkbox
checkbox-primary
checkbox-xs
col-span-1
col-span-12
col-span-2
col-span-6
collapse
combo-box-selected:block
combo-box-selected:dropdown-active
complete
container
contents
cursor-default
cursor-not-allowed
cursor-pointer
custom-option
diff
disabled
divide-base-150/60
divide-y
divider
drop-shadow
dropdown
dropdown-active
dropdown-disabled
dropdown-item
dropdown-menu
dropdown-open:opacity-100
dropdown-open:rotate-180
dropdown-toggle
duration-300
duration-500
ease-in-out
ease-linear
end-3
error-message
file-upload-complete:progress-success
fill-base-content
fill-black
fill-gray-200
filter
filter-reset
fixed
flex
flex-1
flex-col
flex-grow
flex-nowrap
flex-row
flex-shrink-0
flex-wrap
focus-visible:outline
focus-visible:outline-2
focus-visible:outline-indigo-600
focus-visible:outline-none
focus-visible:outline-offset-2
focus-within:border-primary
focus:border-primary
focus:outline-1
focus:outline-none
focus:outline-primary
focus:ring-0
focus:ring-2
focus:ring-indigo-600
focus:ring-inset
font-bold
font-inter
font-medium
font-normal
font-semibold
footer
footer-center
from-base-100
from-base-100/20
from-error/20
from-gray-600/20
from-primary/20
from-success/20
from-violet-400
from-warning/20
gap-0.5
gap-1
gap-1.5
gap-2
gap-3
gap-4
gap-5
gap-6
gap-x-1
gap-x-1.5
gap-x-2
gap-x-3
gap-x-5
gap-x-6
gap-y-1
gap-y-1.5
gap-y-2
gap-y-2.5
gap-y-3
gap-y-4
gap-y-5
gap-y-8
grid
grid-cols-1
grid-cols-12
grid-cols-2
grid-cols-3
grid-cols-4
grid-cols-6
grid-flow-col
grow
grow-0
h-0
h-10
h-12
h-14
h-2
h-3
h-32
h-44
h-6
h-64
h-8
h-[90vh]
h-auto
h-full
h-screen
helper-text
hidden
hover:bg-indigo-500
hover:bg-primary/20
hover:bg-primary/5
hover:bg-transparent
hover:cursor-pointer
hover:text-base-content
hover:text-base-content/60
hover:text-indigo-500
hover:text-primary
image-full
indicator
indicator-item
inline
inline-block
inline-flex
inline-grid
input
input-floating
input-floating-label
input-lg
input-md
input-sm
input-xl
input-xs
inset-0
inset-y-0
inset-y-2
invisible
is-invalid
is-valid
isolate
italic
items-center
items-end
items-start
join
join-item
justify-between
justify-center
justify-end
justify-start
justify-stretch
label-text
leading-3
leading-3.5
leading-6
leading-7
leading-9
leading-[1.1]
leading-none
left-0
lg:bg-base-100/20
lg:flex
lg:gap-y-0
lg:grid-cols-2
lg:grid-cols-3
lg:hidden
lg:justify-end
lg:justify-start
lg:mb-0
lg:min-w-0
lg:p-10
lg:p-8
lg:pb-5
lg:pl-64
lg:pr-3.5
lg:pt-5
lg:px-8
lg:ring-1
lg:ring-base-content/10
lg:rounded-lg
lg:shadow-xs
link
link-animated
link-hover
link-primary
list-disc
list-inside
list-none
loading
loading-lg
loading-sm
loading-spinner
loading-xl
loading-xs
lowercase
m-10
mask
max-h-52
max-lg:flex-col
max-lg:hidden
max-md:flex-wrap
max-md:justify-center
max-sm:hidden
max-w-2xl
max-w-7xl
max-w-8
max-w-80
max-w-full
max-w-lg
max-w-md
max-w-none
max-w-sm
max-w-xl
mb-0.5
mb-1
mb-1.5
mb-2
mb-2.5
mb-3
mb-4
mb-5
mb-8
md:col-span-1
md:col-span-2
md:col-span-6
md:flex
md:gap-x-5
md:grid-cols-2
md:grid-cols-3
md:min-w-md
md:table-cell
md:text-3xl
me-0.5
me-1
me-1.5
me-2
me-2.5
me-3
me-4
me-5
menu
menu-active
menu-disabled
menu-dropdown
menu-dropdown-show
menu-focus
menu-horizontal
menu-title
min-h-0
min-h-full
min-h-screen
min-h-svh
min-w-0
min-w-28
min-w-48
min-w-60
min-w-[100px]
min-w-full
min-w-sm
mix-blend-exclusion
ml-3
ml-4
modal
modal-content
modal-dialog
modal-middle
modal-title
mr-2
mr-3
mr-4
ms-0.5
ms-1
ms-1.5
ms-2
ms-2.5
ms-3
ms-5
ms-auto
mt-1
mt-1.5
mt-10
mt-12
mt-2
mt-2.5
mt-3
mt-3.5
mt-4
mt-5
mt-6
mt-8
mt-auto
mx-1
mx-auto
my-2.5
my-3
my-5
my-8
my-auto
object-cover
opacity-0
opacity-100
opacity-75
open
origin-top-left
outline
outline-0
overflow-hidden
overflow-x-auto
overflow-x-hidden
overflow-y-auto
overlay-open:duration-50
overlay-open:opacity-100
p-0.5
p-1
p-1.5
p-2
p-2.5
p-3
p-4
p-5
p-6
p-8
pb-1
pe-1.5
pin-input
pin-input-underline
placeholder-base-content/50
placeholder-base-content/60
placeholder:text-gray-600
pointer-events-auto
pointer-events-none
progress
progress-bar
progress-indeterminate
progress-primary
pt-0
pt-0.5
pt-1.5
pt-2
pt-3
pt-6
px-1.5
px-2
px-2.5
px-3
px-4
px-5
px-6
py-0.5
py-1
py-1.5
py-10
py-12
py-2
py-2.5
py-3
py-3.5
py-6
radial-progress
radio
range
relative
resize
right-4
ring
ring-0
ring-1
ring-gray-700
ring-inset
ring-white/10
rounded-box
rounded-field
rounded-full
rounded-l-none
rounded-lg
rounded-md
rounded-none
rounded-r-none
rounded-t-lg
rounded-xl
row-active
row-hover
rtl:!mr-0
select
select-disabled:opacity-40
select-disabled:pointer-events-none
select-floating
select-floating-label
select-lg
select-md
select-sm
select-xl
select-xs
selected
selected:select-active
shadow
shadow-base-300/20
shadow-lg
shadow-md
shadow-sm
shadow-xs
shrink-0
size-10
size-12
size-4
size-5
size-7
size-8
skeleton
skeleton-animated
sm:auto-cols-max
sm:col-span-2
sm:col-span-3
sm:col-span-4
sm:col-span-6
sm:flex
sm:flex-nowrap
sm:gap-y-0
sm:grid-cols-2
sm:grid-cols-3
sm:grid-cols-6
sm:items-center
sm:items-end
sm:justify-between
sm:justify-end
sm:leading-6
sm:max-w-2xl
sm:max-w-3xl
sm:max-w-4xl
sm:max-w-5xl
sm:max-w-6xl
sm:max-w-7xl
sm:max-w-[480px]
sm:max-w-lg
sm:max-w-md
sm:max-w-xl
sm:mb-0
sm:min-w-md
sm:mr-3
sm:mt-5
sm:mt-6
sm:mx-auto
sm:p-6
sm:px-12
sm:px-6
sm:py-2
sm:rounded-lg
sm:text-sm
sm:text-sm/5
sm:w-1/2
sm:w-full
space-x-1
space-x-2
space-x-2.5
space-y-1
space-y-4
space-y-6
sr-only
stack
stat
stat-actions
stat-desc
stat-figure
stat-title
stat-value
static
stats
stats-border
status
status-error
status-primary
status-secondary
status-success
status-warning
status-xl
sticky
success-message
switch
switch-primary
tab
tab-active
tab-content
table
table-pin-cols
table-pin-rows
tabs
tabs-bordered
tabs-lg
tabs-lifted
tabs-md
tabs-sm
tabs-vertical
tabs-xl
tabs-xs
text-2xl
text-3xl
text-4xl
text-accent
text-base
text-base-content
text-base-content/40
text-base-content/50
text-base-content/60
text-base-content/70
text-base-content/80
text-base-content/90
text-base/6
text-center
text-error
text-error-content
text-gray-100
text-gray-400
text-gray-500
text-gray-700
text-indigo-600
text-info
text-info-content
text-left
text-lg
text-primary
text-primary-content
text-right
text-slate-100
text-sm
text-sm/5
text-success
text-success-content
text-transparent
text-warning
text-warning-content
text-white
text-xl
text-xl!
text-xs
text-xs/5
textarea
textarea-floating
textarea-floating-label
textarea-lg
textarea-md
textarea-sm
textarea-xl
textarea-xs
theme-controller
to-25%
to-base-100/75
to-purple-400
tooltip
tooltip-content
top-0
top-1/2
top-4
top-full
tracking-tight
tracking-wide
transform
transition
transition-all
transition-opacity
translate-x-0
truncate
underline
uppercase
validate
via-sky-400
w-0
w-0.5
w-12
w-13
w-32
w-4
w-56
w-64
w-8
w-auto
w-fit
w-full
whitespace-nowrap
xl:grid-cols-3
xl:grid-cols-4
z-1
z-10
z-40
z-50

View File

@@ -1,5 +1,4 @@
@using System.Diagnostics.CodeAnalysis
@using Microsoft.AspNetCore.Components
@* TODO: Extract to mooncore? *@

View File

@@ -1,4 +1,3 @@
@using System.Text.Json.Serialization
@using Microsoft.Extensions.Logging
@using XtermBlazor
@inherits MoonCore.Blazor.FlyonUi.Modals.Components.BaseModal
@@ -15,11 +14,11 @@
Addons="Parent.Addons"
Options="Parent.Options"
Class="h-full w-full"
OnFirstRender="HandleFirstRender"/>
OnFirstRender="HandleFirstRenderAsync"/>
}
<div class="absolute top-4 right-4">
<button @onclick="Hide" class="btn btn-error btn-square">
<button @onclick="HideAsync" class="btn btn-error btn-square">
<i class="icon-x text-lg"></i>
</button>
</div>
@@ -50,13 +49,13 @@
}
// Subscribe to parent events
Parent.OnWrite += HandleWrite;
Parent.OnWrite += HandleWriteAsync;
IsInitialized = true;
await InvokeAsync(StateHasChanged);
}
private async Task HandleFirstRender()
private async Task HandleFirstRenderAsync()
{
IsReadyToWrite = true;
@@ -73,7 +72,7 @@
await Terminal.Write(outputToWrite);
}
private async Task HandleWrite(string content)
private async Task HandleWriteAsync(string content)
{
if (!IsReadyToWrite)
return;
@@ -83,7 +82,7 @@
public async ValueTask DisposeAsync()
{
Parent.OnWrite -= HandleWrite;
Parent.OnWrite -= HandleWriteAsync;
await Terminal.DisposeAsync();
}
}

View File

@@ -3,25 +3,38 @@
@inherits MoonCore.Blazor.FlyonUi.Modals.Components.BaseModal
<h1 class="mb-5 font-semibold text-xl">Add a new allocation</h1>
<HandleForm @ref="HandleForm" Model="Form" OnValidSubmit="OnValidSubmit">
<div class="grid grid-cols-1 gap-2">
<div class="col-span-1">
<label class="block text-sm font-medium leading-6 text-base-content">IP Address</label>
<input @bind="Form.IpAddress" type="text" class="input w-full"/>
<div class="p-5">
<div class="flex items-center gap-4">
<div class="avatar avatar-placeholder max-sm:hidden">
<div class="border-base-content/20 rounded-box w-13 border-1">
<span class="icon-ethernet-port text-xl"></span>
</div>
</div>
<div class="col-span-1">
<label class="block text-sm font-medium leading-6 text-base-content">Port</label>
<input @bind="Form.Port" type="text" class="input w-full"/>
<div class="space-y-1">
<h3 class="text-base-content text-2xl font-semibold">Add a new allocation</h3>
<p class="text-base-content/80">Add a new allocation to the selected node</p>
</div>
</div>
</HandleForm>
<div class="mt-5 flex space-x-2">
<WButton OnClick="_ => Hide()" CssClasses="btn btn-secondary grow">Cancel</WButton>
<WButton OnClick="_ => Submit()" CssClasses="btn btn-primary grow">Create</WButton>
<div class="mt-5">
<HandleForm @ref="HandleForm" Model="Form" OnValidSubmit="OnValidSubmit">
<div class="mt-2">
<label class="label-text">IP Address</label>
<input class="input" @bind="Form.IpAddress" type="text"/>
</div>
<div class="mt-2">
<label class="label-text">Port</label>
<input class="input" @bind="Form.Port" type="number"/>
</div>
</HandleForm>
</div>
<div class="mt-5 flex justify-end">
<button @onclick="HideAsync" type="button" class="btn btn-secondary me-2">
Cancel
</button>
<WButton OnClick="SubmitAsync">
Create
</WButton>
</div>
</div>
@code
@@ -42,8 +55,8 @@
private async Task OnValidSubmit()
{
await OnSubmit.Invoke(Form);
await Hide();
await HideAsync();
}
private Task Submit() => HandleForm.Submit();
private Task SubmitAsync() => HandleForm.SubmitAsync();
}

View File

@@ -3,30 +3,42 @@
@inherits MoonCore.Blazor.FlyonUi.Modals.Components.BaseModal
<h1 class="mb-5 font-semibold text-xl">Add a range of new allocations</h1>
<HandleForm @ref="HandleForm" Model="Form" OnValidSubmit="OnValidSubmit">
<div class="grid grid-cols-1 gap-2">
<div class="col-span-1">
<label class="block text-sm font-medium leading-6 text-base-content">IP Address</label>
<input @bind="Form.IpAddress" type="text" class="input w-full"/>
<div class="p-5">
<div class="flex items-center gap-4">
<div class="avatar avatar-placeholder max-sm:hidden">
<div class="border-base-content/20 rounded-box w-13 border-1">
<span class="icon-ethernet-port text-xl"></span>
</div>
</div>
<div class="col-span-1">
<label class="block text-sm font-medium leading-6 text-base-content">Start Port</label>
<input @bind="Form.Start" type="text" class="input w-full"/>
</div>
<div class="col-span-1">
<label class="block text-sm font-medium leading-6 text-base-content">End Port</label>
<input @bind="Form.End" type="text" class="input w-full"/>
<div class="space-y-1">
<h3 class="text-base-content text-2xl font-semibold">Add multiple allocations</h3>
<p class="text-base-content/80">Add a range of new allocations to the selected node</p>
</div>
</div>
</HandleForm>
<div class="mt-5 flex space-x-2">
<WButton OnClick="_ => Hide()" CssClasses="btn btn-secondary grow">Cancel</WButton>
<WButton OnClick="_ => Submit()" CssClasses="btn btn-primary grow">Create</WButton>
<div class="mt-5">
<HandleForm @ref="HandleForm" Model="Form" OnValidSubmit="OnValidSubmit">
<div class="mt-2">
<label class="label-text">IP Address</label>
<input class="input" @bind="Form.IpAddress" type="text"/>
</div>
<div class="mt-2">
<label class="label-text">Start Port</label>
<input class="input" @bind="Form.Start" type="number"/>
</div>
<div class="mt-2">
<label class="label-text">End Port</label>
<input class="input" @bind="Form.End" type="number"/>
</div>
</HandleForm>
</div>
<div class="mt-5 flex justify-end">
<button @onclick="HideAsync" type="button" class="btn btn-secondary me-2">
Cancel
</button>
<WButton OnClick="SubmitAsync">
Create
</WButton>
</div>
</div>
@code
@@ -49,8 +61,8 @@
private async Task OnValidSubmit()
{
await OnSubmit.Invoke(Form);
await Hide();
await HideAsync();
}
private Task Submit() => HandleForm.Submit();
private Task SubmitAsync() => HandleForm.SubmitAsync();
}

View File

@@ -4,25 +4,38 @@
@inherits MoonCore.Blazor.FlyonUi.Modals.Components.BaseModal
<h1 class="mb-5 font-semibold text-xl">Update allocation</h1>
<HandleForm @ref="HandleForm" Model="Form" OnValidSubmit="OnValidSubmit">
<div class="grid grid-cols-1 gap-2">
<div class="col-span-1">
<label class="block text-sm font-medium leading-6 text-base-content">IP Address</label>
<input @bind="Form.IpAddress" type="text" class="input w-full"/>
<div class="p-5">
<div class="flex items-center gap-4">
<div class="avatar avatar-placeholder max-sm:hidden">
<div class="border-base-content/20 rounded-box w-13 border-1">
<span class="icon-ethernet-port text-xl"></span>
</div>
</div>
<div class="col-span-1">
<label class="block text-sm font-medium leading-6 text-base-content">Port</label>
<input @bind="Form.Port" type="text" class="input w-full"/>
<div class="space-y-1">
<h3 class="text-base-content text-2xl font-semibold">Update allocation</h3>
<p class="text-base-content/80">Update an existing allocation</p>
</div>
</div>
</HandleForm>
<div class="mt-5 flex space-x-2">
<WButton OnClick="_ => Hide()" CssClasses="btn btn-secondary grow">Cancel</WButton>
<WButton OnClick="_ => Submit()" CssClasses="btn btn-primary grow">Update</WButton>
<div class="mt-5">
<HandleForm @ref="HandleForm" Model="Form" OnValidSubmit="OnValidSubmit">
<div class="mt-2">
<label class="label-text">IP Address</label>
<input class="input" @bind="Form.IpAddress" type="text"/>
</div>
<div class="mt-2">
<label class="label-text">Port</label>
<input class="input" @bind="Form.Port" type="number"/>
</div>
</HandleForm>
</div>
<div class="mt-5 flex justify-end">
<button @onclick="HideAsync" type="button" class="btn btn-secondary me-2">
Cancel
</button>
<WButton OnClick="SubmitAsync">
Update
</WButton>
</div>
</div>
@code
@@ -45,8 +58,8 @@
private async Task OnValidSubmit()
{
await OnSubmit.Invoke(Form);
await Hide();
await HideAsync();
}
private Task Submit() => HandleForm.Submit();
private Task SubmitAsync() => HandleForm.SubmitAsync();
}

View File

@@ -2,26 +2,7 @@
@using MoonlightServers.Shared.Http.Requests.Admin.Nodes
<div class="grid grid-cols-1 gap-x-6 gap-y-8 sm:grid-cols-6">
<div class="sm:col-span-2">
<label class="block text-sm font-medium leading-6 text-base-content">Enable Transparent
Mode
</label>
<div class="mt-2">
<div class="flex items-center">
<Switch @bind-Value="Request.EnableTransparentMode"/>
</div>
</div>
</div>
<div class="sm:col-span-2">
<label class="block text-sm font-medium leading-6 text-base-content">
Enable Dynamic Firewall
</label>
<div class="mt-2">
<div class="flex items-center">
<Switch @bind-Value="Request.EnableDynamicFirewall"/>
</div>
</div>
</div>
</div>
@code

Some files were not shown because too many files have changed in this diff Show More