1.0.11:发布包改为单文件,非本体文件收进 .GC/bin #15
No files matched your search
@@ -22,7 +22,7 @@
|
||||
-->
|
||||
<AvaloniaVersion>11.3.9</AvaloniaVersion>
|
||||
<MvvmVersion>8.2.2</MvvmVersion>
|
||||
<Version>1.0.10</Version>
|
||||
<Version>1.0.11</Version>
|
||||
<Company>Morris</Company>
|
||||
<Product>GC</Product>
|
||||
<NeutralLanguage>zh-Hans</NeutralLanguage>
|
||||
|
||||
+52
-62
@@ -4,20 +4,24 @@ using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using GC.UI.Server;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
|
||||
namespace GC;
|
||||
|
||||
/// <summary>
|
||||
/// 新界面启动壳。
|
||||
///
|
||||
/// 发布包同时带 <c>GC.UI.Server</c>(本地 HTTP 后端 + 模型窗口宿主)和
|
||||
/// <c>GC-UI</c>(Flutter 前端)时,启动器只做三件事:
|
||||
/// 1. 拉起后端并等 <c>/api/health</c> 就绪;
|
||||
/// 发布包带 <c>GC-UI</c>(Flutter 前端)时,启动器只做三件事:
|
||||
/// 1. 在自己的进程里起后端(本地 HTTP API + 模型窗口宿主),等 <c>/api/health</c> 就绪;
|
||||
/// 2. 拉起 Flutter 窗口;
|
||||
/// 3. 界面退出后关掉后端。
|
||||
///
|
||||
/// 两个产物缺任意一个就返回 <c>false</c>,由调用方回退到内置 Avalonia 界面——
|
||||
/// 这样 `dotnet run`、只编了启动器的开发场景、以及交叉编译缺前端产物的包都能正常打开。
|
||||
/// 后端跑在进程内而不是单独一个 exe:两者用的是同一套 .NET 运行时,
|
||||
/// 拆成两个自包含进程等于把 60MB 运行时复制两份,发布包会白白大一倍。
|
||||
///
|
||||
/// 缺 Flutter 前端时返回 <c>false</c>,由调用方回退到内置 Avalonia 界面——
|
||||
/// 这样 `dotnet run`、只编了启动器的开发场景都能正常打开。
|
||||
/// </summary>
|
||||
internal static class FlutterShell
|
||||
{
|
||||
@@ -25,18 +29,18 @@ internal static class FlutterShell
|
||||
private const int Port = Services.GcUiContract.DefaultPort;
|
||||
|
||||
private static readonly HttpClient Http = new() { Timeout = TimeSpan.FromSeconds(1.5) };
|
||||
private static Process? _backend;
|
||||
|
||||
private static WebApplication? _backend;
|
||||
|
||||
public static bool TryRun(string[] args)
|
||||
{
|
||||
var dir = AppContext.BaseDirectory;
|
||||
var backendPath = FindBackend(dir);
|
||||
var uiPath = FindUi(dir);
|
||||
if (backendPath == null || uiPath == null) return false;
|
||||
if (uiPath == null) return false;
|
||||
|
||||
// 用户可能重复启动:已有后端在跑就直接复用,退出时也不要关掉别人的进程。
|
||||
var port = Port;
|
||||
|
||||
// 用户可能重复启动:已有后端在跑就直接复用,退出时也不要关掉别人的进程。
|
||||
if (!IsHealthy(port))
|
||||
{
|
||||
// 端口可能被别的程序占用:17890 起向后试几个,选第一个能起来且健康的。
|
||||
@@ -46,52 +50,40 @@ internal static class FlutterShell
|
||||
|
||||
for (var candidate = start; candidate < start + Services.GcUiContract.PortScanRange; candidate++)
|
||||
{
|
||||
var process = Start(backendPath, $"--port {candidate}", dir);
|
||||
if (process == null) continue;
|
||||
var app = TryStartBackend(args, candidate);
|
||||
if (app == null) continue;
|
||||
|
||||
if (WaitHealthy(candidate, process, TimeSpan.FromSeconds(25)))
|
||||
if (WaitHealthy(candidate, TimeSpan.FromSeconds(25)))
|
||||
{
|
||||
port = candidate;
|
||||
_backend = process;
|
||||
_backend = app;
|
||||
break;
|
||||
}
|
||||
|
||||
Stop(process);
|
||||
StopBackend(app);
|
||||
}
|
||||
|
||||
if (_backend == null) return false;
|
||||
}
|
||||
|
||||
AppDomain.CurrentDomain.ProcessExit += (_, _) => Stop(_backend);
|
||||
AppDomain.CurrentDomain.ProcessExit += (_, _) => StopBackend(_backend);
|
||||
|
||||
var ui = Start(uiPath, null, dir, port);
|
||||
var ui = Start(uiPath, dir, port);
|
||||
if (ui == null)
|
||||
{
|
||||
Stop(_backend);
|
||||
StopBackend(_backend);
|
||||
_backend = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
ui.WaitForExit();
|
||||
Stop(_backend);
|
||||
StopBackend(_backend);
|
||||
_backend = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- 产物定位
|
||||
|
||||
private static string? FindBackend(string dir)
|
||||
{
|
||||
foreach (var name in OperatingSystem.IsWindows()
|
||||
? new[] { "GC.UI.Server.exe", "GC.UI.Server" }
|
||||
: new[] { "GC.UI.Server", "GC.UI.Server.exe" })
|
||||
{
|
||||
var path = Path.Combine(dir, name);
|
||||
if (File.Exists(path)) return path;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Flutter 桌面产物。
|
||||
/// macOS 是 <c>GC-UI.app/Contents/MacOS/GC-UI</c>;Windows 是 <c>GC-UI.exe</c>;
|
||||
@@ -115,54 +107,55 @@ internal static class FlutterShell
|
||||
|
||||
// ---------------------------------------------------------------- 进程管理
|
||||
|
||||
private static Process? Start(string fileName, string? arguments, string workingDirectory, int port = 0)
|
||||
/// <summary>在本进程内启动后端;端口被占用等失败情况返回 null。</summary>
|
||||
private static WebApplication? TryStartBackend(string[] args, int port)
|
||||
{
|
||||
try
|
||||
{
|
||||
var info = new ProcessStartInfo(fileName)
|
||||
{
|
||||
WorkingDirectory = workingDirectory,
|
||||
UseShellExecute = false,
|
||||
CreateNoWindow = true,
|
||||
};
|
||||
if (!string.IsNullOrEmpty(arguments)) info.Arguments = arguments;
|
||||
|
||||
// 把实际端口传给子进程:后端读它监听,前端读它拼 baseUrl。
|
||||
// 这样换端口不需要重新编译前端。
|
||||
if (port > 0)
|
||||
info.Environment[Services.GcUiContract.PortEnvVar] = port.ToString();
|
||||
|
||||
// macOS .app 内的二进制也需要可执行位;发布包由 zip 解开时可能丢失。
|
||||
if (!OperatingSystem.IsWindows())
|
||||
{
|
||||
try { File.SetUnixFileMode(fileName, UnixFileMode.UserRead | UnixFileMode.UserWrite | UnixFileMode.UserExecute); }
|
||||
catch { /* 权限不足时交给系统判断 */ }
|
||||
}
|
||||
|
||||
return Process.Start(info);
|
||||
var app = BackendServer.Start(args, port);
|
||||
app.StartAsync().GetAwaiter().GetResult();
|
||||
return app;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.Error.WriteLine($"[shell] 启动失败 {fileName}: {ex.Message}");
|
||||
Console.Error.WriteLine($"[shell] 后端启动失败(端口 {port}): {ex.Message}");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static void Stop(Process? process)
|
||||
private static void StopBackend(WebApplication? app)
|
||||
{
|
||||
if (process == null) return;
|
||||
if (app == null) return;
|
||||
try
|
||||
{
|
||||
if (!process.HasExited) process.Kill(entireProcessTree: true);
|
||||
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(3));
|
||||
app.StopAsync(cts.Token).GetAwaiter().GetResult();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.Error.WriteLine($"[shell] 关闭后端失败: {ex.Message}");
|
||||
}
|
||||
finally
|
||||
}
|
||||
|
||||
private static Process Start(string fileName, string workingDirectory, int port)
|
||||
{
|
||||
var info = new ProcessStartInfo(fileName)
|
||||
{
|
||||
process.Dispose();
|
||||
WorkingDirectory = workingDirectory,
|
||||
UseShellExecute = false,
|
||||
};
|
||||
|
||||
// 把实际端口传给前端:它读这个环境变量拼 baseUrl,换端口不需要重新编译界面。
|
||||
info.Environment[Services.GcUiContract.PortEnvVar] = port.ToString();
|
||||
|
||||
// macOS .app 内的二进制也需要可执行位;发布包由 zip 解开时可能丢失。
|
||||
if (!OperatingSystem.IsWindows())
|
||||
{
|
||||
try { File.SetUnixFileMode(fileName, UnixFileMode.UserRead | UnixFileMode.UserWrite | UnixFileMode.UserExecute); }
|
||||
catch { /* 权限不足时交给系统判断 */ }
|
||||
}
|
||||
|
||||
return Process.Start(info)!;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- 健康检查
|
||||
@@ -181,14 +174,11 @@ internal static class FlutterShell
|
||||
}
|
||||
}
|
||||
|
||||
private static bool WaitHealthy(int port, Process backend, TimeSpan timeout)
|
||||
private static bool WaitHealthy(int port, TimeSpan timeout)
|
||||
{
|
||||
var deadline = DateTime.UtcNow + timeout;
|
||||
while (DateTime.UtcNow < deadline)
|
||||
{
|
||||
// 后端进程已经退出就没必要再等:端口被占、依赖缺失都会走这里。
|
||||
if (backend.HasExited) return false;
|
||||
|
||||
if (IsHealthy(port)) return true;
|
||||
Thread.Sleep(250);
|
||||
}
|
||||
|
||||
@@ -17,9 +17,15 @@
|
||||
<PackageReference Include="Avalonia.Desktop" Version="$(AvaloniaVersion)" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<!-- 后端以库的方式编进启动器:发布包只需要一个 exe,不用再带一份运行时 -->
|
||||
<FrameworkReference Include="Microsoft.AspNetCore.App" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\GC\src\GC.Core.csproj" />
|
||||
<ProjectReference Include="..\GC-DOWNLOAD\GC-DOWNLOAD.csproj" />
|
||||
<ProjectReference Include="..\GC-UI\backend\GC.UI.Server\GC.UI.Server.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -24,10 +24,14 @@ public static class SavedogLauncher
|
||||
var home = Path.Combine(paths.SafedogRoot, name);
|
||||
if (File.Exists(home)) return home;
|
||||
|
||||
// 包内 payload:非本体文件统一收在 .GC/bin
|
||||
var payload = Path.Combine(install, ".GC", "bin", name);
|
||||
if (File.Exists(payload)) return payload;
|
||||
|
||||
var direct = Path.Combine(install, name);
|
||||
if (File.Exists(direct)) return direct;
|
||||
|
||||
// 新包把守护进程放在 safedog/ 子目录
|
||||
// 1.0.10 及更早的包把守护进程放在 safedog/ 子目录
|
||||
var packaged = Path.Combine(install, "safedog", name);
|
||||
if (File.Exists(packaged)) return packaged;
|
||||
|
||||
|
||||
+56
-2
@@ -498,7 +498,7 @@ internal sealed class Applier
|
||||
/// 1. 安装目录里「新版没有」的条目 → 移到 backup(旧版本残留,如上一版的旧文件名);
|
||||
/// 2. 与新版同名的条目 → 先移到 backup,再把新版放进来(覆盖正在被占用的文件会失败,
|
||||
/// 这种情况直接报错并还原,绝不留下半新半旧的目录);
|
||||
/// 3. `.GC`、更新目录自身、正在运行的 GC-SAVEDOG.exe 一律跳过。
|
||||
/// 3. `.GC` 只合并 `bin/`(非本体文件),其余子目录与更新目录自身一律跳过。
|
||||
///
|
||||
/// 返回 false 时调用方应调用 <see cref="RestoreFromBackup"/> 还原。
|
||||
/// </summary>
|
||||
@@ -518,6 +518,14 @@ internal sealed class Applier
|
||||
foreach (var entry in Directory.GetFileSystemEntries(stage))
|
||||
{
|
||||
var name = Path.GetFileName(entry);
|
||||
if (string.Equals(name, ".GC", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
// .GC 里只有 bin/ 属于程序本体(守护进程这类「非本体」文件),
|
||||
// 其余(config / model / cache / update / logs / safedog)是用户数据,
|
||||
// 整目录替换时必须原地不动。
|
||||
MergeGcBin(entry, installDir, backupDir, replaced);
|
||||
continue;
|
||||
}
|
||||
if (IsProtected(name))
|
||||
{
|
||||
// 例如 GC-SAVEDOG.exe:本进程正在运行,Windows 上无法替换。
|
||||
@@ -575,6 +583,52 @@ internal sealed class Applier
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 合并新包里的 <c>.GC/bin</c>:只搬这一层文件,不动 .GC 下的用户数据。
|
||||
///
|
||||
/// 守护进程放在这里(而不是安装目录根)是为了「非本体文件全部收进 .GC/bin」;
|
||||
/// 但正在运行的是 <c>.GC/safedog</c> 里的副本,所以这里的文件可以安全替换。
|
||||
/// </summary>
|
||||
private void MergeGcBin(string stageGc, string installDir, string backupDir,
|
||||
List<(string Name, string? BackupPath)> replaced)
|
||||
{
|
||||
try
|
||||
{
|
||||
var bin = Path.Combine(stageGc, "bin");
|
||||
if (!Directory.Exists(bin)) return;
|
||||
|
||||
var relBin = Path.Combine(".GC", "bin");
|
||||
var targetBin = Path.Combine(installDir, relBin);
|
||||
Directory.CreateDirectory(targetBin);
|
||||
|
||||
foreach (var file in Directory.GetFiles(bin))
|
||||
{
|
||||
var name = Path.GetFileName(file);
|
||||
var rel = Path.Combine(relBin, name);
|
||||
var target = Path.Combine(targetBin, name);
|
||||
var backup = Path.Combine(backupDir, ".GC-bin", name);
|
||||
|
||||
if (File.Exists(target))
|
||||
{
|
||||
MoveEntry(target, backup);
|
||||
replaced.Add((rel, backup));
|
||||
}
|
||||
else
|
||||
{
|
||||
replaced.Add((rel, null));
|
||||
}
|
||||
|
||||
MoveEntry(file, target);
|
||||
_log.Info("已更新非本体文件: " + rel, "Updated non-core file: " + rel);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_log.Warn($"合并 .GC/bin 失败(继续使用已有版本):{ex.Message}",
|
||||
$"Failed to merge .GC/bin (keeping the existing one): {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 把备份里的条目原样搬回安装目录,撤掉新装的内容。
|
||||
/// <paramref name="BackupPath"/> 为 null 表示这一项是新包里独有的(没有旧版本),
|
||||
@@ -623,7 +677,7 @@ internal sealed class Applier
|
||||
|
||||
/// <summary>
|
||||
/// 安装目录里不该被更新碰的东西:
|
||||
/// · .GC —— 模型库、设置、日志、更新目录本身都在这里;
|
||||
/// · .GC —— 模型库、设置、日志、更新目录本身都在这里(只有 bin/ 由 MergeGcBin 单独处理);
|
||||
/// · GC-SAVEDOG.exe —— 本进程正在运行,Windows 上无法替换。
|
||||
/// </summary>
|
||||
private static bool IsProtected(string name)
|
||||
|
||||
+2
-1
@@ -69,7 +69,8 @@ Windows 还需要 **VS Build Tools 的「使用 C++ 的桌面开发」工作负
|
||||
```bash
|
||||
# 按构建主机自动选目标,每条产物都带 Flutter 前端:
|
||||
# macOS 主机 → mac-arm64(原生)+ win-amd64 / win-arm64(mingw 交叉)
|
||||
# Linux 主机 → linux-arm64(仅 aarch64 主机)+ win-amd64 / win-arm64(mingw 交叉)
|
||||
# Linux 主机 → win-amd64 / win-arm64(mingw 交叉)
|
||||
# Linux 产物默认不出:需 aarch64 主机 + GC_BUILD_LINUX=1
|
||||
# Windows 主机 → win-amd64 / win-arm64(原生)
|
||||
./build.sh build
|
||||
|
||||
|
||||
@@ -55,6 +55,10 @@ Windows 与 macOS 用**同一套 Flutter 代码 + 各自的原生 runner**:
|
||||
|
||||
### 1. 启动后端
|
||||
|
||||
发布版里后端不走独立进程:`GC-BOOT` 直接引用本工程,调用
|
||||
`BackendServer.Start(args, port)` 在自己进程内托管,发布包因此只有一个 exe
|
||||
(两个自包含进程会把 60MB 运行时复制两份)。下面的独立运行方式只用于开发调试。
|
||||
|
||||
```bash
|
||||
# 仓库根目录
|
||||
dotnet run --project GC-UI/backend/GC.UI.Server
|
||||
|
||||
@@ -0,0 +1,664 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using GC.Download;
|
||||
using GC.Models;
|
||||
using GC.Services;
|
||||
using GC.UI.Server;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace GC.UI.Server;
|
||||
|
||||
/// <summary>
|
||||
/// GC-UI 后端(本地 HTTP 服务:模型扫描 / 下载 / 更新 / 设置 / 模型窗口宿主)。
|
||||
///
|
||||
/// 两种跑法共用同一份代码:
|
||||
/// · 独立进程:<c>GC.UI.Server</c> 可执行文件(开发调试 / 旧包兼容);
|
||||
/// · 进程内:启动器直接调用 <see cref="Start"/>,把后端跑在自己的进程里 ——
|
||||
/// 发布包因此只需要一个 exe,不必再复制一份完整的 .NET 运行时。
|
||||
/// </summary>
|
||||
public static class BackendServer
|
||||
{
|
||||
/// <summary>按命令行 / GC_UI_PORT 解析端口并构建(未启动)的后端。</summary>
|
||||
public static WebApplication StartFromCommandLine(string[] args)
|
||||
=> Start(args, ResolvePort(args));
|
||||
|
||||
/// <summary>
|
||||
/// 构建后端。返回的 <see cref="WebApplication"/> 尚未启动:
|
||||
/// 独立进程直接 <c>Run()</c>,启动器用 <c>StartAsync()</c> 之后继续拉起界面。
|
||||
/// </summary>
|
||||
public static WebApplication Start(string[] args, int port)
|
||||
{
|
||||
// 下载模块(GC-DOWNLOAD)通过宿主钩子注入,和 GC-BOOT 的做法一致。
|
||||
DownloadModuleHost.Factory = new DownloadModuleFactory();
|
||||
|
||||
var services = AppServices.Create();
|
||||
var uiHost = new AvaloniaHost(services);
|
||||
|
||||
var builder = WebApplication.CreateBuilder(new WebApplicationOptions { Args = args });
|
||||
builder.Logging.ClearProviders();
|
||||
builder.WebHost.UseUrls($"http://127.0.0.1:{port}");
|
||||
|
||||
// 本地伴随进程:限制请求体大小、关闭 Server 头、收紧超时,减少被本地恶意页面
|
||||
// 或异常客户端拖垮的攻击面。
|
||||
builder.WebHost.ConfigureKestrel(options =>
|
||||
{
|
||||
options.AddServerHeader = false;
|
||||
options.Limits.MaxRequestBodySize = 2 * 1024 * 1024;
|
||||
options.Limits.RequestHeadersTimeout = TimeSpan.FromSeconds(15);
|
||||
options.Limits.KeepAliveTimeout = TimeSpan.FromMinutes(2);
|
||||
options.Limits.MaxConcurrentConnections = 64;
|
||||
});
|
||||
|
||||
// 桌面端(Windows/macOS)走原生 HTTP,不需要 CORS;
|
||||
// 这里放开本机回环来源,方便用 `flutter run -d chrome` 调试界面。
|
||||
builder.Services.AddCors(options => options.AddDefaultPolicy(policy => policy
|
||||
.SetIsOriginAllowed(origin =>
|
||||
Uri.TryCreate(origin, UriKind.Absolute, out var uri) &&
|
||||
(uri.Host == "127.0.0.1" || uri.Host == "localhost" || uri.Host == "::1"))
|
||||
.AllowAnyHeader()
|
||||
.AllowAnyMethod()));
|
||||
|
||||
var app = builder.Build();
|
||||
app.UseCors();
|
||||
|
||||
// 日志与启动器共用 .GC/logs,整条启动链路(启动器 → 后端 → 守护进程)都在同一组文件里。
|
||||
var logPaths = AppPaths.Discover();
|
||||
GcLog.Init(logPaths.LogsRoot);
|
||||
GcLog.Info($"GC-UI 后端启动,监听 127.0.0.1:{port}",
|
||||
$"GC-UI backend started on 127.0.0.1:{port}");
|
||||
|
||||
// 设置白名单 / 标识校验用到的规则(只在本进程内使用)。
|
||||
var allowedLanguages = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
|
||||
{ "auto", "zh-CN", "en" };
|
||||
var allowedThemes = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
|
||||
{ "light", "dark", "system" };
|
||||
var accentHexRegex = new System.Text.RegularExpressions.Regex(
|
||||
"^#(?:[0-9A-Fa-f]{6})$", System.Text.RegularExpressions.RegexOptions.Compiled);
|
||||
var safeIdRegex = new System.Text.RegularExpressions.Regex(
|
||||
"^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$", System.Text.RegularExpressions.RegexOptions.Compiled);
|
||||
|
||||
// 安全响应头 + Host/Origin 校验(抵御 DNS rebinding 与跨站调用)。
|
||||
app.Use(async (context, next) =>
|
||||
{
|
||||
var headers = context.Response.Headers;
|
||||
headers["X-Content-Type-Options"] = "nosniff";
|
||||
headers["X-Frame-Options"] = "DENY";
|
||||
headers["Referrer-Policy"] = "no-referrer";
|
||||
headers["Content-Security-Policy"] = "default-src 'none'; frame-ancestors 'none'";
|
||||
headers["Cache-Control"] = "no-store";
|
||||
|
||||
var host = context.Request.Host.Host;
|
||||
if (!string.Equals(host, "127.0.0.1", StringComparison.OrdinalIgnoreCase) &&
|
||||
!string.Equals(host, "localhost", StringComparison.OrdinalIgnoreCase) &&
|
||||
!string.Equals(host, "::1", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
context.Response.StatusCode = StatusCodes.Status403Forbidden;
|
||||
return;
|
||||
}
|
||||
|
||||
var origin = context.Request.Headers.Origin.ToString();
|
||||
if (!string.IsNullOrEmpty(origin) &&
|
||||
!(Uri.TryCreate(origin, UriKind.Absolute, out var parsed) &&
|
||||
(parsed.Host == "127.0.0.1" || parsed.Host == "localhost" || parsed.Host == "::1")))
|
||||
{
|
||||
context.Response.StatusCode = StatusCodes.Status403Forbidden;
|
||||
return;
|
||||
}
|
||||
|
||||
await next();
|
||||
});
|
||||
|
||||
// 写入类接口做简单限流:单 IP 每秒最多 40 次,防止本地脚本刷爆下载/更新。
|
||||
var writeBuckets =
|
||||
new System.Collections.Concurrent.ConcurrentDictionary<string, (long Window, int Count)>();
|
||||
app.Use(async (context, next) =>
|
||||
{
|
||||
if (HttpMethods.IsPost(context.Request.Method) ||
|
||||
HttpMethods.IsDelete(context.Request.Method))
|
||||
{
|
||||
var key = context.Connection.RemoteIpAddress?.ToString() ?? "local";
|
||||
var now = Environment.TickCount64;
|
||||
|
||||
// 定期丢弃过期窗口:本机连接数不多,但长时间运行后桶只增不减会缓慢泄漏。
|
||||
if (writeBuckets.Count > 256)
|
||||
{
|
||||
foreach (var entry in writeBuckets)
|
||||
{
|
||||
if (now - entry.Value.Window > 60_000)
|
||||
writeBuckets.TryRemove(entry.Key, out _);
|
||||
}
|
||||
}
|
||||
|
||||
var bucket = writeBuckets.AddOrUpdate(
|
||||
key,
|
||||
_ => (now, 1),
|
||||
(_, old) => now - old.Window > 1000 ? (now, 1) : (old.Window, old.Count + 1));
|
||||
|
||||
if (bucket.Count > 40)
|
||||
{
|
||||
context.Response.StatusCode = StatusCodes.Status429TooManyRequests;
|
||||
await context.Response.WriteAsJsonAsync(ErrorDto.Of("请求过于频繁,请稍后再试"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
await next();
|
||||
});
|
||||
|
||||
// ---- 健康检查 -------------------------------------------------------------
|
||||
|
||||
app.MapGet("/api/health", () => Results.Ok(new HealthDto(
|
||||
true,
|
||||
LauncherRuntimeInfo.CurrentLauncherVersion,
|
||||
LauncherRuntimeInfo.CurrentRid,
|
||||
uiHost.IsAvailable,
|
||||
uiHost.LastError)));
|
||||
|
||||
// ---- 已安装模型 -----------------------------------------------------------
|
||||
|
||||
app.MapGet("/api/models", () =>
|
||||
Results.Ok(services.Models.Scan().Select(ToModelDto).ToList()));
|
||||
|
||||
app.MapGet("/api/models/{id}/preview", (string id, HttpResponse response) =>
|
||||
{
|
||||
if (!IsSafeId(id)) return Results.BadRequest(ErrorDto.Of("模型标识无效"));
|
||||
var package = services.Models.Find(id);
|
||||
if (package == null || !File.Exists(package.PreviewPath)) return Results.NotFound();
|
||||
|
||||
// 封面是静态图,允许前端缓存:默认全局中间件写的 no-store 会让每次滚动都重新请求。
|
||||
// 按扩展名给准确的 MIME —— 统一写 image/png 时,WebP / JPEG 封面在部分平台显示不出来。
|
||||
response.Headers.CacheControl = "private, max-age=300";
|
||||
return Results.File(package.PreviewPath, GuessImageContentType(package.PreviewPath));
|
||||
});
|
||||
|
||||
app.MapPost("/api/models/{id}/launch", async (string id) =>
|
||||
{
|
||||
if (!IsSafeId(id)) return Results.BadRequest(new LaunchResultDto(false, "模型标识无效"));
|
||||
var package = services.Models.Find(id);
|
||||
if (package == null) return Results.NotFound(new LaunchResultDto(false, $"没有找到模型 {id}"));
|
||||
|
||||
try
|
||||
{
|
||||
services.Memory.Refresh();
|
||||
var message = await uiHost.LaunchAsync(package);
|
||||
return Results.Ok(new LaunchResultDto(true, message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// 细节只写日志,不回显给调用方,避免泄漏本机路径等内部信息。
|
||||
Console.Error.WriteLine($"[launch] 启动模型 {id} 失败: {ex}");
|
||||
return Results.Json(new LaunchResultDto(false, "模型启动失败,请查看后端日志"), statusCode: 503);
|
||||
}
|
||||
});
|
||||
|
||||
app.MapDelete("/api/models/{id}", (string id) =>
|
||||
{
|
||||
if (!IsSafeId(id)) return Results.BadRequest(ErrorDto.Of("模型标识无效"));
|
||||
var ok = services.Models.Delete(id);
|
||||
if (ok) services.Models.NotifyChanged();
|
||||
return ok
|
||||
? Results.Ok(new LaunchResultDto(true, $"已删除模型 {id}"))
|
||||
: Results.NotFound(ErrorDto.Of($"没有找到模型 {id}"));
|
||||
});
|
||||
|
||||
// ---- 设置 -----------------------------------------------------------------
|
||||
|
||||
app.MapGet("/api/settings", () => Results.Ok(ToSettingsDto()));
|
||||
|
||||
app.MapPost("/api/settings", (SettingsPatch? patch) =>
|
||||
{
|
||||
if (patch == null) return Results.BadRequest(ErrorDto.Of("缺少设置内容"));
|
||||
|
||||
// 白名单校验:设置项会写进磁盘并被前端直接使用,不接受任意字符串。
|
||||
if (patch.Language != null && !allowedLanguages.Contains(patch.Language))
|
||||
return Results.BadRequest(ErrorDto.Of("不支持的界面语言"));
|
||||
if (patch.Theme != null && !allowedThemes.Contains(patch.Theme))
|
||||
return Results.BadRequest(ErrorDto.Of("不支持的主题"));
|
||||
if (patch.AccentColor != null && !accentHexRegex.IsMatch(patch.AccentColor))
|
||||
return Results.BadRequest(ErrorDto.Of("主题色需为 #RRGGBB"));
|
||||
if (patch.UpdateRepository != null && !IsAllowedRepository(patch.UpdateRepository))
|
||||
return Results.BadRequest(ErrorDto.Of("更新仓库地址不受信任"));
|
||||
|
||||
services.Settings.Apply(s =>
|
||||
{
|
||||
if (patch.Language != null) s.Language = patch.Language;
|
||||
if (patch.Theme != null) s.Theme = patch.Theme;
|
||||
if (patch.AccentColor != null) s.AccentColor = patch.AccentColor.ToUpperInvariant();
|
||||
if (patch.RenderFps.HasValue) s.RenderFps = Math.Clamp(patch.RenderFps.Value, 12, 120);
|
||||
if (patch.MemoryMb.HasValue) s.MemoryMb = Math.Clamp(patch.MemoryMb.Value, 256, 16384);
|
||||
if (patch.MemoryAuto.HasValue) s.MemoryAuto = patch.MemoryAuto.Value;
|
||||
if (patch.AutoUpdateOnStartup.HasValue) s.AutoUpdateOnStartup = patch.AutoUpdateOnStartup.Value;
|
||||
if (patch.RequireSignedManifest.HasValue) s.RequireSignedManifest = patch.RequireSignedManifest.Value;
|
||||
if (patch.UpdateRepository != null) s.UpdateRepository = patch.UpdateRepository;
|
||||
if (patch.UpdateLocalRoot != null) s.UpdateLocalRoot = patch.UpdateLocalRoot;
|
||||
if (patch.ModelRootOverride != null) s.ModelRootOverride = patch.ModelRootOverride;
|
||||
});
|
||||
|
||||
if (patch.Language != null) L.I.SetLanguage(patch.Language);
|
||||
if (patch.MemoryMb.HasValue || patch.MemoryAuto.HasValue)
|
||||
services.Memory.ApplyAuto(services.Settings.Current.MemoryAuto, services.Settings.Current.MemoryMb);
|
||||
|
||||
return Results.Ok(ToSettingsDto());
|
||||
});
|
||||
|
||||
// ---- 模型源 ---------------------------------------------------------------
|
||||
|
||||
app.MapGet("/api/sources", () =>
|
||||
Results.Ok(services.Settings.Current.Sources.Select(ToSourceDto).ToList()));
|
||||
|
||||
app.MapPost("/api/sources/select", async (ForceRequest? request) =>
|
||||
{
|
||||
var force = request?.Force ?? false;
|
||||
try
|
||||
{
|
||||
var fastest = await services.Selector.PickFastestAsync(force, CancellationToken.None);
|
||||
services.Updates.UseRemote(services.DownloadModule.CreateRemote(fastest));
|
||||
return Results.Ok(new LatencyDto(
|
||||
fastest.Id, fastest.Name,
|
||||
services.Selector.LastLatency.TryGetValue(fastest.Id, out var ms) ? ms : 0));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.Error.WriteLine($"[sources] 切换模型源失败: {ex}");
|
||||
return Results.Json(ErrorDto.Of("模型源切换失败"), statusCode: 503);
|
||||
}
|
||||
});
|
||||
|
||||
app.MapGet("/api/remote/models", async (string? sourceId, bool force) =>
|
||||
{
|
||||
var source = ResolveSource(sourceId);
|
||||
if (source == null) return Results.NotFound(ErrorDto.Of("没有可用的模型源"));
|
||||
|
||||
var index = await services.Sources.FetchAsync(source, force, null, CancellationToken.None);
|
||||
var installed = services.Models.Scan()
|
||||
.ToDictionary(p => p.Id, p => p.Manifest.Version, StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
return Results.Ok(new SourceIndexDto(
|
||||
index.SourceId,
|
||||
index.Root,
|
||||
index.FromCache,
|
||||
index.Error,
|
||||
index.ResolvedFrom,
|
||||
index.Models.Select(m => new RemoteModelDto(
|
||||
m.Id,
|
||||
m.LocalizedName,
|
||||
m.LocalizedDescription,
|
||||
m.Manifest.Version,
|
||||
m.SizeBytes,
|
||||
ModelScanner.HumanSize(m.SizeBytes),
|
||||
m.SourceId,
|
||||
installed.ContainsKey(m.Id),
|
||||
installed.TryGetValue(m.Id, out var v) ? v : null)).ToList()));
|
||||
});
|
||||
|
||||
// ---- 下载 -----------------------------------------------------------------
|
||||
|
||||
app.MapPost("/api/download", async (DownloadRequest? request) =>
|
||||
{
|
||||
if (request == null || string.IsNullOrWhiteSpace(request.ModelId))
|
||||
return Results.BadRequest(ErrorDto.Of("缺少 modelId"));
|
||||
|
||||
var source = ResolveSource(request.SourceId);
|
||||
if (source == null) return Results.NotFound(ErrorDto.Of("没有可用的模型源"));
|
||||
|
||||
var index = await services.Sources.FetchAsync(source, false, null, CancellationToken.None);
|
||||
var model = index.Models.FirstOrDefault(m =>
|
||||
m.Id.Equals(request.ModelId, StringComparison.OrdinalIgnoreCase));
|
||||
if (model == null)
|
||||
return Results.NotFound(ErrorDto.Of($"源里没有模型 {request.ModelId}"));
|
||||
|
||||
var job = services.Downloads.Enqueue(model);
|
||||
return Results.Ok(ToJobDto(job));
|
||||
});
|
||||
|
||||
app.MapGet("/api/download/jobs", () =>
|
||||
Results.Ok(services.Downloads.Jobs.Select(ToJobDto).ToList()));
|
||||
|
||||
app.MapPost("/api/download/{id}/cancel", (string id) =>
|
||||
ActOnJob(id, job => services.Downloads.Cancel(job)));
|
||||
|
||||
app.MapPost("/api/download/{id}/retry", (string id) =>
|
||||
ActOnJob(id, job => services.Downloads.Retry(job)));
|
||||
|
||||
app.MapPost("/api/download/{id}/remove", (string id) =>
|
||||
ActOnJob(id, job => services.Downloads.Remove(job)));
|
||||
|
||||
app.MapPost("/api/download/clear-finished", () =>
|
||||
{
|
||||
services.Downloads.ClearFinished();
|
||||
return Results.Ok(new LaunchResultDto(true, "已清除完成的任务"));
|
||||
});
|
||||
|
||||
// ---- 更新 -----------------------------------------------------------------
|
||||
|
||||
app.MapPost("/api/update/check", async (ForceRequest? request) =>
|
||||
{
|
||||
var force = request?.Force ?? true;
|
||||
var messages = new List<string>();
|
||||
|
||||
try
|
||||
{
|
||||
var fastest = await services.Selector.PickFastestAsync(force, CancellationToken.None);
|
||||
services.Updates.UseRemote(services.DownloadModule.CreateRemote(fastest));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.Error.WriteLine($"[update] 测速失败,沿用当前源: {ex.Message}");
|
||||
}
|
||||
|
||||
string? launcherLatest = null;
|
||||
try
|
||||
{
|
||||
launcherLatest = await services.LauncherUpdates.CheckAsync(
|
||||
services.Updates.Remote, CancellationToken.None);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.Error.WriteLine($"[update] 启动器版本检查失败: {ex.Message}");
|
||||
}
|
||||
|
||||
var progress = new Progress<UpdateProgress>(p =>
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(p.Message)) messages.Add(p.Message);
|
||||
});
|
||||
|
||||
var result = await services.Updates.RunAsync(force, progress, CancellationToken.None);
|
||||
|
||||
return Results.Ok(new UpdateCheckDto(
|
||||
result.Outcome.ToString(),
|
||||
result.Message,
|
||||
result.UpdatedModels,
|
||||
result.ModelNames,
|
||||
result.LauncherMessage,
|
||||
result.Error,
|
||||
launcherLatest,
|
||||
services.Updates.Remote.DisplayName,
|
||||
services.Selector.LastLatency
|
||||
.Select(kv => new LatencyDto(
|
||||
kv.Key,
|
||||
SourcePreset.Find(kv.Key)?.Name ?? kv.Key,
|
||||
kv.Value))
|
||||
.ToList()));
|
||||
});
|
||||
|
||||
// ---- 关于 -----------------------------------------------------------------
|
||||
|
||||
app.MapGet("/api/about", async () =>
|
||||
{
|
||||
var repository = services.Settings.Current.UpdateRepository;
|
||||
var contributors = new List<ContributorDto>();
|
||||
try
|
||||
{
|
||||
foreach (var c in await ContributorsService.FetchAsync(repository, CancellationToken.None))
|
||||
contributors.Add(new ContributorDto(c.DisplayName, c.Contributions, c.AvatarUrl));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.Error.WriteLine($"[about] 读取贡献者失败: {ex.Message}");
|
||||
}
|
||||
|
||||
return Results.Ok(new AboutDto(
|
||||
"Morris GC",
|
||||
LauncherRuntimeInfo.CurrentLauncherVersion,
|
||||
LauncherRuntimeInfo.CurrentRid,
|
||||
repository,
|
||||
contributors,
|
||||
// 「关于」页展示的技术栈信息:源码语言与前端框架。
|
||||
SourceLanguage: "C#",
|
||||
Frontend: "Flutter"));
|
||||
});
|
||||
|
||||
// ---- 系统集成 -------------------------------------------------------------
|
||||
|
||||
app.MapPost("/api/shell/open-folder", (PathRequest? request) =>
|
||||
{
|
||||
var path = request?.Path;
|
||||
if (string.IsNullOrWhiteSpace(path))
|
||||
return Results.BadRequest(ErrorDto.Of("缺少 path"));
|
||||
|
||||
// 只允许打开启动器自己的目录,避免前端被当成任意路径执行器
|
||||
if (!IsInsideKnownRoot(path!))
|
||||
return Results.BadRequest(ErrorDto.Of("只允许打开启动器自己的目录"));
|
||||
|
||||
Shell.OpenFolder(path!);
|
||||
return Results.Ok(new LaunchResultDto(true, "已打开目录"));
|
||||
});
|
||||
|
||||
app.MapPost("/api/shell/open-url", (UrlRequest? request) =>
|
||||
{
|
||||
var url = request?.Url;
|
||||
if (string.IsNullOrWhiteSpace(url) || url.Length > 2048 ||
|
||||
!Uri.TryCreate(url, UriKind.Absolute, out var uri))
|
||||
return Results.BadRequest(ErrorDto.Of("URL 无效"));
|
||||
|
||||
if (uri.Scheme != Uri.UriSchemeHttp && uri.Scheme != Uri.UriSchemeHttps)
|
||||
return Results.BadRequest(ErrorDto.Of("只允许 http/https 链接"));
|
||||
|
||||
if (!string.IsNullOrEmpty(uri.UserInfo))
|
||||
return Results.BadRequest(ErrorDto.Of("URL 不允许携带账号密码"));
|
||||
|
||||
Shell.OpenUrl(url!);
|
||||
return Results.Ok(new LaunchResultDto(true, "已打开链接"));
|
||||
});
|
||||
|
||||
// ---- 启动 -----------------------------------------------------------------
|
||||
|
||||
WriteEndpointFile(services, port);
|
||||
Console.WriteLine($"[GC-UI] 后端已启动: http://127.0.0.1:{port}");
|
||||
Console.WriteLine($"[GC-UI] 模型库: {services.Paths.ModelRoot}");
|
||||
|
||||
return app;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 局部辅助
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
static void WriteEndpointFile(AppServices services, int port)
|
||||
{
|
||||
try
|
||||
{
|
||||
var file = Path.Combine(services.Paths.HomeRoot, "ui-backend.json");
|
||||
var payload = JsonSerializer.Serialize(new
|
||||
{
|
||||
port,
|
||||
pid = Environment.ProcessId,
|
||||
url = $"http://127.0.0.1:{port}",
|
||||
version = LauncherRuntimeInfo.CurrentLauncherVersion,
|
||||
platform = LauncherRuntimeInfo.CurrentRid,
|
||||
startedAt = DateTimeOffset.UtcNow.ToString("o")
|
||||
}, new JsonSerializerOptions { WriteIndented = true });
|
||||
|
||||
File.WriteAllText(file, payload);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.Error.WriteLine($"[GC-UI] 写入端点文件失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>按扩展名推断图片 MIME;模型封面允许 png / jpg / webp / gif。</summary>
|
||||
static string GuessImageContentType(string path) => Path.GetExtension(path).ToLowerInvariant() switch
|
||||
{
|
||||
".jpg" or ".jpeg" => "image/jpeg",
|
||||
".webp" => "image/webp",
|
||||
".gif" => "image/gif",
|
||||
".bmp" => "image/bmp",
|
||||
".svg" => "image/svg+xml",
|
||||
_ => "image/png"
|
||||
};
|
||||
|
||||
ModelDto ToModelDto(ModelPackage package) => new( package.Id,
|
||||
package.LocalizedName,
|
||||
package.LocalizedDescription,
|
||||
package.Manifest.Version,
|
||||
package.Manifest.Author,
|
||||
package.SizeBytes,
|
||||
ModelScanner.HumanSize(package.SizeBytes),
|
||||
package.Manifest.Tags ?? new List<string>(),
|
||||
File.Exists(package.PreviewPath),
|
||||
$"/api/models/{package.Id}/preview",
|
||||
package.Directory,
|
||||
package.DataDirectory);
|
||||
|
||||
SourceDto ToSourceDto(ModelSource source) => new(
|
||||
source.Id,
|
||||
string.IsNullOrWhiteSpace(source.Name) ? source.Id : source.Name,
|
||||
source.Url,
|
||||
source.Enabled,
|
||||
source.BuiltIn,
|
||||
source.DisplayHost);
|
||||
|
||||
SettingsDto ToSettingsDto() => new(
|
||||
services.Settings.Current.Language,
|
||||
services.Settings.Current.Theme,
|
||||
services.Settings.Current.AccentColor,
|
||||
services.Settings.Current.RenderFps,
|
||||
services.Settings.Current.MemoryMb,
|
||||
services.Settings.Current.MemoryAuto,
|
||||
services.Settings.Current.AutoUpdateOnStartup,
|
||||
services.Settings.Current.RequireSignedManifest,
|
||||
services.Settings.Current.UpdateRepository,
|
||||
services.Settings.Current.UpdateLocalRoot,
|
||||
services.Settings.Current.ModelRootOverride,
|
||||
services.Memory.BudgetMb,
|
||||
services.Memory.UsageText,
|
||||
services.Paths.ModelRoot,
|
||||
services.Paths.DataRoot,
|
||||
services.Paths.SettingsFile,
|
||||
LauncherRuntimeInfo.CurrentLauncherVersion,
|
||||
LauncherRuntimeInfo.CurrentRid,
|
||||
services.Settings.Current.Sources.Select(ToSourceDto).ToList(),
|
||||
L.Supported.Select(s => new LanguageDto(s.Code, s.Label)).ToList());
|
||||
|
||||
JobDto ToJobDto(IDownloadJob job) => new(
|
||||
job.Id,
|
||||
job.Model.Id,
|
||||
job.Name,
|
||||
job.Version,
|
||||
job.State.ToString(),
|
||||
job.Progress,
|
||||
job.StatusText,
|
||||
job.DetailText,
|
||||
job.Error,
|
||||
job.IsActive,
|
||||
job.CanRetry,
|
||||
job.IsDone);
|
||||
|
||||
ModelSource? ResolveSource(string? sourceId)
|
||||
{
|
||||
var sources = services.Settings.Current.Sources;
|
||||
if (!string.IsNullOrWhiteSpace(sourceId))
|
||||
{
|
||||
var exact = sources.FirstOrDefault(s =>
|
||||
s.Id.Equals(sourceId, StringComparison.OrdinalIgnoreCase));
|
||||
if (exact != null) return exact;
|
||||
}
|
||||
|
||||
return sources.FirstOrDefault(s => s.Enabled && !string.IsNullOrWhiteSpace(s.Url))
|
||||
?? sources.FirstOrDefault();
|
||||
}
|
||||
|
||||
IResult ActOnJob(string id, Action<IDownloadJob> action)
|
||||
{
|
||||
if (!IsSafeId(id)) return Results.BadRequest(ErrorDto.Of("任务标识无效"));
|
||||
var job = services.Downloads.Jobs.FirstOrDefault(j =>
|
||||
j.Id.Equals(id, StringComparison.OrdinalIgnoreCase));
|
||||
if (job == null) return Results.NotFound(ErrorDto.Of($"没有找到任务 {id}"));
|
||||
|
||||
action(job);
|
||||
return Results.Ok(ToJobDto(job));
|
||||
}
|
||||
|
||||
bool IsInsideKnownRoot(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
var full = Path.GetFullPath(path);
|
||||
var roots = new[]
|
||||
{
|
||||
services.Paths.ModelRoot,
|
||||
services.Paths.DataRoot,
|
||||
services.Paths.HomeRoot,
|
||||
services.Paths.AppRoot
|
||||
};
|
||||
|
||||
foreach (var root in roots)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(root)) continue;
|
||||
var rootFull = Path.GetFullPath(root);
|
||||
if (full.Equals(rootFull, StringComparison.OrdinalIgnoreCase)) return true;
|
||||
if (full.StartsWith(rootFull + Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// 路由标识:只允许字母数字开头,后接字母数字/点/下划线/短横线,长度上限 64。
|
||||
// 用于模型 id、任务 id,杜绝 `../` 之类的路径穿越尝试。
|
||||
bool IsSafeId(string? id) => !string.IsNullOrEmpty(id) && safeIdRegex.IsMatch(id);
|
||||
|
||||
// 更新仓库地址:必须是 https、不带账号密码、不是回环/内网 IP。
|
||||
// 防止把本地后端当成 SSRF 跳板去访问内网服务。
|
||||
bool IsAllowedRepository(string value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value)) return false;
|
||||
if (!Uri.TryCreate(value, UriKind.Absolute, out var uri)) return false;
|
||||
if (uri.Scheme != Uri.UriSchemeHttps) return false;
|
||||
if (!string.IsNullOrEmpty(uri.UserInfo)) return false;
|
||||
if (string.Equals(uri.Host, "localhost", StringComparison.OrdinalIgnoreCase)) return false;
|
||||
if (System.Net.IPAddress.TryParse(uri.Host, out var ip) &&
|
||||
(System.Net.IPAddress.IsLoopback(ip) || IsPrivateAddress(ip)))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool IsPrivateAddress(System.Net.IPAddress ip)
|
||||
{
|
||||
var bytes = ip.GetAddressBytes();
|
||||
if (bytes.Length != 4) return false;
|
||||
return bytes[0] == 10
|
||||
|| (bytes[0] == 172 && bytes[1] >= 16 && bytes[1] <= 31)
|
||||
|| (bytes[0] == 192 && bytes[1] == 168)
|
||||
|| (bytes[0] == 169 && bytes[1] == 254);
|
||||
}
|
||||
}
|
||||
|
||||
public static int ResolvePort(string[] args)
|
||||
{
|
||||
// 优先用启动器传来的端口(GC_UI_PORT),保证前端拼出来的 baseUrl 和这里一致。
|
||||
var env = Environment.GetEnvironmentVariable(GcUiContract.PortEnvVar);
|
||||
if (int.TryParse(env, out var fromEnv) && fromEnv > 0 && fromEnv < 65536) return fromEnv;
|
||||
|
||||
for (var i = 0; i < args.Length; i++)
|
||||
{
|
||||
if (args[i] == "--port" && i + 1 < args.Length &&
|
||||
int.TryParse(args[i + 1], out var next) && next > 0 && next < 65536)
|
||||
return next;
|
||||
|
||||
const string prefix = "--port=";
|
||||
if (args[i].StartsWith(prefix, StringComparison.Ordinal) &&
|
||||
int.TryParse(args[i][prefix.Length..], out var inline) && inline > 0 && inline < 65536)
|
||||
return inline;
|
||||
}
|
||||
|
||||
return GcUiContract.DefaultPort;
|
||||
}
|
||||
}
|
||||
@@ -1,665 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using GC.Download;
|
||||
using GC.Models;
|
||||
using GC.Services;
|
||||
using GC.UI.Server;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// GC-UI 后端:本地 HTTP 服务(只监听 127.0.0.1)。
|
||||
//
|
||||
// 它把原来 GC 启动器里的服务层原样复用(GC.Core / GC-DOWNLOAD),
|
||||
// 只是把「界面」从 Avalonia 换成 Flutter —— 前端通过下面这些接口驱动后端。
|
||||
//
|
||||
// GET /api/health 健康检查 + 图形环境是否可用
|
||||
// GET /api/models 已安装模型
|
||||
// GET /api/models/{id}/preview 模型封面图
|
||||
// POST /api/models/{id}/launch 启动模型(打开模型自己的窗口)
|
||||
// DELETE /api/models/{id} 删除模型
|
||||
// GET /api/settings 读取设置
|
||||
// POST /api/settings 修改设置(补丁式)
|
||||
// GET /api/sources 模型源列表
|
||||
// POST /api/sources/select 双源测速并切到最快
|
||||
// GET /api/remote/models 远端可下载模型
|
||||
// POST /api/download 入队下载
|
||||
// GET /api/download/jobs 下载任务
|
||||
// POST /api/download/{id}/cancel|retry|remove
|
||||
// POST /api/download/clear-finished 清除已完成
|
||||
// POST /api/update/check 检查模型 / 启动器更新
|
||||
// GET /api/about 版本 + 贡献者
|
||||
// POST /api/shell/open-folder|open-url 打开目录 / 链接
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
var port = ResolvePort(args);
|
||||
|
||||
// 下载模块(GC-DOWNLOAD)通过宿主钩子注入,和 GC-BOOT 的做法一致。
|
||||
DownloadModuleHost.Factory = new DownloadModuleFactory();
|
||||
|
||||
var services = AppServices.Create();
|
||||
var uiHost = new AvaloniaHost(services);
|
||||
|
||||
var builder = WebApplication.CreateBuilder(new WebApplicationOptions { Args = args });
|
||||
builder.Logging.ClearProviders();
|
||||
builder.WebHost.UseUrls($"http://127.0.0.1:{port}");
|
||||
|
||||
// 本地伴随进程:限制请求体大小、关闭 Server 头、收紧超时,减少被本地恶意页面
|
||||
// 或异常客户端拖垮的攻击面。
|
||||
builder.WebHost.ConfigureKestrel(options =>
|
||||
{
|
||||
options.AddServerHeader = false;
|
||||
options.Limits.MaxRequestBodySize = 2 * 1024 * 1024;
|
||||
options.Limits.RequestHeadersTimeout = TimeSpan.FromSeconds(15);
|
||||
options.Limits.KeepAliveTimeout = TimeSpan.FromMinutes(2);
|
||||
options.Limits.MaxConcurrentConnections = 64;
|
||||
});
|
||||
|
||||
// 桌面端(Windows/macOS)走原生 HTTP,不需要 CORS;
|
||||
// 这里放开本机回环来源,方便用 `flutter run -d chrome` 调试界面。
|
||||
builder.Services.AddCors(options => options.AddDefaultPolicy(policy => policy
|
||||
.SetIsOriginAllowed(origin =>
|
||||
Uri.TryCreate(origin, UriKind.Absolute, out var uri) &&
|
||||
(uri.Host == "127.0.0.1" || uri.Host == "localhost" || uri.Host == "::1"))
|
||||
.AllowAnyHeader()
|
||||
.AllowAnyMethod()));
|
||||
|
||||
var app = builder.Build();
|
||||
app.UseCors();
|
||||
|
||||
// 日志与启动器共用 .GC/logs,整条启动链路(启动器 → 后端 → 守护进程)都在同一组文件里。
|
||||
var logPaths = AppPaths.Discover();
|
||||
GcLog.Init(logPaths.LogsRoot);
|
||||
GcLog.Info($"GC-UI 后端启动,监听 127.0.0.1:{port}",
|
||||
$"GC-UI backend started on 127.0.0.1:{port}");
|
||||
|
||||
// 设置白名单 / 标识校验用到的规则(只在本进程内使用)。
|
||||
var allowedLanguages = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
|
||||
{ "auto", "zh-CN", "en" };
|
||||
var allowedThemes = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
|
||||
{ "light", "dark", "system" };
|
||||
var accentHexRegex = new System.Text.RegularExpressions.Regex(
|
||||
"^#(?:[0-9A-Fa-f]{6})$", System.Text.RegularExpressions.RegexOptions.Compiled);
|
||||
var safeIdRegex = new System.Text.RegularExpressions.Regex(
|
||||
"^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$", System.Text.RegularExpressions.RegexOptions.Compiled);
|
||||
|
||||
// 安全响应头 + Host/Origin 校验(抵御 DNS rebinding 与跨站调用)。
|
||||
app.Use(async (context, next) =>
|
||||
{
|
||||
var headers = context.Response.Headers;
|
||||
headers["X-Content-Type-Options"] = "nosniff";
|
||||
headers["X-Frame-Options"] = "DENY";
|
||||
headers["Referrer-Policy"] = "no-referrer";
|
||||
headers["Content-Security-Policy"] = "default-src 'none'; frame-ancestors 'none'";
|
||||
headers["Cache-Control"] = "no-store";
|
||||
|
||||
var host = context.Request.Host.Host;
|
||||
if (!string.Equals(host, "127.0.0.1", StringComparison.OrdinalIgnoreCase) &&
|
||||
!string.Equals(host, "localhost", StringComparison.OrdinalIgnoreCase) &&
|
||||
!string.Equals(host, "::1", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
context.Response.StatusCode = StatusCodes.Status403Forbidden;
|
||||
return;
|
||||
}
|
||||
|
||||
var origin = context.Request.Headers.Origin.ToString();
|
||||
if (!string.IsNullOrEmpty(origin) &&
|
||||
!(Uri.TryCreate(origin, UriKind.Absolute, out var parsed) &&
|
||||
(parsed.Host == "127.0.0.1" || parsed.Host == "localhost" || parsed.Host == "::1")))
|
||||
{
|
||||
context.Response.StatusCode = StatusCodes.Status403Forbidden;
|
||||
return;
|
||||
}
|
||||
|
||||
await next();
|
||||
});
|
||||
|
||||
// 写入类接口做简单限流:单 IP 每秒最多 40 次,防止本地脚本刷爆下载/更新。
|
||||
var writeBuckets =
|
||||
new System.Collections.Concurrent.ConcurrentDictionary<string, (long Window, int Count)>();
|
||||
app.Use(async (context, next) =>
|
||||
{
|
||||
if (HttpMethods.IsPost(context.Request.Method) ||
|
||||
HttpMethods.IsDelete(context.Request.Method))
|
||||
{
|
||||
var key = context.Connection.RemoteIpAddress?.ToString() ?? "local";
|
||||
var now = Environment.TickCount64;
|
||||
|
||||
// 定期丢弃过期窗口:本机连接数不多,但长时间运行后桶只增不减会缓慢泄漏。
|
||||
if (writeBuckets.Count > 256)
|
||||
{
|
||||
foreach (var entry in writeBuckets)
|
||||
{
|
||||
if (now - entry.Value.Window > 60_000)
|
||||
writeBuckets.TryRemove(entry.Key, out _);
|
||||
}
|
||||
}
|
||||
|
||||
var bucket = writeBuckets.AddOrUpdate(
|
||||
key,
|
||||
_ => (now, 1),
|
||||
(_, old) => now - old.Window > 1000 ? (now, 1) : (old.Window, old.Count + 1));
|
||||
|
||||
if (bucket.Count > 40)
|
||||
{
|
||||
context.Response.StatusCode = StatusCodes.Status429TooManyRequests;
|
||||
await context.Response.WriteAsJsonAsync(ErrorDto.Of("请求过于频繁,请稍后再试"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
await next();
|
||||
});
|
||||
|
||||
// ---- 健康检查 -------------------------------------------------------------
|
||||
|
||||
app.MapGet("/api/health", () => Results.Ok(new HealthDto(
|
||||
true,
|
||||
LauncherRuntimeInfo.CurrentLauncherVersion,
|
||||
LauncherRuntimeInfo.CurrentRid,
|
||||
uiHost.IsAvailable,
|
||||
uiHost.LastError)));
|
||||
|
||||
// ---- 已安装模型 -----------------------------------------------------------
|
||||
|
||||
app.MapGet("/api/models", () =>
|
||||
Results.Ok(services.Models.Scan().Select(ToModelDto).ToList()));
|
||||
|
||||
app.MapGet("/api/models/{id}/preview", (string id, HttpResponse response) =>
|
||||
{
|
||||
if (!IsSafeId(id)) return Results.BadRequest(ErrorDto.Of("模型标识无效"));
|
||||
var package = services.Models.Find(id);
|
||||
if (package == null || !File.Exists(package.PreviewPath)) return Results.NotFound();
|
||||
|
||||
// 封面是静态图,允许前端缓存:默认全局中间件写的 no-store 会让每次滚动都重新请求。
|
||||
// 按扩展名给准确的 MIME —— 统一写 image/png 时,WebP / JPEG 封面在部分平台显示不出来。
|
||||
response.Headers.CacheControl = "private, max-age=300";
|
||||
return Results.File(package.PreviewPath, GuessImageContentType(package.PreviewPath));
|
||||
});
|
||||
|
||||
app.MapPost("/api/models/{id}/launch", async (string id) =>
|
||||
{
|
||||
if (!IsSafeId(id)) return Results.BadRequest(new LaunchResultDto(false, "模型标识无效"));
|
||||
var package = services.Models.Find(id);
|
||||
if (package == null) return Results.NotFound(new LaunchResultDto(false, $"没有找到模型 {id}"));
|
||||
|
||||
try
|
||||
{
|
||||
services.Memory.Refresh();
|
||||
var message = await uiHost.LaunchAsync(package);
|
||||
return Results.Ok(new LaunchResultDto(true, message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// 细节只写日志,不回显给调用方,避免泄漏本机路径等内部信息。
|
||||
Console.Error.WriteLine($"[launch] 启动模型 {id} 失败: {ex}");
|
||||
return Results.Json(new LaunchResultDto(false, "模型启动失败,请查看后端日志"), statusCode: 503);
|
||||
}
|
||||
});
|
||||
|
||||
app.MapDelete("/api/models/{id}", (string id) =>
|
||||
{
|
||||
if (!IsSafeId(id)) return Results.BadRequest(ErrorDto.Of("模型标识无效"));
|
||||
var ok = services.Models.Delete(id);
|
||||
if (ok) services.Models.NotifyChanged();
|
||||
return ok
|
||||
? Results.Ok(new LaunchResultDto(true, $"已删除模型 {id}"))
|
||||
: Results.NotFound(ErrorDto.Of($"没有找到模型 {id}"));
|
||||
});
|
||||
|
||||
// ---- 设置 -----------------------------------------------------------------
|
||||
|
||||
app.MapGet("/api/settings", () => Results.Ok(ToSettingsDto()));
|
||||
|
||||
app.MapPost("/api/settings", (SettingsPatch? patch) =>
|
||||
{
|
||||
if (patch == null) return Results.BadRequest(ErrorDto.Of("缺少设置内容"));
|
||||
|
||||
// 白名单校验:设置项会写进磁盘并被前端直接使用,不接受任意字符串。
|
||||
if (patch.Language != null && !allowedLanguages.Contains(patch.Language))
|
||||
return Results.BadRequest(ErrorDto.Of("不支持的界面语言"));
|
||||
if (patch.Theme != null && !allowedThemes.Contains(patch.Theme))
|
||||
return Results.BadRequest(ErrorDto.Of("不支持的主题"));
|
||||
if (patch.AccentColor != null && !accentHexRegex.IsMatch(patch.AccentColor))
|
||||
return Results.BadRequest(ErrorDto.Of("主题色需为 #RRGGBB"));
|
||||
if (patch.UpdateRepository != null && !IsAllowedRepository(patch.UpdateRepository))
|
||||
return Results.BadRequest(ErrorDto.Of("更新仓库地址不受信任"));
|
||||
|
||||
services.Settings.Apply(s =>
|
||||
{
|
||||
if (patch.Language != null) s.Language = patch.Language;
|
||||
if (patch.Theme != null) s.Theme = patch.Theme;
|
||||
if (patch.AccentColor != null) s.AccentColor = patch.AccentColor.ToUpperInvariant();
|
||||
if (patch.RenderFps.HasValue) s.RenderFps = Math.Clamp(patch.RenderFps.Value, 12, 120);
|
||||
if (patch.MemoryMb.HasValue) s.MemoryMb = Math.Clamp(patch.MemoryMb.Value, 256, 16384);
|
||||
if (patch.MemoryAuto.HasValue) s.MemoryAuto = patch.MemoryAuto.Value;
|
||||
if (patch.AutoUpdateOnStartup.HasValue) s.AutoUpdateOnStartup = patch.AutoUpdateOnStartup.Value;
|
||||
if (patch.RequireSignedManifest.HasValue) s.RequireSignedManifest = patch.RequireSignedManifest.Value;
|
||||
if (patch.UpdateRepository != null) s.UpdateRepository = patch.UpdateRepository;
|
||||
if (patch.UpdateLocalRoot != null) s.UpdateLocalRoot = patch.UpdateLocalRoot;
|
||||
if (patch.ModelRootOverride != null) s.ModelRootOverride = patch.ModelRootOverride;
|
||||
});
|
||||
|
||||
if (patch.Language != null) L.I.SetLanguage(patch.Language);
|
||||
if (patch.MemoryMb.HasValue || patch.MemoryAuto.HasValue)
|
||||
services.Memory.ApplyAuto(services.Settings.Current.MemoryAuto, services.Settings.Current.MemoryMb);
|
||||
|
||||
return Results.Ok(ToSettingsDto());
|
||||
});
|
||||
|
||||
// ---- 模型源 ---------------------------------------------------------------
|
||||
|
||||
app.MapGet("/api/sources", () =>
|
||||
Results.Ok(services.Settings.Current.Sources.Select(ToSourceDto).ToList()));
|
||||
|
||||
app.MapPost("/api/sources/select", async (ForceRequest? request) =>
|
||||
{
|
||||
var force = request?.Force ?? false;
|
||||
try
|
||||
{
|
||||
var fastest = await services.Selector.PickFastestAsync(force, CancellationToken.None);
|
||||
services.Updates.UseRemote(services.DownloadModule.CreateRemote(fastest));
|
||||
return Results.Ok(new LatencyDto(
|
||||
fastest.Id, fastest.Name,
|
||||
services.Selector.LastLatency.TryGetValue(fastest.Id, out var ms) ? ms : 0));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.Error.WriteLine($"[sources] 切换模型源失败: {ex}");
|
||||
return Results.Json(ErrorDto.Of("模型源切换失败"), statusCode: 503);
|
||||
}
|
||||
});
|
||||
|
||||
app.MapGet("/api/remote/models", async (string? sourceId, bool force) =>
|
||||
{
|
||||
var source = ResolveSource(sourceId);
|
||||
if (source == null) return Results.NotFound(ErrorDto.Of("没有可用的模型源"));
|
||||
|
||||
var index = await services.Sources.FetchAsync(source, force, null, CancellationToken.None);
|
||||
var installed = services.Models.Scan()
|
||||
.ToDictionary(p => p.Id, p => p.Manifest.Version, StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
return Results.Ok(new SourceIndexDto(
|
||||
index.SourceId,
|
||||
index.Root,
|
||||
index.FromCache,
|
||||
index.Error,
|
||||
index.ResolvedFrom,
|
||||
index.Models.Select(m => new RemoteModelDto(
|
||||
m.Id,
|
||||
m.LocalizedName,
|
||||
m.LocalizedDescription,
|
||||
m.Manifest.Version,
|
||||
m.SizeBytes,
|
||||
ModelScanner.HumanSize(m.SizeBytes),
|
||||
m.SourceId,
|
||||
installed.ContainsKey(m.Id),
|
||||
installed.TryGetValue(m.Id, out var v) ? v : null)).ToList()));
|
||||
});
|
||||
|
||||
// ---- 下载 -----------------------------------------------------------------
|
||||
|
||||
app.MapPost("/api/download", async (DownloadRequest? request) =>
|
||||
{
|
||||
if (request == null || string.IsNullOrWhiteSpace(request.ModelId))
|
||||
return Results.BadRequest(ErrorDto.Of("缺少 modelId"));
|
||||
|
||||
var source = ResolveSource(request.SourceId);
|
||||
if (source == null) return Results.NotFound(ErrorDto.Of("没有可用的模型源"));
|
||||
|
||||
var index = await services.Sources.FetchAsync(source, false, null, CancellationToken.None);
|
||||
var model = index.Models.FirstOrDefault(m =>
|
||||
m.Id.Equals(request.ModelId, StringComparison.OrdinalIgnoreCase));
|
||||
if (model == null)
|
||||
return Results.NotFound(ErrorDto.Of($"源里没有模型 {request.ModelId}"));
|
||||
|
||||
var job = services.Downloads.Enqueue(model);
|
||||
return Results.Ok(ToJobDto(job));
|
||||
});
|
||||
|
||||
app.MapGet("/api/download/jobs", () =>
|
||||
Results.Ok(services.Downloads.Jobs.Select(ToJobDto).ToList()));
|
||||
|
||||
app.MapPost("/api/download/{id}/cancel", (string id) =>
|
||||
ActOnJob(id, job => services.Downloads.Cancel(job)));
|
||||
|
||||
app.MapPost("/api/download/{id}/retry", (string id) =>
|
||||
ActOnJob(id, job => services.Downloads.Retry(job)));
|
||||
|
||||
app.MapPost("/api/download/{id}/remove", (string id) =>
|
||||
ActOnJob(id, job => services.Downloads.Remove(job)));
|
||||
|
||||
app.MapPost("/api/download/clear-finished", () =>
|
||||
{
|
||||
services.Downloads.ClearFinished();
|
||||
return Results.Ok(new LaunchResultDto(true, "已清除完成的任务"));
|
||||
});
|
||||
|
||||
// ---- 更新 -----------------------------------------------------------------
|
||||
|
||||
app.MapPost("/api/update/check", async (ForceRequest? request) =>
|
||||
{
|
||||
var force = request?.Force ?? true;
|
||||
var messages = new List<string>();
|
||||
|
||||
try
|
||||
{
|
||||
var fastest = await services.Selector.PickFastestAsync(force, CancellationToken.None);
|
||||
services.Updates.UseRemote(services.DownloadModule.CreateRemote(fastest));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.Error.WriteLine($"[update] 测速失败,沿用当前源: {ex.Message}");
|
||||
}
|
||||
|
||||
string? launcherLatest = null;
|
||||
try
|
||||
{
|
||||
launcherLatest = await services.LauncherUpdates.CheckAsync(
|
||||
services.Updates.Remote, CancellationToken.None);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.Error.WriteLine($"[update] 启动器版本检查失败: {ex.Message}");
|
||||
}
|
||||
|
||||
var progress = new Progress<UpdateProgress>(p =>
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(p.Message)) messages.Add(p.Message);
|
||||
});
|
||||
|
||||
var result = await services.Updates.RunAsync(force, progress, CancellationToken.None);
|
||||
|
||||
return Results.Ok(new UpdateCheckDto(
|
||||
result.Outcome.ToString(),
|
||||
result.Message,
|
||||
result.UpdatedModels,
|
||||
result.ModelNames,
|
||||
result.LauncherMessage,
|
||||
result.Error,
|
||||
launcherLatest,
|
||||
services.Updates.Remote.DisplayName,
|
||||
services.Selector.LastLatency
|
||||
.Select(kv => new LatencyDto(
|
||||
kv.Key,
|
||||
SourcePreset.Find(kv.Key)?.Name ?? kv.Key,
|
||||
kv.Value))
|
||||
.ToList()));
|
||||
});
|
||||
|
||||
// ---- 关于 -----------------------------------------------------------------
|
||||
|
||||
app.MapGet("/api/about", async () =>
|
||||
{
|
||||
var repository = services.Settings.Current.UpdateRepository;
|
||||
var contributors = new List<ContributorDto>();
|
||||
try
|
||||
{
|
||||
foreach (var c in await ContributorsService.FetchAsync(repository, CancellationToken.None))
|
||||
contributors.Add(new ContributorDto(c.DisplayName, c.Contributions, c.AvatarUrl));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.Error.WriteLine($"[about] 读取贡献者失败: {ex.Message}");
|
||||
}
|
||||
|
||||
return Results.Ok(new AboutDto(
|
||||
"Morris GC",
|
||||
LauncherRuntimeInfo.CurrentLauncherVersion,
|
||||
LauncherRuntimeInfo.CurrentRid,
|
||||
repository,
|
||||
contributors,
|
||||
// 「关于」页展示的技术栈信息:源码语言与前端框架。
|
||||
SourceLanguage: "C#",
|
||||
Frontend: "Flutter"));
|
||||
});
|
||||
|
||||
// ---- 系统集成 -------------------------------------------------------------
|
||||
|
||||
app.MapPost("/api/shell/open-folder", (PathRequest? request) =>
|
||||
{
|
||||
var path = request?.Path;
|
||||
if (string.IsNullOrWhiteSpace(path))
|
||||
return Results.BadRequest(ErrorDto.Of("缺少 path"));
|
||||
|
||||
// 只允许打开启动器自己的目录,避免前端被当成任意路径执行器
|
||||
if (!IsInsideKnownRoot(path!))
|
||||
return Results.BadRequest(ErrorDto.Of("只允许打开启动器自己的目录"));
|
||||
|
||||
Shell.OpenFolder(path!);
|
||||
return Results.Ok(new LaunchResultDto(true, "已打开目录"));
|
||||
});
|
||||
|
||||
app.MapPost("/api/shell/open-url", (UrlRequest? request) =>
|
||||
{
|
||||
var url = request?.Url;
|
||||
if (string.IsNullOrWhiteSpace(url) || url.Length > 2048 ||
|
||||
!Uri.TryCreate(url, UriKind.Absolute, out var uri))
|
||||
return Results.BadRequest(ErrorDto.Of("URL 无效"));
|
||||
|
||||
if (uri.Scheme != Uri.UriSchemeHttp && uri.Scheme != Uri.UriSchemeHttps)
|
||||
return Results.BadRequest(ErrorDto.Of("只允许 http/https 链接"));
|
||||
|
||||
if (!string.IsNullOrEmpty(uri.UserInfo))
|
||||
return Results.BadRequest(ErrorDto.Of("URL 不允许携带账号密码"));
|
||||
|
||||
Shell.OpenUrl(url!);
|
||||
return Results.Ok(new LaunchResultDto(true, "已打开链接"));
|
||||
});
|
||||
|
||||
// ---- 启动 -----------------------------------------------------------------
|
||||
|
||||
WriteEndpointFile(services, port);
|
||||
Console.WriteLine($"[GC-UI] 后端已启动: http://127.0.0.1:{port}");
|
||||
Console.WriteLine($"[GC-UI] 模型库: {services.Paths.ModelRoot}");
|
||||
|
||||
// 独立进程入口:`GC.UI.Server --port 17890`
|
||||
// 启动器在进程内直接调用 BackendServer.Start,不会走到这里。
|
||||
var app = BackendServer.StartFromCommandLine(args);
|
||||
app.Run();
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 局部辅助
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
static int ResolvePort(string[] args)
|
||||
{
|
||||
// 优先用启动器传来的端口(GC_UI_PORT),保证前端拼出来的 baseUrl 和这里一致。
|
||||
var env = Environment.GetEnvironmentVariable(GcUiContract.PortEnvVar);
|
||||
if (int.TryParse(env, out var fromEnv) && fromEnv > 0 && fromEnv < 65536) return fromEnv;
|
||||
|
||||
for (var i = 0; i < args.Length; i++)
|
||||
{
|
||||
if (args[i] == "--port" && i + 1 < args.Length &&
|
||||
int.TryParse(args[i + 1], out var next) && next > 0 && next < 65536)
|
||||
return next;
|
||||
|
||||
const string prefix = "--port=";
|
||||
if (args[i].StartsWith(prefix, StringComparison.Ordinal) &&
|
||||
int.TryParse(args[i][prefix.Length..], out var inline) && inline > 0 && inline < 65536)
|
||||
return inline;
|
||||
}
|
||||
|
||||
return GcUiContract.DefaultPort;
|
||||
}
|
||||
|
||||
static void WriteEndpointFile(AppServices services, int port)
|
||||
{
|
||||
try
|
||||
{
|
||||
var file = Path.Combine(services.Paths.HomeRoot, "ui-backend.json");
|
||||
var payload = JsonSerializer.Serialize(new
|
||||
{
|
||||
port,
|
||||
pid = Environment.ProcessId,
|
||||
url = $"http://127.0.0.1:{port}",
|
||||
version = LauncherRuntimeInfo.CurrentLauncherVersion,
|
||||
platform = LauncherRuntimeInfo.CurrentRid,
|
||||
startedAt = DateTimeOffset.UtcNow.ToString("o")
|
||||
}, new JsonSerializerOptions { WriteIndented = true });
|
||||
|
||||
File.WriteAllText(file, payload);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.Error.WriteLine($"[GC-UI] 写入端点文件失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>按扩展名推断图片 MIME;模型封面允许 png / jpg / webp / gif。</summary>
|
||||
static string GuessImageContentType(string path) => Path.GetExtension(path).ToLowerInvariant() switch
|
||||
{
|
||||
".jpg" or ".jpeg" => "image/jpeg",
|
||||
".webp" => "image/webp",
|
||||
".gif" => "image/gif",
|
||||
".bmp" => "image/bmp",
|
||||
".svg" => "image/svg+xml",
|
||||
_ => "image/png"
|
||||
};
|
||||
|
||||
ModelDto ToModelDto(ModelPackage package) => new( package.Id,
|
||||
package.LocalizedName,
|
||||
package.LocalizedDescription,
|
||||
package.Manifest.Version,
|
||||
package.Manifest.Author,
|
||||
package.SizeBytes,
|
||||
ModelScanner.HumanSize(package.SizeBytes),
|
||||
package.Manifest.Tags ?? new List<string>(),
|
||||
File.Exists(package.PreviewPath),
|
||||
$"/api/models/{package.Id}/preview",
|
||||
package.Directory,
|
||||
package.DataDirectory);
|
||||
|
||||
SourceDto ToSourceDto(ModelSource source) => new(
|
||||
source.Id,
|
||||
string.IsNullOrWhiteSpace(source.Name) ? source.Id : source.Name,
|
||||
source.Url,
|
||||
source.Enabled,
|
||||
source.BuiltIn,
|
||||
source.DisplayHost);
|
||||
|
||||
SettingsDto ToSettingsDto() => new(
|
||||
services.Settings.Current.Language,
|
||||
services.Settings.Current.Theme,
|
||||
services.Settings.Current.AccentColor,
|
||||
services.Settings.Current.RenderFps,
|
||||
services.Settings.Current.MemoryMb,
|
||||
services.Settings.Current.MemoryAuto,
|
||||
services.Settings.Current.AutoUpdateOnStartup,
|
||||
services.Settings.Current.RequireSignedManifest,
|
||||
services.Settings.Current.UpdateRepository,
|
||||
services.Settings.Current.UpdateLocalRoot,
|
||||
services.Settings.Current.ModelRootOverride,
|
||||
services.Memory.BudgetMb,
|
||||
services.Memory.UsageText,
|
||||
services.Paths.ModelRoot,
|
||||
services.Paths.DataRoot,
|
||||
services.Paths.SettingsFile,
|
||||
LauncherRuntimeInfo.CurrentLauncherVersion,
|
||||
LauncherRuntimeInfo.CurrentRid,
|
||||
services.Settings.Current.Sources.Select(ToSourceDto).ToList(),
|
||||
L.Supported.Select(s => new LanguageDto(s.Code, s.Label)).ToList());
|
||||
|
||||
JobDto ToJobDto(IDownloadJob job) => new(
|
||||
job.Id,
|
||||
job.Model.Id,
|
||||
job.Name,
|
||||
job.Version,
|
||||
job.State.ToString(),
|
||||
job.Progress,
|
||||
job.StatusText,
|
||||
job.DetailText,
|
||||
job.Error,
|
||||
job.IsActive,
|
||||
job.CanRetry,
|
||||
job.IsDone);
|
||||
|
||||
ModelSource? ResolveSource(string? sourceId)
|
||||
{
|
||||
var sources = services.Settings.Current.Sources;
|
||||
if (!string.IsNullOrWhiteSpace(sourceId))
|
||||
{
|
||||
var exact = sources.FirstOrDefault(s =>
|
||||
s.Id.Equals(sourceId, StringComparison.OrdinalIgnoreCase));
|
||||
if (exact != null) return exact;
|
||||
}
|
||||
|
||||
return sources.FirstOrDefault(s => s.Enabled && !string.IsNullOrWhiteSpace(s.Url))
|
||||
?? sources.FirstOrDefault();
|
||||
}
|
||||
|
||||
IResult ActOnJob(string id, Action<IDownloadJob> action)
|
||||
{
|
||||
if (!IsSafeId(id)) return Results.BadRequest(ErrorDto.Of("任务标识无效"));
|
||||
var job = services.Downloads.Jobs.FirstOrDefault(j =>
|
||||
j.Id.Equals(id, StringComparison.OrdinalIgnoreCase));
|
||||
if (job == null) return Results.NotFound(ErrorDto.Of($"没有找到任务 {id}"));
|
||||
|
||||
action(job);
|
||||
return Results.Ok(ToJobDto(job));
|
||||
}
|
||||
|
||||
bool IsInsideKnownRoot(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
var full = Path.GetFullPath(path);
|
||||
var roots = new[]
|
||||
{
|
||||
services.Paths.ModelRoot,
|
||||
services.Paths.DataRoot,
|
||||
services.Paths.HomeRoot,
|
||||
services.Paths.AppRoot
|
||||
};
|
||||
|
||||
foreach (var root in roots)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(root)) continue;
|
||||
var rootFull = Path.GetFullPath(root);
|
||||
if (full.Equals(rootFull, StringComparison.OrdinalIgnoreCase)) return true;
|
||||
if (full.StartsWith(rootFull + Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// 路由标识:只允许字母数字开头,后接字母数字/点/下划线/短横线,长度上限 64。
|
||||
// 用于模型 id、任务 id,杜绝 `../` 之类的路径穿越尝试。
|
||||
bool IsSafeId(string? id) => !string.IsNullOrEmpty(id) && safeIdRegex.IsMatch(id);
|
||||
|
||||
// 更新仓库地址:必须是 https、不带账号密码、不是回环/内网 IP。
|
||||
// 防止把本地后端当成 SSRF 跳板去访问内网服务。
|
||||
bool IsAllowedRepository(string value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value)) return false;
|
||||
if (!Uri.TryCreate(value, UriKind.Absolute, out var uri)) return false;
|
||||
if (uri.Scheme != Uri.UriSchemeHttps) return false;
|
||||
if (!string.IsNullOrEmpty(uri.UserInfo)) return false;
|
||||
if (string.Equals(uri.Host, "localhost", StringComparison.OrdinalIgnoreCase)) return false;
|
||||
if (System.Net.IPAddress.TryParse(uri.Host, out var ip) &&
|
||||
(System.Net.IPAddress.IsLoopback(ip) || IsPrivateAddress(ip)))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool IsPrivateAddress(System.Net.IPAddress ip)
|
||||
{
|
||||
var bytes = ip.GetAddressBytes();
|
||||
if (bytes.Length != 4) return false;
|
||||
return bytes[0] == 10
|
||||
|| (bytes[0] == 172 && bytes[1] >= 16 && bytes[1] <= 31)
|
||||
|| (bytes[0] == 192 && bytes[1] == 168)
|
||||
|| (bytes[0] == 169 && bytes[1] == 254);
|
||||
}
|
||||
@@ -10,11 +10,12 @@ namespace GC.Services;
|
||||
/// <安装目录>/
|
||||
/// GCL(.exe | .app/...)
|
||||
/// .GC/
|
||||
/// settings.json 设置与已安装版本记录
|
||||
/// bin/ 非本体文件(守护进程等,随包分发,更新时整目录替换)
|
||||
/// config/ 设置与已安装版本记录(settings.json)
|
||||
/// model/ 模型(启动时下载)
|
||||
/// cache/ 下载缓存 / 原子替换暂存
|
||||
/// update/ 待下次启动应用的启动器更新包
|
||||
/// safedog/ 更新守护进程(首次启动从安装包复制过来)
|
||||
/// safedog/ 更新守护进程的运行副本(首次启动从 .GC/bin 复制过来)
|
||||
/// logs/ 日志,按天分中英两份:gc-YYYYMMDD.log / .en.log
|
||||
/// </code>
|
||||
/// 开发态同样使用仓库根 .GC/model,并自动同步仓库 model/ 的可分发部分。
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace GC.Services;
|
||||
/// 运行期目录准备:
|
||||
/// <list type="number">
|
||||
/// <item>创建 <c>.GC/logs</c> 与 <c>.GC/safedog</c>;</item>
|
||||
/// <item>把安装包里的守护进程复制到 <c>.GC/safedog</c>(程序本体与用户数据分开);</item>
|
||||
/// <item>把包内 <c>.GC/bin</c> 里的守护进程复制到 <c>.GC/safedog</c>(非本体文件不散落在安装目录);</item>
|
||||
/// <item>初始化双语日志并写一条启动记录。</item>
|
||||
/// </list>
|
||||
///
|
||||
@@ -36,7 +36,7 @@ public static class RuntimeLayout
|
||||
return safedog;
|
||||
}
|
||||
|
||||
/// <summary>把包内守护进程同步到 <c>.GC/safedog</c>。已是最新则不动。</summary>
|
||||
/// <summary>把包内 <c>.GC/bin</c> 的守护进程同步到 <c>.GC/safedog</c>。已是最新则不动。</summary>
|
||||
private static string? InstallSafedog(AppPaths paths)
|
||||
{
|
||||
var name = SavedogFiles.ExecutableName;
|
||||
@@ -64,10 +64,14 @@ public static class RuntimeLayout
|
||||
|
||||
private static string? FindPackaged(AppPaths paths, string name)
|
||||
{
|
||||
// 包内非本体文件统一收在 .GC/bin;后面几项兼容 1.0.10 及更早的包布局
|
||||
var candidates = new[]
|
||||
{
|
||||
Path.Combine(paths.HomeRoot, "bin", name),
|
||||
Path.Combine(paths.InstallDirectory, ".GC", "bin", name),
|
||||
Path.Combine(paths.InstallDirectory, "safedog", name),
|
||||
Path.Combine(paths.InstallDirectory, name),
|
||||
Path.Combine(paths.AppRoot, ".GC", "bin", name),
|
||||
Path.Combine(paths.AppRoot, "safedog", name),
|
||||
Path.Combine(paths.AppRoot, name),
|
||||
};
|
||||
|
||||
@@ -59,23 +59,35 @@ Windows 用 `.\build.ps1`,参数相同(`build / check / models / stamp / run
|
||||
## 运行目录(发布包里就长这样)
|
||||
|
||||
```
|
||||
<解压出来的目录>/ ← 压缩包里只有这一个文件夹
|
||||
GCL-<版本>-<平台>(.exe | .app/) 启动器
|
||||
GC-UI(.exe) Flutter 前端
|
||||
safedog/GC-SAVEDOG[.exe] 更新守护进程(运行时复制到 .GC/safedog)
|
||||
data/ lib/ *.dll 后端与 Flutter 运行时
|
||||
.GC/ 首次启动自动生成
|
||||
config/settings.json 用户设置(与缓存分开:删 cache 不会丢配置)
|
||||
model/ 启动时下载的模型
|
||||
cache/ 下载暂存 / 原子替换
|
||||
update/ 待应用的启动器更新(apply-request.json + package.zip)
|
||||
safedog/GC-SAVEDOG[.exe] 实际运行的守护进程(不随整目录替换被覆盖)
|
||||
logs/gc-YYYYMMDD.log 日志(中文)
|
||||
logs/gc-YYYYMMDD.en.log 日志(English)
|
||||
<解压出来的目录>/ ← 压缩包里只有这一个文件夹
|
||||
GCL-<版本>-<平台>.exe 启动器(单文件:服务层 + 本地后端 + .NET 运行时都在里面)
|
||||
GC-UI.exe Flutter 前端
|
||||
flutter_windows.dll Flutter 引擎(引擎自带,不在 .NET 单文件里)
|
||||
data/app.so, data/flutter_assets/ Flutter 资源与 AOT 快照
|
||||
.GC/bin/GC-SAVEDOG[.exe] 非本体文件:更新守护进程
|
||||
```
|
||||
|
||||
压缩包内只有一个顶层目录,解压后不会散落一屏 dll;主程序、后端、前端、守护进程都在
|
||||
这个目录里。`.GC` 紧挨着主程序,装在哪都便携 —— 整个目录复制走,模型、设置、日志跟着走。
|
||||
就这些,没有一屏 dll。安装目录根只放 GC 本体,非本体文件(守护进程)一律收在 `.GC/bin`。
|
||||
macOS 是同一个单文件启动器,只是被放进 `GCL-<版本>-mac-arm64.app/Contents/MacOS/`,
|
||||
Flutter 前端作为 `GC-UI.app` 放在同一层。
|
||||
|
||||
首次启动后 `.GC` 补齐成:
|
||||
|
||||
```
|
||||
.GC/
|
||||
bin/ 非本体文件(随包分发,更新时按文件替换)
|
||||
config/settings.json 用户设置(与缓存分开:删 cache 不会丢配置)
|
||||
model/ 启动时下载的模型
|
||||
cache/ 下载暂存 / 原子替换
|
||||
update/ 待应用的启动器更新(apply-request.json + package.zip)
|
||||
safedog/GC-SAVEDOG[.exe] 守护进程的运行副本(首次启动从 .GC/bin 复制)
|
||||
logs/gc-YYYYMMDD.log 日志(中文)
|
||||
logs/gc-YYYYMMDD.en.log 日志(English)
|
||||
```
|
||||
|
||||
`.GC` 紧挨着主程序,装在哪都便携 —— 整个目录复制走,模型、设置、日志跟着走。
|
||||
守护进程「`.GC/bin` 放源、`.GC/safedog` 放运行副本」是因为更新要整目录替换:
|
||||
正在运行的 exe 在 Windows 上换不掉,所以跑副本、换源文件,下次启动再同步。
|
||||
|
||||
**发布包不含任何模型**。首次启动联网检查后把模型下载到 `.GC/model/` 并立刻显示;
|
||||
安装目录不可写时自动退回用户数据目录。`.GC/cache` 与 `.GC/model` 随时可删,程序会重新下载;
|
||||
@@ -93,7 +105,8 @@ Windows 用 `.\build.ps1`,参数相同(`build / check / models / stamp / run
|
||||
```
|
||||
启动器下载 zip -> 校验 sha256 -> 写 apply-request.json -> 启动 .GC/safedog/GC-SAVEDOG -> 自己退出
|
||||
GC-SAVEDOG: 二次验签 -> 检查 zip 安全性 -> 解压到 .GC/update/stage
|
||||
-> 整目录替换:旧文件搬到 .GC/update/backup,新文件就位(保留 .GC 不动)
|
||||
-> 整目录替换:旧文件搬到 .GC/update/backup,新文件就位
|
||||
(.GC 只合并 bin/,config/model/cache/update/logs/safedog 原地不动)
|
||||
-> 启动新版,等 .GC/update/health.json
|
||||
-> 收到:删备份、写 last-good.json
|
||||
-> 没收到/进程退出:撤掉新文件、把备份搬回、重启旧版,写 state.json = rolledback
|
||||
@@ -253,9 +266,9 @@ Repository/
|
||||
| 产物 | 平台 |
|
||||
| --- | --- |
|
||||
| `dist/mac-arm64/GCL-<版本>-mac-arm64.zip` | macOS Apple Silicon(单顶层 `GCL-….app`) |
|
||||
| `dist/win-amd64/GCL-<版本>-win-amd64.zip` | Windows x64(单顶层 `GCL-…/`,含 Flutter 前端与 `safedog/`) |
|
||||
| `dist/win-amd64/GCL-<版本>-win-amd64.zip` | Windows x64(单顶层 `GCL-…/`,含 Flutter 前端,非本体文件在 `.GC/bin/`) |
|
||||
| `dist/win-arm64/GCL-<版本>-win-arm64.zip` | Windows on ARM 同上 |
|
||||
| `dist/linux-arm64/GCL-<版本>-linux-arm64.zip` | Linux ARM64 同上(启动器无扩展名,需在 aarch64 主机构建) |
|
||||
| `dist/linux-arm64/GCL-<版本>-linux-arm64.zip` | Linux ARM64 同上(启动器无扩展名;默认不构建,需 aarch64 主机 + `GC_BUILD_LINUX=1`) |
|
||||
|
||||
平台目录就是「该平台的编译产物目录」:打包完成后只留最终 zip(原始 `.app` / `.exe`
|
||||
会被挪到 `build/trash/`,下次构建时移出,不做递归删除)。
|
||||
|
||||
+24
-18
@@ -3,7 +3,10 @@
|
||||
#
|
||||
# 目标平台按构建主机决定,每条产物都带 Flutter 前端:
|
||||
# macOS 主机 : mac-arm64(原生)+ win-amd64 / win-arm64(mingw 交叉)
|
||||
# Linux 主机 : linux-arm64(原生 / 交叉)+ win-amd64 / win-arm64(mingw 交叉)
|
||||
# Linux 主机 : win-amd64 / win-arm64(mingw 交叉)
|
||||
# Linux 产物默认不构建:目标为 linux-arm64,官方 Flutter 引擎只有
|
||||
# x64 产物,必须在 aarch64 主机上编。需要时用 GC_BUILD_LINUX=1 显式开启
|
||||
# (云端 aarch64 runner 就是这么用的)。
|
||||
# Windows 主机: win-amd64 / win-arm64(原生)
|
||||
#
|
||||
# 前端是默认必需项:flutter 缺失或编译失败一律中断,不再悄悄产出只带 Avalonia
|
||||
@@ -23,16 +26,24 @@ bs_build() {
|
||||
MINGW*|MSYS*|CYGWIN*) : ;; # Windows 主机只能编 Windows
|
||||
*) BUILD_LINUX=1 ;;
|
||||
esac
|
||||
# Linux 目标已切成 arm64:Flutter 的 Linux 前端必须用 aarch64 主机自带的
|
||||
# engine 产物(官方只发 x64 版),x64 主机上强行编出来的是 x64 二进制,
|
||||
# 装到 arm 机器上跑不起来。这里直接跳过,并说明原因,不当成构建失败。
|
||||
# Linux 产物默认不出:目标平台是 linux-arm64,而官方 Flutter 引擎只发 x64 产物,
|
||||
# x64 主机上编出来的是 x64 二进制,装到 arm 机器上跑不起来。
|
||||
# 需要时显式开启(云端 aarch64 runner):GC_BUILD_LINUX=1 ./build.sh build
|
||||
if [ "$BUILD_LINUX" = 1 ]; then
|
||||
case "$(uname -m)" in
|
||||
aarch64|arm64) ;;
|
||||
case "${GC_BUILD_LINUX:-0}" in
|
||||
1|true|yes)
|
||||
case "$(uname -m)" in
|
||||
aarch64|arm64) ;;
|
||||
*)
|
||||
BUILD_LINUX=0
|
||||
echo "!! 已请求 Linux 产物,但当前主机是 $(uname -m)"
|
||||
echo " (linux-arm64 需要有 aarch64 主机,Flutter 引擎只有 x64 官方产物)"
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
*)
|
||||
BUILD_LINUX=0
|
||||
echo "!! 跳过 Linux 产物:目标为 linux-arm64,当前主机是 $(uname -m)"
|
||||
echo " (Flutter Linux 引擎只有 x64 官方产物,需在 aarch64 主机上构建)"
|
||||
echo "==> 跳过 Linux 产物(默认不构建;需要时用 GC_BUILD_LINUX=1 显式开启)"
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
@@ -81,8 +92,7 @@ bs_build() {
|
||||
|
||||
if [ "$BUILD_MAC" = 1 ]; then
|
||||
progress_step "编译 Mac"
|
||||
_run_publish mac 90 publish_rid "osx-arm64" "dist/mac-arm64" false || return 1
|
||||
publish_backend "osx-arm64" "dist/mac-arm64" || return 1
|
||||
_run_publish mac 90 publish_rid "osx-arm64" "dist/mac-arm64" true || return 1
|
||||
# Flutter 的 macOS 产物必须用 Xcode 在本机编,Linux 上无法替代
|
||||
build_flutter_ui macos "dist/mac-arm64" || {
|
||||
echo "!! macOS 前端编译失败。macOS 版 Flutter 只能在 macOS 上编。"
|
||||
@@ -90,23 +100,19 @@ bs_build() {
|
||||
}
|
||||
elif [ "$ALLOW_NO_UI" = 1 ]; then
|
||||
progress_step "编译 Mac"
|
||||
_run_publish mac 90 publish_rid "osx-arm64" "dist/mac-arm64" false || return 1
|
||||
publish_backend "osx-arm64" "dist/mac-arm64" || return 1
|
||||
_run_publish mac 90 publish_rid "osx-arm64" "dist/mac-arm64" true || return 1
|
||||
echo "!! --allow-no-ui:macOS 包内不含 Flutter 前端,启动器将回退 Avalonia"
|
||||
fi
|
||||
|
||||
progress_step "编译 Win-x64"
|
||||
_run_publish winx64 70 publish_rid "win-x64" "dist/win-amd64" false || return 1
|
||||
publish_backend "win-x64" "dist/win-amd64" || return 1
|
||||
_run_publish winx64 70 publish_rid "win-x64" "dist/win-amd64" true || return 1
|
||||
|
||||
progress_step "编译 Win-arm64"
|
||||
_run_publish winarm 70 publish_rid "win-arm64" "dist/win-arm64" false || return 1
|
||||
publish_backend "win-arm64" "dist/win-arm64" || return 1
|
||||
_run_publish winarm 70 publish_rid "win-arm64" "dist/win-arm64" true || return 1
|
||||
|
||||
if [ "$BUILD_LINUX" = 1 ]; then
|
||||
progress_step "编译 Linux"
|
||||
_run_publish linux 70 publish_rid "linux-arm64" "dist/linux-arm64" false || return 1
|
||||
publish_backend "linux-arm64" "dist/linux-arm64" || return 1
|
||||
_run_publish linux 70 publish_rid "linux-arm64" "dist/linux-arm64" true || return 1
|
||||
build_flutter_ui linux "dist/linux-arm64" || return 1
|
||||
fi
|
||||
|
||||
|
||||
+64
-46
@@ -65,48 +65,56 @@ build_models() {
|
||||
stamp_versions
|
||||
}
|
||||
|
||||
# 发布目录只放启动器 + 空的 .GC 运行骨架,绝不放模型
|
||||
# 发布目录只放程序本体:不预置 .GC,也不放模型。
|
||||
# .GC(config / model / cache / update / safedog / logs)一律在首次启动时
|
||||
# 由 AppPaths.EnsureCreated + RuntimeLayout 创建,压缩包里只有 GC 本体。
|
||||
prepare_runtime_layout() {
|
||||
REL="$1"
|
||||
DEST="$ROOT_DIR/$REL"
|
||||
[ -d "$DEST" ] || return 0
|
||||
rm -rf "$DEST/model" "$DEST/examples"
|
||||
mkdir -p "$DEST/.GC/model" "$DEST/.GC/cache" "$DEST/.GC/update" "$DEST/.GC/config"
|
||||
cat > "$DEST/.GC/model/README.txt" <<'TXT'
|
||||
模型库目录(.GC/model/)
|
||||
启动时程序会读取 GitCode 仓库的 version.json,把最新版模型下载到这里。
|
||||
离线使用也可以手动放入 <模型id>/<模型id>.json + <模型id>/<模型id>.model/。
|
||||
|
||||
运行目录:
|
||||
<可执行文件>
|
||||
GC-SAVEDOG 更新守护进程(验签 + 原子替换 + 失败回滚)
|
||||
.GC/config/settings.json 用户设置(删 .GC/cache 不会丢配置)
|
||||
.GC/model/ 本目录(下载的模型)
|
||||
.GC/cache/ 下载暂存
|
||||
.GC/update/ 待下次启动应用的启动器更新
|
||||
TXT
|
||||
if [ ! -f "$DEST/.GC/config/settings.json" ]; then
|
||||
cat > "$DEST/.GC/config/settings.json" <<'JSON'
|
||||
{
|
||||
"language": "auto",
|
||||
"theme": "light",
|
||||
"renderFps": 30,
|
||||
"memoryMb": 2048,
|
||||
"autoUpdateOnStartup": true,
|
||||
"requireSignedManifest": true,
|
||||
"updateRepository": "https://git.xhmcl.com/Morris/GC",
|
||||
"updateManifestUrl": "",
|
||||
"updateLocalRoot": "",
|
||||
"installedModelVersions": {},
|
||||
"launcherVersion": "",
|
||||
"pendingLauncherVersion": "",
|
||||
"lastUpdateCheck": "",
|
||||
"sources": [],
|
||||
"recentModels": []
|
||||
rm -rf "$DEST/model" "$DEST/examples" "$DEST/.GC"
|
||||
echo " 运行目录 -> $REL(首次启动后生成 .GC/:config model cache update safedog logs)"
|
||||
}
|
||||
JSON
|
||||
fi
|
||||
echo " 运行目录 -> $REL/.GC (config/settings.json + model/ + cache/ + update/)"
|
||||
|
||||
# 剔除与目标平台无关 / 只在调试诊断时才会加载的组件。
|
||||
# 判定依据:Windows 包用 Kestrel 自托管,不经过 IIS/HttpSys;Avalonia 在 Windows
|
||||
# 上只用 Win32 后端;DAC/DBI/DiaSymReader 只有调试器与读 PDB 时才需要,
|
||||
# 而发布包 DebugType=none、不带 PDB。全都不在启动与正常运行路径上。
|
||||
prune_package() {
|
||||
DEST="$1"; PLAT="$2"
|
||||
[ -d "$DEST" ] || return 0
|
||||
case "$PLAT" in
|
||||
win)
|
||||
# ProjectReference 会把后端 exe 的 runtimeconfig 一起拷过来;后端已编入启动器,
|
||||
# 这些残留没有用。
|
||||
rm -f "$DEST"/GC.UI.Server.exe "$DEST"/GC.UI.Server.dll \
|
||||
"$DEST"/GC.UI.Server.deps.json "$DEST"/GC.UI.Server.runtimeconfig.json
|
||||
rm -f "$DEST"/mscordaccore*.dll \
|
||||
"$DEST"/mscordbi.dll \
|
||||
"$DEST"/Microsoft.DiaSymReader.Native*.dll \
|
||||
"$DEST"/web.config \
|
||||
"$DEST"/aspnetcorev2_inprocess.dll \
|
||||
"$DEST"/Microsoft.AspNetCore.Server.IIS.dll \
|
||||
"$DEST"/Microsoft.AspNetCore.Server.IISIntegration.dll \
|
||||
"$DEST"/Microsoft.AspNetCore.Server.HttpSys.dll \
|
||||
"$DEST"/Avalonia.X11.dll \
|
||||
"$DEST"/Avalonia.Native.dll \
|
||||
"$DEST"/Avalonia.FreeDesktop.dll \
|
||||
"$DEST"/Tmds.DBus.Protocol.dll
|
||||
;;
|
||||
linux)
|
||||
rm -f "$DEST"/mscordaccore*.dll \
|
||||
"$DEST"/mscordbi.dll \
|
||||
"$DEST"/Microsoft.DiaSymReader.Native*.dll \
|
||||
"$DEST"/web.config \
|
||||
"$DEST"/aspnetcorev2_inprocess.dll \
|
||||
"$DEST"/Microsoft.AspNetCore.Server.IIS.dll \
|
||||
"$DEST"/Microsoft.AspNetCore.Server.IISIntegration.dll \
|
||||
"$DEST"/Microsoft.AspNetCore.Server.HttpSys.dll \
|
||||
"$DEST"/Avalonia.Win32.dll \
|
||||
"$DEST"/Avalonia.Win32.Automation.dll
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# $1=RID $2=输出目录 $3=singlefile(true/false)
|
||||
@@ -124,15 +132,18 @@ publish_rid() {
|
||||
-p:DebugType=none \
|
||||
-p:PublishSingleFile="$SINGLE" \
|
||||
-p:IncludeNativeLibrariesForSelfExtract="$SINGLE" \
|
||||
-p:EnableCompressionInSingleFile="$SINGLE" \
|
||||
-p:PublishTrimmed=false \
|
||||
-o "$ROOT_DIR/$OUT"
|
||||
-o "$ROOT_DIR/$OUT" || return 1
|
||||
|
||||
# 更新守护进程:与主程序同目录(macOS 打包时会被一起移入 Contents/MacOS)
|
||||
if [ -n "${SAVEDOG_PROJ:-}" ] && [ -f "$ROOT_DIR/$SAVEDOG_PROJ" ]; then
|
||||
echo "==> 编译 GC-SAVEDOG (${RID}) -> ${OUT}(裁剪单文件)"
|
||||
echo "==> 编译 GC-SAVEDOG (${RID}) -> ${OUT}(裁剪 + 压缩单文件)"
|
||||
# 守护进程不引用 Avalonia,可以安全裁剪:70MB -> 14MB。
|
||||
# 前提是 JSON 全部走源生成上下文(GC-SAVEDOG/SavedogJson.cs),新增 JSON 类型
|
||||
# 忘了注册只会在发布产物里炸,所以 update-test 会跑一次真实 apply 兜底。
|
||||
# EnableCompressionInSingleFile:运行时不常驻,启动时解压一次即可,
|
||||
# 换来包内少 4MB 左右,对「下载一次、只在更新时跑」的守护进程很划算。
|
||||
dotnet publish "$SAVEDOG_PROJ" \
|
||||
-c Release \
|
||||
-r "$RID" \
|
||||
@@ -141,6 +152,7 @@ publish_rid() {
|
||||
-p:DebugType=none \
|
||||
-p:PublishSingleFile=true \
|
||||
-p:IncludeNativeLibrariesForSelfExtract=true \
|
||||
-p:EnableCompressionInSingleFile=true \
|
||||
-p:PublishTrimmed=true \
|
||||
-p:TrimMode=full \
|
||||
-p:JsonSerializerIsReflectionEnabledByDefault=false \
|
||||
@@ -161,7 +173,8 @@ pack_models() {
|
||||
du -sh "$ZIP"
|
||||
}
|
||||
|
||||
# 启动器更新包:只包含程序文件,排除 .GC(否则会覆盖用户已下载的模型与设置)
|
||||
# 启动器更新包:安装目录根只放 GC 本体;非本体文件(守护进程等)收进 .GC/bin。
|
||||
# .GC 下的用户数据(config / model / cache / update / logs / safedog)不进包。
|
||||
#
|
||||
# 产物落点遵循「仓库 dist/<系统>-<架构>/」布局:
|
||||
# dist/mac-arm64/GCL-<版本>-mac-arm64.zip
|
||||
@@ -186,7 +199,9 @@ publish_backend() {
|
||||
--self-contained true \
|
||||
-p:Version="$VERSION" \
|
||||
-p:DebugType=none \
|
||||
-p:PublishSingleFile=false \
|
||||
-p:PublishSingleFile=true \
|
||||
-p:IncludeNativeLibrariesForSelfExtract=true \
|
||||
-p:EnableCompressionInSingleFile=true \
|
||||
-p:PublishTrimmed=false \
|
||||
-o "$ROOT_DIR/$OUT" || return 1
|
||||
}
|
||||
@@ -307,14 +322,16 @@ pack_launcher() {
|
||||
rm -rf "$TMP"; mkdir -p "$PKG"
|
||||
cp -R "$SRC"/. "$PKG"/
|
||||
rm -f "$PKG"/*.zip
|
||||
prune_package "$PKG" win
|
||||
mv "$PKG/$(basename "$EXE")" "$PKG/$PKGNAME.exe"
|
||||
chmod +x "$PKG/$PKGNAME.exe" 2>/dev/null || true
|
||||
if [ ! -f "$PKG/GC-SAVEDOG.exe" ]; then
|
||||
echo " !! 缺少 GC-SAVEDOG.exe,该平台将退回旧脚本更新"
|
||||
else
|
||||
# 守护进程放 safedog/:首次启动复制到 .GC/safedog,更新替换不再动它
|
||||
mkdir -p "$PKG/safedog"
|
||||
mv "$PKG/GC-SAVEDOG.exe" "$PKG/safedog/"
|
||||
# 非本体文件统一收进 .GC/bin:安装目录根只留 GC 本体。
|
||||
# 首次启动复制到 .GC/safedog 再运行,所以这里的源文件更新时可安全替换。
|
||||
mkdir -p "$PKG/.GC/bin"
|
||||
mv "$PKG/GC-SAVEDOG.exe" "$PKG/.GC/bin/"
|
||||
fi
|
||||
if [ ! -f "$PKG/GC-UI.exe" ]; then
|
||||
echo " !! 包内没有 Flutter 前端,启动器将使用内置 Avalonia 界面"
|
||||
@@ -336,13 +353,14 @@ pack_launcher() {
|
||||
rm -rf "$TMP"; mkdir -p "$PKG"
|
||||
cp -R "$SRC"/. "$PKG"/
|
||||
rm -f "$PKG"/*.zip
|
||||
prune_package "$PKG" linux
|
||||
if [ -f "$PKG/GC" ]; then
|
||||
mv "$PKG/GC" "$PKG/$PKGNAME"
|
||||
chmod +x "$PKG/$PKGNAME" 2>/dev/null || true
|
||||
fi
|
||||
if [ -f "$PKG/GC-SAVEDOG" ]; then
|
||||
mkdir -p "$PKG/safedog"
|
||||
mv "$PKG/GC-SAVEDOG" "$PKG/safedog/"
|
||||
mkdir -p "$PKG/.GC/bin"
|
||||
mv "$PKG/GC-SAVEDOG" "$PKG/.GC/bin/"
|
||||
fi
|
||||
if [ ! -f "$PKG/GC-UI" ]; then
|
||||
echo " !! 包内没有 Flutter 前端,启动器将使用内置 Avalonia 界面"
|
||||
|
||||
+29
-29
@@ -1,46 +1,46 @@
|
||||
{
|
||||
"schema": 1,
|
||||
"generated": "2026-11-18T12:37:25Z",
|
||||
"generated": "2026-11-18T13:05:57Z",
|
||||
"repository": "https://git.xhmcl.com/Morris/GC",
|
||||
"branch": "main",
|
||||
"modelDir": "model",
|
||||
"launcher": {
|
||||
"version": "1.0.10",
|
||||
"version": "1.0.11",
|
||||
"revision": "",
|
||||
"packages": {
|
||||
"win-x64": {
|
||||
"path": "dist/win-amd64/GCL-1.0.10-win-amd64.zip",
|
||||
"path": "dist/win-amd64/GCL-1.0.11-win-amd64.zip",
|
||||
"dir": "dist/win-amd64",
|
||||
"name": "GCL-1.0.10-win-amd64.zip",
|
||||
"url": "https://git.xhmcl.com/Morris/GC/releases/download/1.0.10/GCL-1.0.10-win-amd64.zip",
|
||||
"sha256": "ace717e9a96704c0f51420fc7ee23af01405c239cf9e039352d9864d7fe513b8",
|
||||
"size": 74323474
|
||||
"name": "GCL-1.0.11-win-amd64.zip",
|
||||
"url": "https://git.xhmcl.com/Morris/GC/releases/download/1.0.11/GCL-1.0.11-win-amd64.zip",
|
||||
"sha256": "55f1d5eb0dfdfc243656e6705c3d276dd83611561f913fe5ca9e6e5d2f2dd658",
|
||||
"size": 74973271
|
||||
},
|
||||
"win-arm64": {
|
||||
"path": "dist/win-arm64/GCL-1.0.10-win-arm64.zip",
|
||||
"path": "dist/win-arm64/GCL-1.0.11-win-arm64.zip",
|
||||
"dir": "dist/win-arm64",
|
||||
"name": "GCL-1.0.10-win-arm64.zip",
|
||||
"url": "https://git.xhmcl.com/Morris/GC/releases/download/1.0.10/GCL-1.0.10-win-arm64.zip",
|
||||
"sha256": "af1337e0ad110ca408141477d17cb33e9a3ea187909d94c5425086d6215ea651",
|
||||
"size": 72068324
|
||||
"name": "GCL-1.0.11-win-arm64.zip",
|
||||
"url": "https://git.xhmcl.com/Morris/GC/releases/download/1.0.11/GCL-1.0.11-win-arm64.zip",
|
||||
"sha256": "9ce48381fcca18e7d6789364e1c43f7e616ceae529c0c1167b099ed762f5808f",
|
||||
"size": 72515856
|
||||
},
|
||||
"osx-arm64": {
|
||||
"path": "dist/mac-arm64/GCL-1.0.10-mac-arm64.zip",
|
||||
"path": "dist/mac-arm64/GCL-1.0.11-mac-arm64.zip",
|
||||
"dir": "dist/mac-arm64",
|
||||
"name": "GCL-1.0.10-mac-arm64.zip",
|
||||
"url": "https://git.xhmcl.com/Morris/GC/releases/download/1.0.10/GCL-1.0.10-mac-arm64.zip"
|
||||
"name": "GCL-1.0.11-mac-arm64.zip",
|
||||
"url": "https://git.xhmcl.com/Morris/GC/releases/download/1.0.11/GCL-1.0.11-mac-arm64.zip"
|
||||
},
|
||||
"osx-x64": {
|
||||
"path": "dist/mac-x64/GCL-1.0.10-mac-x64.zip",
|
||||
"path": "dist/mac-x64/GCL-1.0.11-mac-x64.zip",
|
||||
"dir": "dist/mac-x64",
|
||||
"name": "GCL-1.0.10-mac-x64.zip",
|
||||
"url": "https://git.xhmcl.com/Morris/GC/releases/download/1.0.10/GCL-1.0.10-mac-x64.zip"
|
||||
"name": "GCL-1.0.11-mac-x64.zip",
|
||||
"url": "https://git.xhmcl.com/Morris/GC/releases/download/1.0.11/GCL-1.0.11-mac-x64.zip"
|
||||
},
|
||||
"linux-arm64": {
|
||||
"path": "dist/linux-arm64/GCL-1.0.10-linux-arm64.zip",
|
||||
"path": "dist/linux-arm64/GCL-1.0.11-linux-arm64.zip",
|
||||
"dir": "dist/linux-arm64",
|
||||
"name": "GCL-1.0.10-linux-arm64.zip",
|
||||
"url": "https://git.xhmcl.com/Morris/GC/releases/download/1.0.10/GCL-1.0.10-linux-arm64.zip"
|
||||
"name": "GCL-1.0.11-linux-arm64.zip",
|
||||
"url": "https://git.xhmcl.com/Morris/GC/releases/download/1.0.11/GCL-1.0.11-linux-arm64.zip"
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -49,7 +49,7 @@
|
||||
"id": "contour-map",
|
||||
"version": "1.1",
|
||||
"build": "773ab2161d",
|
||||
"manifestSha256": "f81d18da03ea3507872468738a3e9bd43e63c884203cae36f213e8dafb3d4027",
|
||||
"manifestSha256": "f673521f7462324a2a461253ed975c9f89abc4df34b937cad70a2a134623456d",
|
||||
"filesSha256": "a6bdf9b4273aabee50c3c94ceab4d0abee15f0df1af90c58bdbb796e0d2d5699",
|
||||
"files": 5,
|
||||
"dir": "model/contour-map"
|
||||
@@ -58,7 +58,7 @@
|
||||
"id": "earth-geography",
|
||||
"version": "1.9",
|
||||
"build": "cc68b8863b",
|
||||
"manifestSha256": "d231450e1d103eb324ba6c78b073782247ce5e1960b6f7697795e18c89e8e888",
|
||||
"manifestSha256": "89e3afa8843fb080c81e062967790cddba54665b182e4a0819c8c1fd737d5189",
|
||||
"filesSha256": "c018ba481831e23d3183a38ac47251f19754c7464baa5d85b47cea7a49fcfa95",
|
||||
"files": 11,
|
||||
"dir": "model/earth-geography"
|
||||
@@ -67,7 +67,7 @@
|
||||
"id": "earth-revolution",
|
||||
"version": "1.7",
|
||||
"build": "53b7a0fbc3",
|
||||
"manifestSha256": "3e9550fa769a2a52215a7eea53b26e5db13281d1833fc02f83c56ff5b214a949",
|
||||
"manifestSha256": "31f20837131573957101f7fba9a653c8785f6dbda5fd678862148a9f7f87e841",
|
||||
"filesSha256": "4cd45b0324a77574a0da3a939c2a6faebc785c5a24cb50136d62a78a6ea2e9b1",
|
||||
"files": 7,
|
||||
"dir": "model/earth-revolution"
|
||||
@@ -76,7 +76,7 @@
|
||||
"id": "earth-rotation",
|
||||
"version": "1.7",
|
||||
"build": "ecd52665f9",
|
||||
"manifestSha256": "ac74d2037ea06b1ce758c3187deb37527eec11ce37789e62e4dadf95bf1fdd94",
|
||||
"manifestSha256": "caa89497a70b29db87e67d35cd7d3e27a18306646209b2178cfb71b73cfca8ba",
|
||||
"filesSha256": "594b005a6a9f36cd0b5d4e4a7a0b1ab42d53c8032832545b71c3915493d56c8e",
|
||||
"files": 7,
|
||||
"dir": "model/earth-rotation"
|
||||
@@ -85,7 +85,7 @@
|
||||
"id": "scale-calculator",
|
||||
"version": "1.6",
|
||||
"build": "105653737d",
|
||||
"manifestSha256": "f81bbd3453c56e7547a0fceedf4458a2a9febfb77f7d8eabe03b47e526eedaef",
|
||||
"manifestSha256": "952d2529f3b62f6703456ae9bc6f867edac148b7ec9963444c426d26aa35208d",
|
||||
"filesSha256": "732dd26406e0f1e836970499d7ea644def332ce909d7f8aa0a403bbe7337e604",
|
||||
"files": 6,
|
||||
"dir": "model/scale-calculator"
|
||||
@@ -94,8 +94,8 @@
|
||||
"signature": {
|
||||
"alg": "ECDSA-P256-SHA256",
|
||||
"keyId": "gc-2026-12",
|
||||
"value": "4k5CD5awa6iiLoZDDTQbpUEs3qnA1GBNit66T0IOMmKzHpHFmd1oaMGiQFFMDL+LHnKoKooWcF6G8HnaQv3hig==",
|
||||
"contentSha256": "26aa159b440dd0f1d2e912c959059e8f7df6aa9ecd7c1c53fde8915239134b19",
|
||||
"signedAt": "2026-11-18T12:38:10Z"
|
||||
"value": "6i/y23uDD4qa3docjAeeUIHHEV+hSrEGEV6vxQ54a3tyUzxc5lbxBth15gnmxgac7kL3ULULb3G4dI59R6MHxg==",
|
||||
"contentSha256": "86290d84dce5ae9619f5f25e7151480d916aab6177449955366f87b74fbce71c",
|
||||
"signedAt": "2026-11-18T13:06:34Z"
|
||||
}
|
||||
}
|
||||
+29
-29
@@ -1,46 +1,46 @@
|
||||
{
|
||||
"schema": 1,
|
||||
"generated": "2026-11-18T12:37:25Z",
|
||||
"generated": "2026-11-18T13:05:57Z",
|
||||
"repository": "https://git.xhmcl.com/Morris/GC",
|
||||
"branch": "main",
|
||||
"modelDir": "model",
|
||||
"launcher": {
|
||||
"version": "1.0.10",
|
||||
"version": "1.0.11",
|
||||
"revision": "",
|
||||
"packages": {
|
||||
"win-x64": {
|
||||
"path": "dist/win-amd64/GCL-1.0.10-win-amd64.zip",
|
||||
"path": "dist/win-amd64/GCL-1.0.11-win-amd64.zip",
|
||||
"dir": "dist/win-amd64",
|
||||
"name": "GCL-1.0.10-win-amd64.zip",
|
||||
"url": "https://git.xhmcl.com/Morris/GC/releases/download/1.0.10/GCL-1.0.10-win-amd64.zip",
|
||||
"sha256": "ace717e9a96704c0f51420fc7ee23af01405c239cf9e039352d9864d7fe513b8",
|
||||
"size": 74323474
|
||||
"name": "GCL-1.0.11-win-amd64.zip",
|
||||
"url": "https://git.xhmcl.com/Morris/GC/releases/download/1.0.11/GCL-1.0.11-win-amd64.zip",
|
||||
"sha256": "55f1d5eb0dfdfc243656e6705c3d276dd83611561f913fe5ca9e6e5d2f2dd658",
|
||||
"size": 74973271
|
||||
},
|
||||
"win-arm64": {
|
||||
"path": "dist/win-arm64/GCL-1.0.10-win-arm64.zip",
|
||||
"path": "dist/win-arm64/GCL-1.0.11-win-arm64.zip",
|
||||
"dir": "dist/win-arm64",
|
||||
"name": "GCL-1.0.10-win-arm64.zip",
|
||||
"url": "https://git.xhmcl.com/Morris/GC/releases/download/1.0.10/GCL-1.0.10-win-arm64.zip",
|
||||
"sha256": "af1337e0ad110ca408141477d17cb33e9a3ea187909d94c5425086d6215ea651",
|
||||
"size": 72068324
|
||||
"name": "GCL-1.0.11-win-arm64.zip",
|
||||
"url": "https://git.xhmcl.com/Morris/GC/releases/download/1.0.11/GCL-1.0.11-win-arm64.zip",
|
||||
"sha256": "9ce48381fcca18e7d6789364e1c43f7e616ceae529c0c1167b099ed762f5808f",
|
||||
"size": 72515856
|
||||
},
|
||||
"osx-arm64": {
|
||||
"path": "dist/mac-arm64/GCL-1.0.10-mac-arm64.zip",
|
||||
"path": "dist/mac-arm64/GCL-1.0.11-mac-arm64.zip",
|
||||
"dir": "dist/mac-arm64",
|
||||
"name": "GCL-1.0.10-mac-arm64.zip",
|
||||
"url": "https://git.xhmcl.com/Morris/GC/releases/download/1.0.10/GCL-1.0.10-mac-arm64.zip"
|
||||
"name": "GCL-1.0.11-mac-arm64.zip",
|
||||
"url": "https://git.xhmcl.com/Morris/GC/releases/download/1.0.11/GCL-1.0.11-mac-arm64.zip"
|
||||
},
|
||||
"osx-x64": {
|
||||
"path": "dist/mac-x64/GCL-1.0.10-mac-x64.zip",
|
||||
"path": "dist/mac-x64/GCL-1.0.11-mac-x64.zip",
|
||||
"dir": "dist/mac-x64",
|
||||
"name": "GCL-1.0.10-mac-x64.zip",
|
||||
"url": "https://git.xhmcl.com/Morris/GC/releases/download/1.0.10/GCL-1.0.10-mac-x64.zip"
|
||||
"name": "GCL-1.0.11-mac-x64.zip",
|
||||
"url": "https://git.xhmcl.com/Morris/GC/releases/download/1.0.11/GCL-1.0.11-mac-x64.zip"
|
||||
},
|
||||
"linux-arm64": {
|
||||
"path": "dist/linux-arm64/GCL-1.0.10-linux-arm64.zip",
|
||||
"path": "dist/linux-arm64/GCL-1.0.11-linux-arm64.zip",
|
||||
"dir": "dist/linux-arm64",
|
||||
"name": "GCL-1.0.10-linux-arm64.zip",
|
||||
"url": "https://git.xhmcl.com/Morris/GC/releases/download/1.0.10/GCL-1.0.10-linux-arm64.zip"
|
||||
"name": "GCL-1.0.11-linux-arm64.zip",
|
||||
"url": "https://git.xhmcl.com/Morris/GC/releases/download/1.0.11/GCL-1.0.11-linux-arm64.zip"
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -49,7 +49,7 @@
|
||||
"id": "contour-map",
|
||||
"version": "1.1",
|
||||
"build": "773ab2161d",
|
||||
"manifestSha256": "f81d18da03ea3507872468738a3e9bd43e63c884203cae36f213e8dafb3d4027",
|
||||
"manifestSha256": "f673521f7462324a2a461253ed975c9f89abc4df34b937cad70a2a134623456d",
|
||||
"filesSha256": "a6bdf9b4273aabee50c3c94ceab4d0abee15f0df1af90c58bdbb796e0d2d5699",
|
||||
"files": 5,
|
||||
"dir": "model/contour-map"
|
||||
@@ -58,7 +58,7 @@
|
||||
"id": "earth-geography",
|
||||
"version": "1.9",
|
||||
"build": "cc68b8863b",
|
||||
"manifestSha256": "d231450e1d103eb324ba6c78b073782247ce5e1960b6f7697795e18c89e8e888",
|
||||
"manifestSha256": "89e3afa8843fb080c81e062967790cddba54665b182e4a0819c8c1fd737d5189",
|
||||
"filesSha256": "c018ba481831e23d3183a38ac47251f19754c7464baa5d85b47cea7a49fcfa95",
|
||||
"files": 11,
|
||||
"dir": "model/earth-geography"
|
||||
@@ -67,7 +67,7 @@
|
||||
"id": "earth-revolution",
|
||||
"version": "1.7",
|
||||
"build": "53b7a0fbc3",
|
||||
"manifestSha256": "3e9550fa769a2a52215a7eea53b26e5db13281d1833fc02f83c56ff5b214a949",
|
||||
"manifestSha256": "31f20837131573957101f7fba9a653c8785f6dbda5fd678862148a9f7f87e841",
|
||||
"filesSha256": "4cd45b0324a77574a0da3a939c2a6faebc785c5a24cb50136d62a78a6ea2e9b1",
|
||||
"files": 7,
|
||||
"dir": "model/earth-revolution"
|
||||
@@ -76,7 +76,7 @@
|
||||
"id": "earth-rotation",
|
||||
"version": "1.7",
|
||||
"build": "ecd52665f9",
|
||||
"manifestSha256": "ac74d2037ea06b1ce758c3187deb37527eec11ce37789e62e4dadf95bf1fdd94",
|
||||
"manifestSha256": "caa89497a70b29db87e67d35cd7d3e27a18306646209b2178cfb71b73cfca8ba",
|
||||
"filesSha256": "594b005a6a9f36cd0b5d4e4a7a0b1ab42d53c8032832545b71c3915493d56c8e",
|
||||
"files": 7,
|
||||
"dir": "model/earth-rotation"
|
||||
@@ -85,7 +85,7 @@
|
||||
"id": "scale-calculator",
|
||||
"version": "1.6",
|
||||
"build": "105653737d",
|
||||
"manifestSha256": "f81bbd3453c56e7547a0fceedf4458a2a9febfb77f7d8eabe03b47e526eedaef",
|
||||
"manifestSha256": "952d2529f3b62f6703456ae9bc6f867edac148b7ec9963444c426d26aa35208d",
|
||||
"filesSha256": "732dd26406e0f1e836970499d7ea644def332ce909d7f8aa0a403bbe7337e604",
|
||||
"files": 6,
|
||||
"dir": "model/scale-calculator"
|
||||
@@ -94,8 +94,8 @@
|
||||
"signature": {
|
||||
"alg": "ECDSA-P256-SHA256",
|
||||
"keyId": "gc-2026-12",
|
||||
"value": "4k5CD5awa6iiLoZDDTQbpUEs3qnA1GBNit66T0IOMmKzHpHFmd1oaMGiQFFMDL+LHnKoKooWcF6G8HnaQv3hig==",
|
||||
"contentSha256": "26aa159b440dd0f1d2e912c959059e8f7df6aa9ecd7c1c53fde8915239134b19",
|
||||
"signedAt": "2026-11-18T12:38:10Z"
|
||||
"value": "6i/y23uDD4qa3docjAeeUIHHEV+hSrEGEV6vxQ54a3tyUzxc5lbxBth15gnmxgac7kL3ULULb3G4dI59R6MHxg==",
|
||||
"contentSha256": "86290d84dce5ae9619f5f25e7151480d916aab6177449955366f87b74fbce71c",
|
||||
"signedAt": "2026-11-18T13:06:34Z"
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user