1
This commit is contained in:
149
Gatedge.ScanCode/Program.cs
Normal file
149
Gatedge.ScanCode/Program.cs
Normal file
@@ -0,0 +1,149 @@
|
||||
|
||||
using Gatedge.ScanCode.Common;
|
||||
using Gatedge.ScanCode.Extension;
|
||||
using Gatedge.ScanCode.Middleware;
|
||||
using Gatedge.ScanCode.Options;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.AspNetCore.StaticFiles;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.FileProviders;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Text.Unicode;
|
||||
|
||||
namespace Gatedge.ScanCode
|
||||
{
|
||||
/// <summary>
|
||||
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
/// </summary>
|
||||
public class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// main<69><6E><EFBFBD><EFBFBD>
|
||||
/// </summary>
|
||||
/// <param name="args"></param>
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
// <20><><EFBFBD><EFBFBD>K3CloudApi<70><69>
|
||||
builder.Services.AddConfigureK3CloudApi(builder.Configuration);
|
||||
// <20><><EFBFBD><EFBFBD>Jwt
|
||||
builder.Services.ConfigureJwtContext(builder.Configuration);
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
||||
builder.Services.AddConfigureK3FileService(builder.Configuration);
|
||||
// <20><><EFBFBD><EFBFBD>json
|
||||
//builder.Services.ConfigureServices();
|
||||
// <20><><EFBFBD><EFBFBD>Services
|
||||
builder.Services.ConfigureCore();
|
||||
// Add services to the container.
|
||||
builder.Services.AddControllers();
|
||||
|
||||
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen(option =>
|
||||
{
|
||||
option.AddSecurityRequirement(new OpenApiSecurityRequirement()
|
||||
{
|
||||
|
||||
{
|
||||
new OpenApiSecurityScheme
|
||||
{
|
||||
Reference = new OpenApiReference
|
||||
{
|
||||
Id = "Bearer",
|
||||
Type = ReferenceType.SecurityScheme
|
||||
}
|
||||
},
|
||||
new List<string>()
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>Bearer<65><72>֤
|
||||
option.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
|
||||
{
|
||||
Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"",
|
||||
Name = "Authorization",
|
||||
In = ParameterLocation.Header,
|
||||
Type = SecuritySchemeType.ApiKey,
|
||||
Scheme = "Bearer"
|
||||
});
|
||||
|
||||
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>swaggerע<72><D7A2>
|
||||
var basePath = AppContext.BaseDirectory;
|
||||
var xmlPath = Path.Combine(basePath, "Gatedge.ScanCode.xml");
|
||||
option.IncludeXmlComments(xmlPath);
|
||||
|
||||
});
|
||||
|
||||
builder.Logging.AddProvider(new FileLoggerProvider(
|
||||
filePath: "../logs/app.log", // <20><>־<EFBFBD>ļ<EFBFBD>·<EFBFBD><C2B7>
|
||||
maxFileSize: 10 * 1024 * 1024, // 10MB
|
||||
maxRetainedFiles: 1000 // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1000<30><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
||||
));
|
||||
|
||||
builder.Services.AddControllers().AddJsonOptions(options =>
|
||||
{
|
||||
options.JsonSerializerOptions.PropertyNamingPolicy = null;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˴<EFBFBD><CBB4><EFBFBD>ǰ<EFBFBD><C7B0>ȫ<EFBFBD><C8AB>д
|
||||
options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˷<EFBFBD><CBB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD>
|
||||
});
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
|
||||
|
||||
app.UseStaticFiles();
|
||||
|
||||
var filePath = Path.Combine(builder.Environment.ContentRootPath, "K3CloudFile");
|
||||
if (!Directory.Exists(filePath))
|
||||
{
|
||||
Directory.CreateDirectory(filePath);
|
||||
}
|
||||
var fileProvider = new PhysicalFileProvider(filePath);
|
||||
var provider = new FileExtensionContentTypeProvider();
|
||||
provider.Mappings[".apk"] = "application/vnd.android.package-archive";
|
||||
provider.Mappings[".wgt"] = "application/widget";
|
||||
var requestPath = "/Download";
|
||||
|
||||
// Enable displaying browser links.
|
||||
app.UseStaticFiles(new StaticFileOptions
|
||||
{
|
||||
FileProvider = fileProvider,
|
||||
RequestPath = requestPath,
|
||||
ContentTypeProvider = provider
|
||||
});
|
||||
|
||||
app.UseDirectoryBrowser(new DirectoryBrowserOptions
|
||||
{
|
||||
FileProvider = fileProvider,
|
||||
RequestPath = requestPath,
|
||||
});
|
||||
|
||||
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
}
|
||||
/*
|
||||
<20>м<EFBFBD><D0BC><EFBFBD>ע<EFBFBD><D7A2>˳<EFBFBD><CBB3>Ӱ<EFBFBD><D3B0>ִ<EFBFBD><D6B4>˳<EFBFBD><CBB3><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>˳<EFBFBD><CBB3> = ִ<><D6B4>˳<EFBFBD><CBB3><EFBFBD><EFBFBD><EFBFBD>쳣<EFBFBD><ECB3A3><EFBFBD><EFBFBD><EFBFBD>м<EFBFBD><D0BC><EFBFBD>Ӧ<EFBFBD>÷<EFBFBD><C3B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*/
|
||||
// 1.<2E><><EFBFBD><EFBFBD>Ȩ<EFBFBD><C8A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤
|
||||
app.UseAuthentication(); //<2F><>֤<EFBFBD>м<EFBFBD><D0BC><EFBFBD>
|
||||
app.UseAuthorization(); //<2F><>Ȩ<EFBFBD>м<EFBFBD><D0BC><EFBFBD>
|
||||
// <20><>־<EFBFBD>м<EFBFBD><D0BC><EFBFBD>
|
||||
app.UseMiddleware<ResponseLoggingMiddleware>();
|
||||
// ȫ<><C8AB><EFBFBD>쳣<EFBFBD>м<EFBFBD><D0BC><EFBFBD>
|
||||
app.UseMiddleware<GlobalExceptionMiddleware>();
|
||||
//app.UseHttpsRedirection(); // ת<><D7AA>HTTP<54><50>HTTPS
|
||||
app.MapControllers();
|
||||
app.Run();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user