- 启动:健康检查与设置并行请求,页面按需构建并 Offstage 保活,封面按展示尺寸解码 - UI:模型卡片增加悬停动效、封面渐变遮罩、版本/作者/标签胶囊,空简介占位 - 主题:设置页新增主色调选择(预设 + 自定义 #RRGGBB),前后端持久化并实时生效 - CI:新增 PR 审核流水线(后端编译/自检、Flutter 分析测试、漏洞与密钥扫描、汇总门禁) - CI:新增每晚 21:00(UTC 13:00)预发布流水线,prerelease 且不设为 Latest,先删旧再建新 - 安全:后端新增安全响应头、Host/Origin 校验、写入限流、请求体上限、ID 与设置白名单、错误信息脱敏 - 源:暂时只启用 Xhmcl;GitCode 实现保留但不再调用,旧配置自动迁移
87 lines
3.2 KiB
C#
87 lines
3.2 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
|
||
namespace GC.Services;
|
||
|
||
/// <summary>
|
||
/// 内置下载源。
|
||
///
|
||
/// 目前只启用 Xhmcl;GitCode 的 preset 与下载实现仍保留在代码中,
|
||
/// 但不参与测速 / 下载 / 更新。两个源本来指向同一份仓库内容,
|
||
/// 区别只是托管服务器;恢复双源时把 GitCode 加回 <see cref="All"/>。
|
||
/// </summary>
|
||
public sealed class SourcePreset
|
||
{
|
||
public string Id { get; init; } = "";
|
||
public string Name { get; init; } = "";
|
||
/// <summary>仓库主页(用于展示与打开)。</summary>
|
||
public string HomeUrl { get; init; } = "";
|
||
/// <summary>API 根地址(Gitea: /api/v1,GitCode: /api/v5)。</summary>
|
||
public string ApiBase { get; init; } = "";
|
||
/// <summary>原始文件下载前缀(用于拼 raw 地址)。</summary>
|
||
public string RawBase { get; init; } = "";
|
||
/// <summary>后端类型:gitea / gitcode。</summary>
|
||
public string Kind { get; init; } = "";
|
||
public string Owner { get; init; } = "";
|
||
public string Repo { get; init; } = "";
|
||
public string Branch { get; init; } = "main";
|
||
/// <summary>raw 地址风格:gitea 用 raw/branch/{b},gitcode 用 raw/{b}。</summary>
|
||
public string RawStyle { get; init; } = "branch";
|
||
|
||
public string Repository => HomeUrl;
|
||
|
||
/// <summary>拼 raw 文件下载地址(两个平台的 URL 结构不同)。</summary>
|
||
public string RawUrl(string path) => RawStyle == "plain"
|
||
? $"{RawBase}/{Owner}/{Repo}/raw/{Branch}/{path.TrimStart('/')}"
|
||
: $"{RawBase}/{Owner}/{Repo}/raw/branch/{Branch}/{path.TrimStart('/')}";
|
||
|
||
public static readonly SourcePreset Xhmcl = new()
|
||
{
|
||
Id = "xhmcl",
|
||
Name = "Xhmcl",
|
||
HomeUrl = "https://git.xhmcl.com/Morris/GC",
|
||
ApiBase = "https://git.xhmcl.com/api/v1",
|
||
RawBase = "https://git.xhmcl.com",
|
||
Kind = "gitea",
|
||
RawStyle = "branch",
|
||
Owner = "Morris",
|
||
Repo = "GC",
|
||
Branch = "main"
|
||
};
|
||
|
||
public static readonly SourcePreset GitCode = new()
|
||
{
|
||
Id = "gitcode",
|
||
Name = "GitCode",
|
||
HomeUrl = "https://gitcode.com/Morris_1/GC",
|
||
ApiBase = "https://api.gitcode.com/api/v5",
|
||
RawBase = "https://gitcode.com",
|
||
Kind = "gitcode",
|
||
RawStyle = "plain",
|
||
Owner = "Morris_1",
|
||
Repo = "GC",
|
||
Branch = "main"
|
||
};
|
||
|
||
/// <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>
|
||
public static SourcePreset Detect(string? url)
|
||
{
|
||
if (!string.IsNullOrWhiteSpace(url) &&
|
||
url!.Contains("xhmcl.com", StringComparison.OrdinalIgnoreCase))
|
||
return Xhmcl;
|
||
|
||
// 旧配置里的 GitCode 地址不再作为下载源,统一落到 Xhmcl。
|
||
return Xhmcl;
|
||
}
|
||
}
|