1
0

Add server basic functions.

This commit is contained in:
Ca2didi 2025-03-21 01:59:09 +08:00
parent c332d15db6
commit e3f673988f
18 changed files with 273 additions and 0 deletions

View File

@ -6,6 +6,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Flawless.Abstract.Test", "F
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Flawless.Core", "Flawless.Core\Flawless.Core.csproj", "{FA8139D0-FBA4-4F17-9017-B446A732D0E8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Flawless.Communication", "Flawless.Communication\Flawless.Communication.csproj", "{E0C2A8CE-D382-4DF2-9675-1A41833B30F2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Flawless.Server", "Flawless.Server\Flawless.Server.csproj", "{66142212-034C-4702-92FE-5C625D725048}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -24,5 +28,13 @@ Global
{FA8139D0-FBA4-4F17-9017-B446A732D0E8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FA8139D0-FBA4-4F17-9017-B446A732D0E8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FA8139D0-FBA4-4F17-9017-B446A732D0E8}.Release|Any CPU.Build.0 = Release|Any CPU
{E0C2A8CE-D382-4DF2-9675-1A41833B30F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E0C2A8CE-D382-4DF2-9675-1A41833B30F2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E0C2A8CE-D382-4DF2-9675-1A41833B30F2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E0C2A8CE-D382-4DF2-9675-1A41833B30F2}.Release|Any CPU.Build.0 = Release|Any CPU
{66142212-034C-4702-92FE-5C625D725048}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{66142212-034C-4702-92FE-5C625D725048}.Debug|Any CPU.Build.0 = Debug|Any CPU
{66142212-034C-4702-92FE-5C625D725048}.Release|Any CPU.ActiveCfg = Release|Any CPU
{66142212-034C-4702-92FE-5C625D725048}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,7 @@
namespace Flawless.Communication.Authentication;
public record AuthenticationStatus
{
public required bool OpenRegister { get; set; }
public required bool OpenLogin { get; set; }
}

View File

@ -0,0 +1,10 @@
namespace Flawless.Communication.Authentication;
public record LoginRequest
{
public required string Identification { get; init; }
public required string Password { get; init; }
public required bool DontExpireHalfMonth { get; set; }
}

View File

@ -0,0 +1,12 @@
namespace Flawless.Communication.Authentication;
public record RegisterRequest
{
public required string Email { get; set; }
public required string Username { get; set; }
public required string Password { get; set; }
public required bool DontExpireHalfMonth { get; set; }
}

View File

@ -0,0 +1,10 @@
namespace Flawless.Communication.Authentication;
public enum RegisterResultStatus
{
Success,
Forbidden,
Registered
}
public record RegisterResult(RegisterResultStatus Status);

View File

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,6 @@
namespace Flawless.Core.BinaryDataFormat;
public static class DataInserter
{
}

View File

@ -0,0 +1,34 @@
using Flawless.Communication.Authentication;
using Flawless.Server.Models;
using Microsoft.AspNetCore.Mvc;
namespace Flawless.Server.Controllers;
[ApiController, Route("api/auth")]
public class AuthenticationController(FlawlessContext dbContext, ILogger<AuthenticationController> logger)
: ControllerBase
{
[HttpGet("status")]
public ActionResult<AuthenticationStatus> GetStatus()
{
logger.LogInformation("Authentication status has sent to {0}", HttpContext.Connection.RemoteIpAddress);
return new AuthenticationStatus()
{
OpenRegister = true,
OpenLogin = true,
};
}
[HttpPost("register")]
public async Task<ActionResult<RegisterResult>> RegisterAsync(RegisterRequest request)
{
return BadRequest();
}
[HttpPost("login")]
public async Task<ActionResult<string>> LoginAsync([FromBody] LoginRequest request)
{
return "SuccessToken";
}
}

View File

@ -0,0 +1,20 @@
using Microsoft.AspNetCore.Mvc;
namespace Flawless.Server.Controllers;
[ApiController]
[Route("ws/depot/transmission")]
public class DepotTransmissionController : ControllerBase
{
[Route("download/{requestId}")]
public async Task DownloadDepotAsync(string requestId)
{
}
[Route("upload/{requestId}")]
public async Task UploadDepotAsync(string requestId)
{
}
}

View File

@ -0,0 +1,9 @@
using Microsoft.AspNetCore.Mvc;
namespace Flawless.Server.Controllers;
[ApiController, Route("api/repository")]
public class RepositoryController : ControllerBase
{
}

View File

@ -0,0 +1,9 @@
using Microsoft.AspNetCore.Mvc;
namespace Flawless.Server.Controllers;
[ApiController, Route("api/user")]
public class UserController : ControllerBase
{
}

View File

@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="9.0.3" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.2"/>
<PackageReference Include="Microsoft.AspNetCore.WebSockets" Version="2.3.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="9.0.3" />
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="8.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="8.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="8.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Flawless.Abstract\Flawless.Abstract.csproj" />
<ProjectReference Include="..\Flawless.Communication\Flawless.Communication.csproj" />
<ProjectReference Include="..\Flawless.Core\Flawless.Core.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,10 @@
using Microsoft.EntityFrameworkCore;
namespace Flawless.Server.Models;
public class FlawlessContext : DbContext
{
public FlawlessContext(DbContextOptions<FlawlessContext> options) : base(options)
{
}
}

View File

@ -0,0 +1,5 @@
namespace Flawless.Server.Models;
public class FlawlessStorageContext(WebApplication app)
{
}

View File

@ -0,0 +1,54 @@
using Flawless.Server.Controllers;
using Flawless.Server.Models;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.EntityFrameworkCore;
var builder = WebApplication.CreateBuilder(args);
// Api related
builder.Services.AddOpenApi();
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(opt =>
{
opt.DocInclusionPredicate((name, api) => api.HttpMethod != null); // Filter out WebSocket methods
opt.SupportNonNullableReferenceTypes();
});
// Authentication related.
builder.Services.AddAuthentication(opt =>
{
opt.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
opt.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
}).AddJwtBearer(opt =>
{
});
// Data connection related.
builder.Services.AddSingleton<DepotTransmissionController>();
builder.Services.AddDbContext<FlawlessContext>(opt =>
{
opt.UseInMemoryDatabase("Flawless");
});
var app = builder.Build();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseWebSockets(new WebSocketOptions
{
KeepAliveInterval = TimeSpan.FromSeconds(60),
KeepAliveTimeout = TimeSpan.FromSeconds(300),
});
app.MapControllers();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
app.UseSwagger();
app.UseSwaggerUI();
}
app.Run();

View File

@ -0,0 +1,23 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "http://localhost:5256",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "https://localhost:7020;http://localhost:5256",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

View File

@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

View File

@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}