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;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user