Initial commit
This commit is contained in:
+33
@@ -0,0 +1,33 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using OssTJiaUploaderService;
|
||||
using OssZipUploaderService;
|
||||
|
||||
IHost host = Host.CreateDefaultBuilder(args)
|
||||
.UseWindowsService() // 将宿主绑定到 Windows 服务
|
||||
.ConfigureAppConfiguration((ctx, cfg) =>
|
||||
{
|
||||
cfg.AddJsonFile("appsettings.Development.json", optional: true);
|
||||
})
|
||||
.ConfigureServices((ctx, services) =>
|
||||
{
|
||||
services.AddOptions<OssOptions>()
|
||||
.Bind(ctx.Configuration.GetSection("Oss"))
|
||||
.Validate(o => !string.IsNullOrWhiteSpace(o.Endpoint) && !string.IsNullOrWhiteSpace(o.Bucket),
|
||||
"请配置 Oss:Endpoint 和 Oss:Bucket。")
|
||||
.Validate(o => !string.IsNullOrWhiteSpace(o.AccessKeyId) && !string.IsNullOrWhiteSpace(o.AccessKeySecret),
|
||||
"请先使用 encrypt-key.ps1 -UpdateConfig 填写完整的新 RAM 用户 AccessKey。")
|
||||
.Validate(o => string.IsNullOrWhiteSpace(o.RoleArn) ||
|
||||
(!string.IsNullOrWhiteSpace(o.StsRegionId) && !string.IsNullOrWhiteSpace(o.StsEndpoint) &&
|
||||
System.Text.RegularExpressions.Regex.IsMatch(o.RoleSessionName ?? "", @"^[a-zA-Z0-9.@_-]{2,64}$") &&
|
||||
o.StsDurationSeconds >= 900 && o.StsDurationSeconds <= 43200),
|
||||
"STS 配置无效:请检查接入点、地域、会话名称,以及凭据有效期(900~43200 秒,且不能超过角色的最大会话时长)。");
|
||||
services.AddSingleton<OssClientFactory>();
|
||||
// 注册 DingTalkNotifier 所需的服务
|
||||
services.AddHttpClient<DingTalkNotifier>();
|
||||
services.AddHostedService<Worker>();
|
||||
})
|
||||
.Build();
|
||||
|
||||
await host.RunAsync();
|
||||
|
||||
Reference in New Issue
Block a user