fix(update): recover from GitHub rate limits with configurable mirrors

This commit is contained in:
手瓜一十雪 committed 2026-10-18 19:41:02 +08:00
1 parent 68deb48811
commit 20cf7394e5
21 files changed
+1423 -93

No files matched your search

+42
View File
@@ -1,10 +1,52 @@
import { Hono } from 'hono';
import type { HttpBindings } from '@hono/node-server';
import type { UpdateService } from '../update/service';
import { readUpdateSource, saveUpdateSource, testUpdateSources } from '../update/sources';
import {
normalizeUpdateSourceConfig,
type UpdateSourceConfig,
} from '@snowluma/common/update-source';
export function updateRoutes(service: UpdateService, restart: () => void) {
const app = new Hono<{ Bindings: HttpBindings }>();
app.get('/status', (c) => c.json(service.status()));
app.get('/sources', (c) => {
try {
return c.json({ config: readUpdateSource() });
} catch (error) {
return c.json({ message: error instanceof Error ? error.message : String(error) }, 500);
}
});
app.post('/sources', async (c) => {
let config: UpdateSourceConfig;
try {
config = normalizeUpdateSourceConfig(await c.req.json());
} catch (error) {
return c.json({ message: error instanceof Error ? error.message : String(error) }, 400);
}
try {
saveUpdateSource(config);
return c.json({
config,
saved: true,
applied: true,
online: true,
errors: [],
message: '更新来源已保存',
});
} catch (error) {
return c.json({ message: error instanceof Error ? error.message : String(error) }, 500);
}
});
app.post('/sources/test', async (c) => {
try {
return c.json({ results: await testUpdateSources(await c.req.json()) });
} catch (error) {
return c.json({ message: error instanceof Error ? error.message : String(error) }, 400);
}
});
app.post('/download', async (c) => {
let body: unknown;