UI 体验与启动优化 · 主题色 · Gitea CI/夜间预发布 · 后端安全加固
- 启动:健康检查与设置并行请求,页面按需构建并 Offstage 保活,封面按展示尺寸解码 - UI:模型卡片增加悬停动效、封面渐变遮罩、版本/作者/标签胶囊,空简介占位 - 主题:设置页新增主色调选择(预设 + 自定义 #RRGGBB),前后端持久化并实时生效 - CI:新增 PR 审核流水线(后端编译/自检、Flutter 分析测试、漏洞与密钥扫描、汇总门禁) - CI:新增每晚 21:00(UTC 13:00)预发布流水线,prerelease 且不设为 Latest,先删旧再建新 - 安全:后端新增安全响应头、Host/Origin 校验、写入限流、请求体上限、ID 与设置白名单、错误信息脱敏 - 源:暂时只启用 Xhmcl;GitCode 实现保留但不再调用,旧配置自动迁移
This commit is contained in:
1 parent
3480cbaa5f
commit
ae73eca2c4
15 files changed
+1007
-153
No files matched your search
@@ -15,6 +15,9 @@ public sealed class Contributor
|
||||
/// <summary>提交次数(API 里的 contributions)。</summary>
|
||||
public int Contributions { get; set; }
|
||||
|
||||
/// <summary>接口直接返回的头像地址(Gitea 的 avatar_url);为空时按邮箱哈希生成。</summary>
|
||||
public string? Avatar { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 登录名 -> 展示名。GitCode 的 contributors 接口只返回账号登录名,
|
||||
/// 不返回真实姓名,这里做一层映射,让关于页显示作者想展示的名字。
|
||||
@@ -24,14 +27,16 @@ public sealed class Contributor
|
||||
["Morris_1"] = "Morris"
|
||||
};
|
||||
|
||||
/// <summary>头像地址:GitCode 用邮箱哈希拼头像,取不到时返回 null。</summary>
|
||||
/// <summary>头像地址:优先用接口返回的头像,否则按邮箱哈希拼 GitCode 头像。</summary>
|
||||
public string? AvatarUrl =>
|
||||
string.IsNullOrWhiteSpace(Email)
|
||||
? null
|
||||
: $"https://cdn-img.gitcode.com/avatar/{Convert.ToHexString(
|
||||
System.Security.Cryptography.MD5.HashData(
|
||||
System.Text.Encoding.UTF8.GetBytes(Email!.Trim().ToLowerInvariant())))
|
||||
.ToLowerInvariant()}";
|
||||
!string.IsNullOrWhiteSpace(Avatar)
|
||||
? Avatar
|
||||
: string.IsNullOrWhiteSpace(Email)
|
||||
? null
|
||||
: $"https://cdn-img.gitcode.com/avatar/{Convert.ToHexString(
|
||||
System.Security.Cryptography.MD5.HashData(
|
||||
System.Text.Encoding.UTF8.GetBytes(Email!.Trim().ToLowerInvariant())))
|
||||
.ToLowerInvariant()}";
|
||||
|
||||
public string DisplayName
|
||||
{
|
||||
@@ -59,21 +64,26 @@ public static class ContributorsService
|
||||
return c;
|
||||
}
|
||||
|
||||
/// <summary>默认仓库的 contributors 接口地址。</summary>
|
||||
/// <summary>按仓库地址推导贡献者接口:Xhmcl(Gitea) 与 GitCode 结构不同。</summary>
|
||||
public static string BuildUrl(string repository)
|
||||
{
|
||||
var raw = string.IsNullOrWhiteSpace(repository)
|
||||
? SourcePreset.GitCode.HomeUrl : repository.Trim();
|
||||
? SourcePreset.Xhmcl.HomeUrl : repository.Trim();
|
||||
if (!Uri.TryCreate(raw, UriKind.Absolute, out var uri))
|
||||
return "https://api.gitcode.com/api/v5/repos/Morris_1/GC/contributors";
|
||||
return "https://git.xhmcl.com/api/v1/repos/Morris/GC/collaborators";
|
||||
|
||||
var parts = uri.AbsolutePath.Trim('/').Split('/', StringSplitOptions.RemoveEmptyEntries);
|
||||
if (parts.Length < 2)
|
||||
return "https://api.gitcode.com/api/v5/repos/Morris_1/GC/contributors";
|
||||
return "https://git.xhmcl.com/api/v1/repos/Morris/GC/collaborators";
|
||||
|
||||
var repo = parts[1].EndsWith(".git", StringComparison.OrdinalIgnoreCase)
|
||||
? parts[1][..^4] : parts[1];
|
||||
return $"https://api.gitcode.com/api/v5/repos/{parts[0]}/{repo}/contributors";
|
||||
|
||||
// GitCode 代码保留,仅在仓库确实指向 GitCode 时才走它。
|
||||
if (uri.Host.Contains("gitcode.com", StringComparison.OrdinalIgnoreCase))
|
||||
return $"https://api.gitcode.com/api/v5/repos/{parts[0]}/{repo}/contributors";
|
||||
|
||||
return $"https://{uri.Host}/api/v1/repos/{parts[0]}/{repo}/collaborators";
|
||||
}
|
||||
|
||||
public static async Task<List<Contributor>> FetchAsync(string repository, CancellationToken ct = default)
|
||||
@@ -88,12 +98,33 @@ public static class ContributorsService
|
||||
var trimmed = text.TrimStart();
|
||||
if (trimmed.Length == 0 || trimmed[0] != '[') return new List<Contributor>();
|
||||
|
||||
var list = JsonSerializer.Deserialize<List<Contributor>>(text, new JsonSerializerOptions
|
||||
using var doc = JsonDocument.Parse(text);
|
||||
var list = new List<Contributor>();
|
||||
foreach (var item in doc.RootElement.EnumerateArray())
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
}) ?? new List<Contributor>();
|
||||
// Gitea: login / avatar_url;GitCode: name / email / contributions。
|
||||
if (item.TryGetProperty("login", out var login))
|
||||
{
|
||||
list.Add(new Contributor
|
||||
{
|
||||
Name = login.GetString() ?? "",
|
||||
Avatar = item.TryGetProperty("avatar_url", out var avatar)
|
||||
? avatar.GetString() : null
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
list.Add(new Contributor
|
||||
{
|
||||
Name = item.TryGetProperty("name", out var name)
|
||||
? name.GetString() ?? "" : "",
|
||||
Email = item.TryGetProperty("email", out var email)
|
||||
? email.GetString() : null,
|
||||
Contributions = item.TryGetProperty("contributions", out var c) &&
|
||||
c.TryGetInt32(out var count) ? count : 0
|
||||
});
|
||||
}
|
||||
|
||||
// 按提交数从多到少,贡献最多的排最前
|
||||
list.Sort((a, b) => b.Contributions.CompareTo(a.Contributions));
|
||||
return list;
|
||||
}
|
||||
|
||||
@@ -18,10 +18,11 @@ public sealed class SettingsService
|
||||
public void Load()
|
||||
{
|
||||
Current = Json.Read<AppSettings>(_paths.SettingsFile) ?? new AppSettings();
|
||||
if (Current.UpdateRepository.Contains("gitcode.com/2509_92447106/GC", StringComparison.OrdinalIgnoreCase))
|
||||
|
||||
// 暂时停用 GitCode:旧配置里的 GitCode 仓库地址统一迁到 Xhmcl。
|
||||
if (Current.UpdateRepository.Contains("gitcode.com", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
Current.UpdateRepository = Current.UpdateRepository.Replace(
|
||||
"2509_92447106", "Morris_1", StringComparison.OrdinalIgnoreCase);
|
||||
Current.UpdateRepository = SourcePreset.Xhmcl.HomeUrl;
|
||||
Save();
|
||||
}
|
||||
SeedDefaultSource();
|
||||
@@ -29,12 +30,11 @@ public sealed class SettingsService
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 只允许两个内置源:Xhmcl 与 GitCode(同一份仓库的两个镜像)。
|
||||
/// 不再支持用户自定义源 —— 每次加载都把 Sources 规整成这两条,
|
||||
/// 老配置里的自定义源会被清理掉。
|
||||
/// 当前只启用 Xhmcl 一个内置源。GitCode 的定义与下载实现保留在代码里,
|
||||
/// 但不再参与测速 / 下载 / 更新;恢复时把 GitCode 加回 <see cref="SourcePreset.All"/> 即可。
|
||||
/// </summary>
|
||||
public const string DefaultSourceId = "gitcode";
|
||||
public const string DefaultSourceUrl = "https://gitcode.com/Morris_1/GC";
|
||||
public const string DefaultSourceId = "xhmcl";
|
||||
public const string DefaultSourceUrl = "https://git.xhmcl.com/Morris/GC";
|
||||
|
||||
private void SeedDefaultSource()
|
||||
{
|
||||
|
||||
@@ -5,10 +5,11 @@ using System.Linq;
|
||||
namespace GC.Services;
|
||||
|
||||
/// <summary>
|
||||
/// 内置下载源。只允许这两个,不再支持用户自定义源。
|
||||
/// 内置下载源。
|
||||
///
|
||||
/// 两个源的内容是同一份仓库(同一个 version.json、同一批模型),
|
||||
/// 区别只是**托管在哪台服务器**上;启动时探测两者延迟,取快的那个下载。
|
||||
/// 目前只启用 Xhmcl;GitCode 的 preset 与下载实现仍保留在代码中,
|
||||
/// 但不参与测速 / 下载 / 更新。两个源本来指向同一份仓库内容,
|
||||
/// 区别只是托管服务器;恢复双源时把 GitCode 加回 <see cref="All"/>。
|
||||
/// </summary>
|
||||
public sealed class SourcePreset
|
||||
{
|
||||
@@ -63,17 +64,23 @@ public sealed class SourcePreset
|
||||
Branch = "main"
|
||||
};
|
||||
|
||||
public static readonly SourcePreset[] All = { Xhmcl, GitCode };
|
||||
/// <summary>
|
||||
/// 当前启用的源:暂时只保留 Xhmcl。GitCode 的定义与实现仍保留在代码里,
|
||||
/// 但不参与测速、下载与更新(需要恢复时把 GitCode 加回这个数组即可)。
|
||||
/// </summary>
|
||||
public static readonly SourcePreset[] All = { Xhmcl };
|
||||
|
||||
public static SourcePreset? Find(string? id) =>
|
||||
All.FirstOrDefault(p => string.Equals(p.Id, id, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
/// <summary>把任意仓库地址映射到这两个内置源之一(用于兼容旧配置)。</summary>
|
||||
/// <summary>把任意仓库地址映射到启用的内置源(用于兼容旧配置)。</summary>
|
||||
public static SourcePreset Detect(string? url)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(url)) return GitCode;
|
||||
var u = url!.ToLowerInvariant();
|
||||
if (u.Contains("xhmcl.com")) return Xhmcl;
|
||||
return GitCode;
|
||||
if (!string.IsNullOrWhiteSpace(url) &&
|
||||
url!.Contains("xhmcl.com", StringComparison.OrdinalIgnoreCase))
|
||||
return Xhmcl;
|
||||
|
||||
// 旧配置里的 GitCode 地址不再作为下载源,统一落到 Xhmcl。
|
||||
return Xhmcl;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user