Add editable portal page content
This commit is contained in:
+61
-1
@@ -53,6 +53,11 @@ public sealed class NginxManager
|
||||
|
||||
public int PortalListenPort => _config.PortalListenPort;
|
||||
|
||||
public PortalContentSettings PortalContent => new(
|
||||
_config.PortalSiteName,
|
||||
_config.PortalHeadline,
|
||||
_config.PortalIntroduction);
|
||||
|
||||
public string NginxExePath
|
||||
{
|
||||
get => _config.NginxExePath;
|
||||
@@ -83,6 +88,14 @@ public sealed class NginxManager
|
||||
SaveConfig();
|
||||
}
|
||||
|
||||
public void UpdatePortalContent(string siteName, string headline, string introduction)
|
||||
{
|
||||
_config.PortalSiteName = NormalizeLimitedText(siteName, "入口页名称", 80);
|
||||
_config.PortalHeadline = NormalizeLimitedText(headline, "主页标题", 120);
|
||||
_config.PortalIntroduction = NormalizeLimitedText(introduction, "主页简介", 500);
|
||||
SaveConfig();
|
||||
}
|
||||
|
||||
public void AddOrUpdateRoute(
|
||||
string domain,
|
||||
string upstream,
|
||||
@@ -218,7 +231,7 @@ public sealed class NginxManager
|
||||
public void SaveConfig()
|
||||
{
|
||||
File.WriteAllText(_configPath, JsonSerializer.Serialize(_config, JsonOptions), Encoding.UTF8);
|
||||
WebPortal.RenderTo(_dataDirectory, _config.Routes);
|
||||
WebPortal.RenderTo(_dataDirectory, PortalContent, _config.Routes);
|
||||
}
|
||||
|
||||
public string CreateBackup(string destinationPath)
|
||||
@@ -367,6 +380,7 @@ public sealed class NginxManager
|
||||
}
|
||||
|
||||
NormalizeDataPaths(config);
|
||||
NormalizePortalContent(config);
|
||||
NormalizeRouteMetadata(config.Routes);
|
||||
|
||||
return config;
|
||||
@@ -486,6 +500,10 @@ public sealed class NginxManager
|
||||
config.ErrorLogPath = NormalizePathSetting(config.ErrorLogPath, defaults.ErrorLogPath);
|
||||
config.PortalDomain = NormalizeOptionalDomain(config.PortalDomain ?? string.Empty);
|
||||
config.PortalListenPort = NormalizePort(config.PortalListenPort, "入口页监听端口");
|
||||
NormalizePortalContent(config);
|
||||
config.PortalSiteName = NormalizeLimitedText(config.PortalSiteName, "入口页名称", 80);
|
||||
config.PortalHeadline = NormalizeLimitedText(config.PortalHeadline, "主页标题", 120);
|
||||
config.PortalIntroduction = NormalizeLimitedText(config.PortalIntroduction, "主页简介", 500);
|
||||
config.Routes ??= [];
|
||||
NormalizeDataPaths(config);
|
||||
NormalizeRouteMetadata(config.Routes);
|
||||
@@ -624,6 +642,9 @@ public sealed class NginxManager
|
||||
ErrorLogPath = Path.Combine("data", "logs", "error.log"),
|
||||
PortalDomain = string.Empty,
|
||||
PortalListenPort = 80,
|
||||
PortalSiteName = PortalContentSettings.DefaultSiteName,
|
||||
PortalHeadline = PortalContentSettings.DefaultHeadline,
|
||||
PortalIntroduction = PortalContentSettings.DefaultIntroduction,
|
||||
Routes = []
|
||||
};
|
||||
|
||||
@@ -682,6 +703,19 @@ public sealed class NginxManager
|
||||
}
|
||||
}
|
||||
|
||||
private static void NormalizePortalContent(NginxManagerConfig config)
|
||||
{
|
||||
config.PortalSiteName = string.IsNullOrWhiteSpace(config.PortalSiteName)
|
||||
? PortalContentSettings.DefaultSiteName
|
||||
: config.PortalSiteName.Trim();
|
||||
config.PortalHeadline = string.IsNullOrWhiteSpace(config.PortalHeadline)
|
||||
? PortalContentSettings.DefaultHeadline
|
||||
: config.PortalHeadline.Trim();
|
||||
config.PortalIntroduction = string.IsNullOrWhiteSpace(config.PortalIntroduction)
|
||||
? PortalContentSettings.DefaultIntroduction
|
||||
: config.PortalIntroduction.Trim();
|
||||
}
|
||||
|
||||
private static bool IsLegacyPath(string path, string expectedPath) =>
|
||||
string.Equals(
|
||||
path.Replace('/', '\\'),
|
||||
@@ -782,6 +816,17 @@ public sealed class NginxManager
|
||||
|
||||
return value.Trim();
|
||||
}
|
||||
|
||||
private static string NormalizeLimitedText(string value, string fieldName, int maximumLength)
|
||||
{
|
||||
var normalized = NormalizeRequiredText(value, fieldName);
|
||||
if (normalized.Length > maximumLength)
|
||||
{
|
||||
throw new ArgumentException($"{fieldName}不能超过 {maximumLength} 个字符。");
|
||||
}
|
||||
|
||||
return normalized;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed record BackupImportResult(
|
||||
@@ -800,9 +845,24 @@ public sealed class NginxManagerConfig
|
||||
public string ErrorLogPath { get; set; } = Path.Combine("logs", "error.log");
|
||||
public string PortalDomain { get; set; } = string.Empty;
|
||||
public int PortalListenPort { get; set; } = 80;
|
||||
public string PortalSiteName { get; set; } = PortalContentSettings.DefaultSiteName;
|
||||
public string PortalHeadline { get; set; } = PortalContentSettings.DefaultHeadline;
|
||||
public string PortalIntroduction { get; set; } = PortalContentSettings.DefaultIntroduction;
|
||||
public List<RouteEntry> Routes { get; set; } = [];
|
||||
}
|
||||
|
||||
public sealed record PortalContentSettings(string SiteName, string Headline, string Introduction)
|
||||
{
|
||||
public const string DefaultSiteName = "服务导航";
|
||||
public const string DefaultHeadline = "欢迎访问统一服务入口";
|
||||
public const string DefaultIntroduction = "请选择下方网站或服务,点击卡片即可开始访问。";
|
||||
|
||||
public static PortalContentSettings Default { get; } = new(
|
||||
DefaultSiteName,
|
||||
DefaultHeadline,
|
||||
DefaultIntroduction);
|
||||
}
|
||||
|
||||
public sealed class RouteEntry
|
||||
{
|
||||
public string Domain { get; set; } = string.Empty;
|
||||
|
||||
Reference in New Issue
Block a user