diff --git a/MoonlightServers.ApiServer/Database/Entities/Star.cs b/MoonlightServers.ApiServer/Database/Entities/Star.cs index 1bc15b0..927d2ed 100644 --- a/MoonlightServers.ApiServer/Database/Entities/Star.cs +++ b/MoonlightServers.ApiServer/Database/Entities/Star.cs @@ -28,5 +28,6 @@ public class Star // Misc public int RequiredAllocations { get; set; } public bool AllowDockerImageChange { get; set; } + public int DefaultDockerImage { get; set; } public string ParseConfiguration { get; set; } } \ No newline at end of file diff --git a/MoonlightServers.ApiServer/Database/Migrations/20241211075318_AddedDefaultDockerImageField.Designer.cs b/MoonlightServers.ApiServer/Database/Migrations/20241211075318_AddedDefaultDockerImageField.Designer.cs new file mode 100644 index 0000000..131800f --- /dev/null +++ b/MoonlightServers.ApiServer/Database/Migrations/20241211075318_AddedDefaultDockerImageField.Designer.cs @@ -0,0 +1,434 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using MoonlightServers.ApiServer.Database; + +#nullable disable + +namespace MoonlightServers.ApiServer.Database.Migrations +{ + [DbContext(typeof(ServersDataContext))] + [Migration("20241211075318_AddedDefaultDockerImageField")] + partial class AddedDefaultDockerImageField + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasDefaultSchema("Servers") + .HasAnnotation("ProductVersion", "8.0.11") + .HasAnnotation("Relational:MaxIdentifierLength", 64); + + MySqlModelBuilderExtensions.AutoIncrementColumns(modelBuilder); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Allocation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("IpAddress") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("NodeId") + .HasColumnType("int"); + + b.Property("Port") + .HasColumnType("int"); + + b.Property("ServerId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("NodeId"); + + b.HasIndex("ServerId"); + + b.ToTable("Allocations", "Servers"); + }); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Node", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("EnableDynamicFirewall") + .HasColumnType("tinyint(1)"); + + b.Property("EnableTransparentMode") + .HasColumnType("tinyint(1)"); + + b.Property("Fqdn") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("FtpPort") + .HasColumnType("int"); + + b.Property("HttpPort") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Token") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.ToTable("Nodes", "Servers"); + }); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Server", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("Bandwidth") + .HasColumnType("int"); + + b.Property("Cpu") + .HasColumnType("int"); + + b.Property("Disk") + .HasColumnType("int"); + + b.Property("DockerImageIndex") + .HasColumnType("int"); + + b.Property("Memory") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("NodeId") + .HasColumnType("int"); + + b.Property("OwnerId") + .HasColumnType("int"); + + b.Property("StarId") + .HasColumnType("int"); + + b.Property("StartupOverride") + .HasColumnType("longtext"); + + b.Property("UseVirtualDisk") + .HasColumnType("tinyint(1)"); + + b.HasKey("Id"); + + b.HasIndex("NodeId"); + + b.HasIndex("StarId"); + + b.ToTable("Servers", "Servers"); + }); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.ServerBackup", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("Completed") + .HasColumnType("tinyint(1)"); + + b.Property("CompletedAt") + .HasColumnType("datetime(6)"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("Size") + .HasColumnType("bigint"); + + b.Property("Successful") + .HasColumnType("tinyint(1)"); + + b.HasKey("Id"); + + b.ToTable("ServerBackups", "Servers"); + }); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.ServerVariable", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("Key") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("ServerId") + .HasColumnType("int"); + + b.Property("Value") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.HasIndex("ServerId"); + + b.ToTable("ServerVariables", "Servers"); + }); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Star", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("AllowDockerImageChange") + .HasColumnType("tinyint(1)"); + + b.Property("Author") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("DefaultDockerImage") + .HasColumnType("int"); + + b.Property("DonateUrl") + .HasColumnType("longtext"); + + b.Property("InstallDockerImage") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("InstallScript") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("InstallShell") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("OnlineDetection") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("ParseConfiguration") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("RequiredAllocations") + .HasColumnType("int"); + + b.Property("StartupCommand") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("StopCommand") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("UpdateUrl") + .HasColumnType("longtext"); + + b.Property("Version") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.ToTable("Stars", "Servers"); + }); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.StarDockerImage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("AutoPulling") + .HasColumnType("tinyint(1)"); + + b.Property("DisplayName") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Identifier") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("StarId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("StarId"); + + b.ToTable("StarDockerImages", "Servers"); + }); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.StarVariable", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("AllowEditing") + .HasColumnType("tinyint(1)"); + + b.Property("AllowViewing") + .HasColumnType("tinyint(1)"); + + b.Property("DefaultValue") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Description") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Filter") + .HasColumnType("longtext"); + + b.Property("Key") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("StarId") + .HasColumnType("int"); + + b.Property("Type") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("StarId"); + + b.ToTable("StarVariables", "Servers"); + }); + + 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.ServerVariable", b => + { + b.HasOne("MoonlightServers.ApiServer.Database.Entities.Server", "Server") + .WithMany() + .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"); + }); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Star", b => + { + b.Navigation("DockerImages"); + + b.Navigation("Variables"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/MoonlightServers.ApiServer/Database/Migrations/20241211075318_AddedDefaultDockerImageField.cs b/MoonlightServers.ApiServer/Database/Migrations/20241211075318_AddedDefaultDockerImageField.cs new file mode 100644 index 0000000..5b5cf05 --- /dev/null +++ b/MoonlightServers.ApiServer/Database/Migrations/20241211075318_AddedDefaultDockerImageField.cs @@ -0,0 +1,31 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace MoonlightServers.ApiServer.Database.Migrations +{ + /// + public partial class AddedDefaultDockerImageField : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "DefaultDockerImage", + schema: "Servers", + table: "Stars", + type: "int", + nullable: false, + defaultValue: 0); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "DefaultDockerImage", + schema: "Servers", + table: "Stars"); + } + } +} diff --git a/MoonlightServers.ApiServer/Database/Migrations/ServersDataContextModelSnapshot.cs b/MoonlightServers.ApiServer/Database/Migrations/ServersDataContextModelSnapshot.cs index 2696ba2..ce53445 100644 --- a/MoonlightServers.ApiServer/Database/Migrations/ServersDataContextModelSnapshot.cs +++ b/MoonlightServers.ApiServer/Database/Migrations/ServersDataContextModelSnapshot.cs @@ -210,6 +210,9 @@ namespace MoonlightServers.ApiServer.Database.Migrations .IsRequired() .HasColumnType("longtext"); + b.Property("DefaultDockerImage") + .HasColumnType("int"); + b.Property("DonateUrl") .HasColumnType("longtext"); diff --git a/MoonlightServers.ApiServer/Http/Controllers/Admin/Stars/StarsController.cs b/MoonlightServers.ApiServer/Http/Controllers/Admin/Stars/StarsController.cs index d62e043..7b743ce 100644 --- a/MoonlightServers.ApiServer/Http/Controllers/Admin/Stars/StarsController.cs +++ b/MoonlightServers.ApiServer/Http/Controllers/Admin/Stars/StarsController.cs @@ -75,6 +75,7 @@ public class StarsController : Controller star.InstallScript = "echo Installing..."; star.RequiredAllocations = 1; star.AllowDockerImageChange = false; + star.DefaultDockerImage = -1; star.ParseConfiguration = "[]"; var finalStar = StarRepository.Add(star); diff --git a/MoonlightServers.ApiServer/Models/Stars/StarExportModel.cs b/MoonlightServers.ApiServer/Models/Stars/StarExportModel.cs index 5c06c28..6a50f01 100644 --- a/MoonlightServers.ApiServer/Models/Stars/StarExportModel.cs +++ b/MoonlightServers.ApiServer/Models/Stars/StarExportModel.cs @@ -24,6 +24,7 @@ public class StarExportModel // Misc public int RequiredAllocations { get; set; } public bool AllowDockerImageChange { get; set; } + public int DefaultDockerImage { get; set; } public string ParseConfiguration { get; set; } // Relations diff --git a/MoonlightServers.ApiServer/Services/StarImportExportService.cs b/MoonlightServers.ApiServer/Services/StarImportExportService.cs index 7d5cfbf..253eeb7 100644 --- a/MoonlightServers.ApiServer/Services/StarImportExportService.cs +++ b/MoonlightServers.ApiServer/Services/StarImportExportService.cs @@ -50,6 +50,7 @@ public class StarImportExportService ParseConfiguration = star.ParseConfiguration, RequiredAllocations = star.RequiredAllocations, AllowDockerImageChange = star.AllowDockerImageChange, + DefaultDockerImage = star.DefaultDockerImage, Variables = star.Variables.Select(x => new StarExportModel.StarVariableExportModel() { Name = x.Name, @@ -117,6 +118,7 @@ public class StarImportExportService ParseConfiguration = model.ParseConfiguration, RequiredAllocations = model.RequiredAllocations, AllowDockerImageChange = model.AllowDockerImageChange, + DefaultDockerImage = model.DefaultDockerImage, Variables = model.Variables.Select(x => new StarVariable() { DefaultValue = x.DefaultValue, @@ -173,6 +175,7 @@ public class StarImportExportService StartupCommand = model.StartupCommand, RequiredAllocations = model.AllocationsNeeded, AllowDockerImageChange = model.AllowDockerImageChange, + DefaultDockerImage = model.DefaultDockerImage, Variables = model.Variables.Select(x => new StarVariable() { DefaultValue = x.DefaultValue, diff --git a/MoonlightServers.ApiServer/Startup/PluginStartup.cs b/MoonlightServers.ApiServer/Startup/PluginStartup.cs index c08da29..6bcb49e 100644 --- a/MoonlightServers.ApiServer/Startup/PluginStartup.cs +++ b/MoonlightServers.ApiServer/Startup/PluginStartup.cs @@ -6,12 +6,10 @@ namespace MoonlightServers.ApiServer.Startup; public class PluginStartup : IAppStartup { - private readonly ILogger Logger; private readonly BundleService BundleService; - public PluginStartup(ILogger logger, BundleService bundleService) + public PluginStartup(BundleService bundleService) { - Logger = logger; BundleService = bundleService; } diff --git a/MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/DockerImageStarUpdate.razor b/MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/DockerImageStarUpdate.razor index dec212c..cebdf3f 100644 --- a/MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/DockerImageStarUpdate.razor +++ b/MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/DockerImageStarUpdate.razor @@ -14,12 +14,12 @@ @inject ToastService ToastService @inject AlertService AlertService -
- -
- -
+
+ +
+ +
@foreach (var dockerImage in DockerImages) {
diff --git a/MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/InstallationStarUpdate.razor b/MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/InstallationStarUpdate.razor index 22b3913..69f06ac 100644 --- a/MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/InstallationStarUpdate.razor +++ b/MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/InstallationStarUpdate.razor @@ -1,4 +1,5 @@ @using MoonlightServers.Shared.Http.Requests.Admin.Stars +
diff --git a/MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/MiscStarUpdate.razor b/MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/MiscStarUpdate.razor new file mode 100644 index 0000000..2864f06 --- /dev/null +++ b/MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/MiscStarUpdate.razor @@ -0,0 +1,67 @@ +@using MoonCore.Blazor.Tailwind.Components +@using MoonCore.Helpers +@using MoonCore.Models +@using MoonlightServers.Shared.Http.Requests.Admin.Stars +@using MoonlightServers.Shared.Http.Responses.Admin.StarDockerImages +@using MoonlightServers.Shared.Http.Responses.Admin.Stars +@using MoonlightServers.Frontend.UI.Components.Forms + +@inject HttpApiClient ApiClient + + +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+
+ +@code +{ + [Parameter] public UpdateStarRequest Request { get; set; } + [Parameter] public StarDetailResponse Star { get; set; } + + private List DockerImages; + + private async Task Load(LazyLoader _) + { + var pagedVariables = await ApiClient.GetJson>( + $"api/admin/servers/stars/{Star.Id}/dockerImages?page=0&pageSize=50" + ); + + DockerImages = pagedVariables + .Items + .OrderBy(x => x.Id) // Make sure its in the correct order every time + .ToList(); + } +} \ No newline at end of file diff --git a/MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/VariablesStarUpdate.razor b/MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/VariablesStarUpdate.razor index 2477c63..8f41803 100644 --- a/MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/VariablesStarUpdate.razor +++ b/MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/VariablesStarUpdate.razor @@ -1,6 +1,4 @@ @using MoonCore.Blazor.Tailwind.Alerts -@using MoonlightServers.Shared.Http.Responses.Admin.Stars -@using MoonlightServers.Shared.Http.Responses.Admin.StarVariables @using MoonCore.Blazor.Tailwind.Components @using MoonCore.Blazor.Tailwind.Modals @using MoonCore.Blazor.Tailwind.Toasts @@ -8,6 +6,8 @@ @using MoonCore.Models @using MoonlightServers.Frontend.UI.Components.Stars.Modals @using MoonlightServers.Shared.Http.Requests.Admin.StarVariables +@using MoonlightServers.Shared.Http.Responses.Admin.Stars +@using MoonlightServers.Shared.Http.Responses.Admin.StarVariables @inject HttpApiClient ApiClient @inject ModalService ModalService diff --git a/MoonlightServers.Frontend/UI/Views/Admin/Stars/Index.razor b/MoonlightServers.Frontend/UI/Views/Admin/Stars/Index.razor index 8549cca..33a05da 100644 --- a/MoonlightServers.Frontend/UI/Views/Admin/Stars/Index.razor +++ b/MoonlightServers.Frontend/UI/Views/Admin/Stars/Index.razor @@ -35,7 +35,7 @@ @if (!string.IsNullOrEmpty(context.DonateUrl)) { - + Donate diff --git a/MoonlightServers.Frontend/UI/Views/Admin/Stars/Update.razor b/MoonlightServers.Frontend/UI/Views/Admin/Stars/Update.razor index f426f75..4b0c8e2 100644 --- a/MoonlightServers.Frontend/UI/Views/Admin/Stars/Update.razor +++ b/MoonlightServers.Frontend/UI/Views/Admin/Stars/Update.razor @@ -51,6 +51,10 @@ + + + + diff --git a/MoonlightServers.Shared/Http/Requests/Admin/Stars/UpdateStarRequest.cs b/MoonlightServers.Shared/Http/Requests/Admin/Stars/UpdateStarRequest.cs index d684775..285baf1 100644 --- a/MoonlightServers.Shared/Http/Requests/Admin/Stars/UpdateStarRequest.cs +++ b/MoonlightServers.Shared/Http/Requests/Admin/Stars/UpdateStarRequest.cs @@ -42,6 +42,7 @@ public class UpdateStarRequest public int RequiredAllocations { get; set; } public bool AllowDockerImageChange { get; set; } + public int DefaultDockerImage { get; set; } [Required(ErrorMessage = "You need to provide parse configuration")] public string ParseConfiguration { get; set; } diff --git a/MoonlightServers.Shared/Http/Responses/Admin/Stars/StarDetailResponse.cs b/MoonlightServers.Shared/Http/Responses/Admin/Stars/StarDetailResponse.cs index c51eb11..7dac373 100644 --- a/MoonlightServers.Shared/Http/Responses/Admin/Stars/StarDetailResponse.cs +++ b/MoonlightServers.Shared/Http/Responses/Admin/Stars/StarDetailResponse.cs @@ -31,5 +31,6 @@ public class StarDetailResponse // Misc public int RequiredAllocations { get; set; } public bool AllowDockerImageChange { get; set; } + public int DefaultDockerImage { get; set; } public string ParseConfiguration { get; set; } } \ No newline at end of file