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:
@@ -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; }
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
using MoonlightServers.DaemonShared.Enums;
|
||||
using MoonlightServers.Shared.Enums;
|
||||
using ServerState = MoonlightServers.Shared.Enums.ServerState;
|
||||
|
||||
namespace MoonlightServers.ApiServer.Extensions;
|
||||
|
||||
@@ -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
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
@@ -62,27 +62,27 @@ public class NodesController : Controller
|
||||
|
||||
if (node == null)
|
||||
return Problem("No node with this id found", statusCode: 404);
|
||||
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
[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()
|
||||
@@ -107,8 +107,8 @@ 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();
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
)
|
||||
@@ -104,16 +104,16 @@ public class StarsController : Controller
|
||||
|
||||
if (star == null)
|
||||
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()
|
||||
@@ -121,8 +121,8 @@ 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();
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,18 +239,18 @@ 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
|
||||
);
|
||||
|
||||
|
||||
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,14 +259,14 @@ 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
|
||||
);
|
||||
|
||||
|
||||
if (serverResult.Value == null)
|
||||
return serverResult.Result ?? Problem("Unable to retrieve server");
|
||||
|
||||
@@ -292,18 +293,18 @@ 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
|
||||
);
|
||||
|
||||
|
||||
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,18 +313,18 @@ 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
|
||||
);
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user