-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
108 lines (94 loc) · 3.65 KB
/
Program.cs
File metadata and controls
108 lines (94 loc) · 3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using MudBlazor.Services;
using HexoArticleEditor.Components;
using HexoArticleEditor;
using Microsoft.AspNetCore.Components.Authorization;
using HexoArticleEditor.Auth;
using System.Net;
using Microsoft.Extensions.FileProviders;
AppConfig.Load();
if (string.IsNullOrEmpty(AppConfig.HexoBasePath))
{
Console.Write("似乎是第一次启动软件呢!需要指定一下 Hexo 的目录:");
string path = Console.ReadLine();
if (string.IsNullOrEmpty(path))
{
Console.WriteLine("输入的路径无效,找到目录了再来吧");
return;
}
if (Directory.Exists(path))
{
if(!File.Exists(Path.Combine(path, "_config.yml")))
{
Console.WriteLine("未在此目录下找到 _config.yml. 可能提供的并不是 Hexo 根目录");
return;
}
}
else
{
Console.WriteLine("未找到此目录,找到目录了再来吧");
return;
}
Console.WriteLine($"文章路径:{Path.Combine(path, "source\\_posts")}");
Console.WriteLine($"存储图片路径:{Path.Combine(path, "public\\images\\post")}");
Console.WriteLine("以上路径是否正确?[y/n]");
if (Console.ReadLine().Trim().ToLower() == "y")
{
ConfigHelper.SetConfig("HexoBasePath", path);
ConfigHelper.SetConfig("HexoArticlePath", Path.Combine(path, "source\\_posts"));
ConfigHelper.SetConfig("HexoImagePath", Path.Combine(path, "public\\images\\post"));
AppConfig.HexoBasePath = path;
AppConfig.HexoArticlePath = Path.Combine(path, "source\\_posts");
AppConfig.HexoImagePath = Path.Combine(path, "public\\images\\post");
}
else
{
Console.Write("Hexo 的文章路径:");
path = Console.ReadLine();
ConfigHelper.SetConfig("HexoArticlePath", path);
AppConfig.HexoArticlePath = path;
Console.Write("Hexo 的存储图片路径:");
path = Console.ReadLine();
ConfigHelper.SetConfig("HexoImagePath", path);
AppConfig.HexoImagePath = path;
}
Console.Write("保证 Shell 安全我们需要进行简单的鉴权,请输入一个复杂一些的密码:");
string password = Console.ReadLine();
ConfigHelper.SetConfig("Password", password);
AppConfig.Password = password;
}
var builder = WebApplication.CreateBuilder(args);
builder.WebHost.ConfigureKestrel(serverOptions =>
{
serverOptions.Listen(IPAddress.Parse(AppConfig.ListenIP), AppConfig.ListenPort);
});
// Add MudBlazor services
builder.Services.AddMudServices();
builder.Services.AddSignalR(e => { e.MaximumReceiveMessageSize = AppConfig.MaxFileSize; });
// Add services to the container.
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
builder.Services.AddScoped<SessionStorageProvider>();
builder.Services.AddScoped<AuthenticationStateProvider>(p => p.GetRequiredService<SessionStorageProvider>());
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error", createScopeForErrors: true);
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseStaticFiles();
// Serve Hexo images directly from the Hexo public/images directory
var hexoImagesPath = Path.Combine(AppConfig.HexoBasePath, "public", "images");
if (Directory.Exists(hexoImagesPath))
{
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(hexoImagesPath),
RequestPath = "/images"
});
}
app.UseAntiforgery();
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();
app.Run();