添加项目文件。
This commit is contained in:
19
Atomx.Storage/Atomx.Storage.csproj
Normal file
19
Atomx.Storage/Atomx.Storage.csproj
Normal file
@@ -0,0 +1,19 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Mapster" Version="7.4.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Atomx.Data\Atomx.Data.csproj" />
|
||||
<ProjectReference Include="..\Atomx.Utils\Atomx.Utils.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
6
Atomx.Storage/Atomx.Storage.http
Normal file
6
Atomx.Storage/Atomx.Storage.http
Normal file
@@ -0,0 +1,6 @@
|
||||
@Atomx.Storage_HostAddress = http://localhost:5050
|
||||
|
||||
GET {{Atomx.Storage_HostAddress}}/weatherforecast/
|
||||
Accept: application/json
|
||||
|
||||
###
|
||||
56
Atomx.Storage/Controllers/UploadController.cs
Normal file
56
Atomx.Storage/Controllers/UploadController.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using Atomx.Data;
|
||||
using Atomx.Data.Services;
|
||||
using Atomx.Storage.Services;
|
||||
using MapsterMapper;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Atomx.Storage.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class UploadController : ControllerBase
|
||||
{
|
||||
readonly ILogger<UploadController> _logger;
|
||||
readonly IIdentityService _identityService;
|
||||
readonly IIdCreatorService _idCreator;
|
||||
readonly IMapper _mapper;
|
||||
readonly DataContext _dbContext;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="logger"></param>
|
||||
/// <param name="identityService"></param>
|
||||
/// <param name="idCreator"></param>
|
||||
/// <param name="adminService"></param>
|
||||
/// <param name="mapper"></param>
|
||||
public UploadController(ILogger<UploadController> logger, IIdentityService identityService, IIdCreatorService idCreator, IMapper mapper, DataContext dataContext)
|
||||
{
|
||||
_logger = logger;
|
||||
_identityService = identityService;
|
||||
_idCreator = idCreator;
|
||||
_mapper = mapper;
|
||||
_dbContext = dataContext;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 上传图片
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost("image")]
|
||||
public IActionResult Images()
|
||||
{
|
||||
return Ok("Upload Service");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 上传文件
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost("file")]
|
||||
public IActionResult File()
|
||||
{
|
||||
return Ok("Upload Service");
|
||||
}
|
||||
}
|
||||
}
|
||||
33
Atomx.Storage/Controllers/WeatherForecastController.cs
Normal file
33
Atomx.Storage/Controllers/WeatherForecastController.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Atomx.Storage.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class WeatherForecastController : ControllerBase
|
||||
{
|
||||
private static readonly string[] Summaries = new[]
|
||||
{
|
||||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
|
||||
};
|
||||
|
||||
private readonly ILogger<WeatherForecastController> _logger;
|
||||
|
||||
public WeatherForecastController(ILogger<WeatherForecastController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
[HttpGet(Name = "GetWeatherForecast")]
|
||||
public IEnumerable<WeatherForecast> Get()
|
||||
{
|
||||
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
|
||||
{
|
||||
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
|
||||
TemperatureC = Random.Shared.Next(-20, 55),
|
||||
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
|
||||
})
|
||||
.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
21
Atomx.Storage/Program.cs
Normal file
21
Atomx.Storage/Program.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
|
||||
builder.Services.AddControllers();
|
||||
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
|
||||
builder.Services.AddOpenApi();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.MapOpenApi();
|
||||
}
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
||||
14
Atomx.Storage/Properties/launchSettings.json
Normal file
14
Atomx.Storage/Properties/launchSettings.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": false,
|
||||
"applicationUrl": "http://localhost:5050",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
84
Atomx.Storage/Services/IIdentityService.cs
Normal file
84
Atomx.Storage/Services/IIdentityService.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
using Atomx.Utils.Extension;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace Atomx.Storage.Services
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public interface IIdentityService
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取用户ID
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
long GetUserId();
|
||||
|
||||
/// <summary>
|
||||
/// 获取客户端IP
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
string GetClientIp();
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户设置的时区
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
int GetTimeZone();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class IdentityService : IIdentityService
|
||||
{
|
||||
IHttpContextAccessor _httpContextAccessor;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="httpContextAccessor"></param>
|
||||
public IdentityService(IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户ID
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public long GetUserId()
|
||||
{
|
||||
var id = _httpContextAccessor.HttpContext?.User?.Claims?.SingleOrDefault(p => p.Type == ClaimTypes.Sid)?.Value ?? "0";
|
||||
return id.ToLong();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取客户端IP
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string GetClientIp()
|
||||
{
|
||||
var ipAddress = _httpContextAccessor.HttpContext?.Request.Headers["X-Forwarded-For"].FirstOrDefault();
|
||||
if (ipAddress == null)
|
||||
{
|
||||
ipAddress = _httpContextAccessor.HttpContext?.Request.Headers["X-Real-IP"].FirstOrDefault();
|
||||
if (ipAddress == null)
|
||||
{
|
||||
ipAddress = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress?.ToString() ?? "";
|
||||
}
|
||||
}
|
||||
return ipAddress;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户设置的时区
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int GetTimeZone()
|
||||
{
|
||||
var timeZone = _httpContextAccessor.HttpContext?.User?.Claims?.SingleOrDefault(p => p.Type == "TimeZone")?.Value ?? "0";
|
||||
return timeZone.ToInt();
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Atomx.Storage/WeatherForecast.cs
Normal file
13
Atomx.Storage/WeatherForecast.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace Atomx.Storage
|
||||
{
|
||||
public class WeatherForecast
|
||||
{
|
||||
public DateOnly Date { get; set; }
|
||||
|
||||
public int TemperatureC { get; set; }
|
||||
|
||||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
|
||||
|
||||
public string? Summary { get; set; }
|
||||
}
|
||||
}
|
||||
8
Atomx.Storage/appsettings.Development.json
Normal file
8
Atomx.Storage/appsettings.Development.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
||||
9
Atomx.Storage/appsettings.json
Normal file
9
Atomx.Storage/appsettings.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
Reference in New Issue
Block a user