Skip to content

Commit 77abdd8

Browse files
authored
Merge pull request #445 from Moonlight-Panel/v2.1_OptimizeNugetBuilding
Optimize nuget building. Refactored startup. Fixed smaller issues
2 parents 4baa0bb + 7599a7d commit 77abdd8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+969
-1018
lines changed

.dockerignore

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,35 @@
1-
using Moonlight.ApiServer;
2-
using Moonlight.ApiServer.Runtime;
3-
4-
var startup = new Startup();
1+
using Moonlight.ApiServer.Runtime;
2+
using Moonlight.ApiServer.Startup;
53

64
var pluginLoader = new PluginLoader();
75
pluginLoader.Initialize();
6+
/*
7+
await startup.Run(args, pluginLoader.Instances);
8+
9+
*/
10+
11+
var cs = new Startup();
12+
13+
await cs.Initialize(args, pluginLoader.Instances);
14+
15+
var builder = WebApplication.CreateBuilder(args);
16+
17+
await cs.AddMoonlight(builder);
18+
19+
var app = builder.Build();
20+
21+
await cs.AddMoonlight(app);
22+
23+
// Handle setup of wasm app hosting in the runtime
24+
// so the Moonlight.ApiServer doesn't need the wasm package
25+
if (cs.Configuration.Frontend.EnableHosting)
26+
{
27+
if (app.Environment.IsDevelopment())
28+
app.UseWebAssemblyDebugging();
29+
30+
app.UseBlazorFrameworkFiles();
31+
app.UseStaticFiles();
32+
}
33+
834

9-
await startup.Run(args, pluginLoader.Instances);
35+
await app.RunAsync();
Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,45 @@
11
using MoonCore.Helpers;
2+
using YamlDotNet.Serialization;
23

34
namespace Moonlight.ApiServer.Configuration;
45

5-
public class AppConfiguration
6+
public record AppConfiguration
67
{
8+
[YamlMember(Description = "The public url your instance should be accessible through")]
79
public string PublicUrl { get; set; } = "http://localhost:5165";
810

11+
[YamlMember(Description = "The credentials of the postgres which moonlight should use")]
912
public DatabaseConfig Database { get; set; } = new();
13+
14+
[YamlMember(Description = "Settings regarding authentication")]
1015
public AuthenticationConfig Authentication { get; set; } = new();
16+
17+
[YamlMember(Description = "These options are only meant for development purposes")]
1118
public DevelopmentConfig Development { get; set; } = new();
12-
public ClientConfig Client { get; set; } = new();
19+
public FrontendData Frontend { get; set; } = new();
1320
public KestrelConfig Kestrel { get; set; } = new();
1421
public MetricsData Metrics { get; set; } = new();
1522

16-
public class ClientConfig
23+
public static AppConfiguration CreateEmpty()
1724
{
18-
public bool Enable { get; set; } = true;
25+
return new AppConfiguration()
26+
{
27+
// Set arrays as empty here
28+
29+
Kestrel = new()
30+
{
31+
AllowedOrigins = []
32+
}
33+
};
34+
}
35+
36+
public record FrontendData
37+
{
38+
[YamlMember(Description = "Enable the hosting of the frontend. Disable this if you only want to run the api server")]
39+
public bool EnableHosting { get; set; } = true;
1940
}
2041

21-
public class DatabaseConfig
42+
public record DatabaseConfig
2243
{
2344
public string Host { get; set; } = "your-database-host.name";
2445
public int Port { get; set; } = 5432;
@@ -29,15 +50,19 @@ public class DatabaseConfig
2950
public string Database { get; set; } = "db_name";
3051
}
3152

32-
public class AuthenticationConfig
53+
public record AuthenticationConfig
3354
{
55+
[YamlMember(Description = "The secret token to use for creating jwts and encrypting things. This needs to be at least 32 characters long")]
3456
public string Secret { get; set; } = Formatter.GenerateString(32);
57+
58+
[YamlMember(Description = "The lifespan of generated user tokens in hours")]
3559
public int TokenDuration { get; set; } = 24 * 10;
3660

61+
[YamlMember(Description = "This enables the use of the local oauth2 provider, so moonlight will use itself as an oauth2 provider")]
3762
public bool EnableLocalOAuth2 { get; set; } = true;
3863
public OAuth2Data OAuth2 { get; set; } = new();
3964

40-
public class OAuth2Data
65+
public record OAuth2Data
4166
{
4267
public string Secret { get; set; } = Formatter.GenerateString(32);
4368
public string ClientId { get; set; } = Formatter.GenerateString(8);
@@ -46,24 +71,32 @@ public class OAuth2Data
4671
public string? AccessEndpoint { get; set; }
4772
public string? AuthorizationRedirect { get; set; }
4873

74+
[YamlMember(Description = "This specifies if the first registered user will become an admin automatically. This only works when using local oauth2")]
4975
public bool FirstUserAdmin { get; set; } = true;
5076
}
5177
}
5278

53-
public class DevelopmentConfig
79+
public record DevelopmentConfig
5480
{
81+
[YamlMember(Description = "This toggles the availability of the api docs via /api/swagger")]
5582
public bool EnableApiDocs { get; set; } = false;
5683
}
5784

58-
public class KestrelConfig
85+
public record KestrelConfig
5986
{
87+
[YamlMember(Description = "The upload limit in megabytes for the api server")]
6088
public int UploadLimit { get; set; } = 100;
61-
public string AllowedOrigins { get; set; } = "*";
89+
90+
[YamlMember(Description = "The allowed origins for the api server. Use * to allow all origins (which is not advised)")]
91+
public string[] AllowedOrigins { get; set; } = ["*"];
6292
}
6393

64-
public class MetricsData
94+
public record MetricsData
6595
{
96+
[YamlMember(Description = "This enables the collecting of metrics and allows access to the /metrics endpoint")]
6697
public bool Enable { get; set; } = false;
98+
99+
[YamlMember(Description = "The interval in which metrics are created, specified in seconds")]
67100
public int Interval { get; set; } = 15;
68101
}
69102
}

Moonlight.ApiServer/Database/Entities/ApiKey.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System.ComponentModel.DataAnnotations.Schema;
2-
3-
namespace Moonlight.ApiServer.Database.Entities;
1+
namespace Moonlight.ApiServer.Database.Entities;
42

53
public class ApiKey
64
{

Moonlight.ApiServer/Database/Entities/User.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System.ComponentModel.DataAnnotations.Schema;
2-
3-
namespace Moonlight.ApiServer.Database.Entities;
1+
namespace Moonlight.ApiServer.Database.Entities;
42

53
public class User
64
{

Moonlight.ApiServer/Http/Controllers/Admin/Sys/AdvancedController.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Microsoft.AspNetCore.Authorization;
2+
using Microsoft.AspNetCore.Http;
23
using Microsoft.AspNetCore.Mvc;
34
using Moonlight.ApiServer.Services;
45

Moonlight.ApiServer/Http/Controllers/Admin/Sys/DiagnoseController.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Microsoft.AspNetCore.Authorization;
2+
using Microsoft.AspNetCore.Http;
23
using Microsoft.AspNetCore.Mvc;
34
using Moonlight.ApiServer.Services;
45
using Moonlight.Shared.Http.Requests.Admin.Sys;

Moonlight.ApiServer/Http/Controllers/Admin/Sys/ThemeController.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System.Text.Json;
22
using Microsoft.AspNetCore.Authorization;
33
using Microsoft.AspNetCore.Mvc;
4-
using MoonCore.Helpers;
54
using Moonlight.Shared.Http.Requests.Admin.Sys;
65

76
namespace Moonlight.ApiServer.Http.Controllers.Admin.Sys;

Moonlight.ApiServer/Http/Controllers/Auth/AuthController.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
using System.IdentityModel.Tokens.Jwt;
22
using System.Text;
3-
using System.Text.Json;
43
using Microsoft.AspNetCore.Authorization;
54
using Microsoft.AspNetCore.Mvc;
65
using Microsoft.EntityFrameworkCore;
6+
using Microsoft.Extensions.Logging;
77
using Microsoft.IdentityModel.Tokens;
88
using MoonCore.Exceptions;
99
using MoonCore.Extended.Abstractions;
10-
using MoonCore.Helpers;
1110
using Moonlight.ApiServer.Configuration;
1211
using Moonlight.ApiServer.Database.Entities;
1312
using Moonlight.ApiServer.Interfaces;
1413
using Moonlight.Shared.Http.Requests.Auth;
1514
using Moonlight.Shared.Http.Responses.Auth;
16-
using Moonlight.Shared.Http.Responses.OAuth2;
1715

1816
namespace Moonlight.ApiServer.Http.Controllers.Auth;
1917

@@ -76,7 +74,7 @@ public async Task<LoginCompleteResponse> Complete([FromBody] LoginCompleteReques
7674
// Generate token
7775
var securityTokenDescriptor = new SecurityTokenDescriptor()
7876
{
79-
Expires = DateTime.Now.AddYears(Configuration.Authentication.TokenDuration),
77+
Expires = DateTime.Now.AddHours(Configuration.Authentication.TokenDuration),
8078
IssuedAt = DateTime.Now,
8179
NotBefore = DateTime.Now.AddMinutes(-1),
8280
Claims = new Dictionary<string, object>()

Moonlight.ApiServer/Http/Controllers/Frontend/FrontendController.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Text;
2+
using Microsoft.AspNetCore.Http;
23
using Microsoft.AspNetCore.Mvc;
34
using Moonlight.ApiServer.Services;
45
using Moonlight.Shared.Misc;

0 commit comments

Comments
 (0)