更新 lib/routes.js

This commit is contained in:
QQ 2026-11-11 23:14:25 +08:00
parent e5cfe30ffa
commit 20deafc2d6
1 changed files with 21 additions and 17 deletions

View File

@ -4,13 +4,13 @@ import { SkillAdminError } from "./skill-admin.js";
import { renderSkillsPage } from "./skill-page.js"; import { renderSkillsPage } from "./skill-page.js";
/** Route constants — kept in one place so the client half can reuse them. */ /** Route constants — kept in one place so the client half can reuse them. */
export const ROUTES = { export const ROUTES = {
page: '/cloud-memory', page: '/dsh-brain',
status: '/cloud-memory/status', status: '/dsh-brain/status',
config: '/cloud-memory/config', config: '/dsh-brain/config',
login: '/cloud-memory/login', login: '/dsh-brain/login',
test: '/cloud-memory/test', test: '/dsh-brain/test',
flush: '/cloud-memory/flush', flush: '/dsh-brain/flush',
skills: '/cloud-memory/skills', skills: '/dsh-brain/skills',
}; };
/** Largest request body we accept (a settings patch is tiny). */ /** Largest request body we accept (a settings patch is tiny). */
const MAX_BODY_BYTES = 64 * 1024; const MAX_BODY_BYTES = 64 * 1024;
@ -97,7 +97,7 @@ function servePage(deps, req, res) {
else else
res.end(html); res.end(html);
} }
/** `GET /cloud-memory/status`. */ /** `GET /dsh-brain/status`. */
function serveStatus(deps, req, res) { function serveStatus(deps, req, res) {
if (req.method !== 'GET') { if (req.method !== 'GET') {
fail(res, 405, 'method-not-allowed'); fail(res, 405, 'method-not-allowed');
@ -105,7 +105,7 @@ function serveStatus(deps, req, res) {
} }
json(res, 200, statusPayload(deps)); json(res, 200, statusPayload(deps));
} }
/** `PUT /cloud-memory/config`. */ /** `PUT /dsh-brain/config`. */
async function serveConfig(deps, req, res) { async function serveConfig(deps, req, res) {
if (req.method !== 'PUT' && req.method !== 'POST') { if (req.method !== 'PUT' && req.method !== 'POST') {
fail(res, 405, 'method-not-allowed'); fail(res, 405, 'method-not-allowed');
@ -139,7 +139,7 @@ async function serveConfig(deps, req, res) {
} }
json(res, 200, statusPayload(deps)); json(res, 200, statusPayload(deps));
} }
/** `POST /cloud-memory/test` — validate both tokens without recording anything. */ /** `POST /dsh-brain/test` — validate both tokens without recording anything. */
async function serveTest(deps, req, res) { async function serveTest(deps, req, res) {
if (req.method !== 'POST') { if (req.method !== 'POST') {
fail(res, 405, 'method-not-allowed'); fail(res, 405, 'method-not-allowed');
@ -181,7 +181,7 @@ async function serveTest(deps, req, res) {
})(); })();
json(res, 200, { ok: true, activity, memory, summary }); json(res, 200, { ok: true, activity, memory, summary });
} }
/** `POST /cloud-memory/flush`. */ /** `POST /dsh-brain/flush`. */
async function serveFlush(deps, req, res) { async function serveFlush(deps, req, res) {
if (req.method !== 'POST') { if (req.method !== 'POST') {
fail(res, 405, 'method-not-allowed'); fail(res, 405, 'method-not-allowed');
@ -201,7 +201,7 @@ const TOKEN_LABELS = {
summary: 'DSH desktop 对话摘要', summary: 'DSH desktop 对话摘要',
}; };
/** /**
* `POST /cloud-memory/login` — sign in with the cloud account and exchange it * `POST /dsh-brain/login` — sign in with the cloud account and exchange it
* for the two scoped tokens. * for the two scoped tokens.
* *
* The password is used once, in memory, and never written anywhere: the flow is * The password is used once, in memory, and never written anywhere: the flow is
@ -314,11 +314,11 @@ function adminStatus(code) {
} }
/** /**
* The skill management surface, one prefix route: * The skill management surface, one prefix route:
* `GET /cloud-memory/skills` the management page * `GET /dsh-brain/skills` the management page
* `GET /cloud-memory/skills/api` inventory JSON (skills + trash) * `GET /dsh-brain/skills/api` inventory JSON (skills + trash)
* `POST /cloud-memory/skills/toggle` { folder, enabled } * `POST /dsh-brain/skills/toggle` { folder, enabled }
* `POST /cloud-memory/skills/remove` { folder } * `POST /dsh-brain/skills/remove` { folder }
* `POST /cloud-memory/skills/install` { url } * `POST /dsh-brain/skills/install` { url }
*/ */
async function serveSkills(deps, req, res) { async function serveSkills(deps, req, res) {
if (deps.admin === undefined) { if (deps.admin === undefined) {
@ -400,6 +400,10 @@ async function serveSkills(deps, req, res) {
} }
} }
/** Build the exact-route table registered with the host web server. */ /** Build the exact-route table registered with the host web server. */
/** Pre-rename aliases (v0.5.0): the same handlers under the old `/cloud-memory` prefix. */
export function createLegacyRoutes(deps) {
return createRoutes(deps).map((route) => ({ ...route, path: route.path.replace('/dsh-brain', '/cloud-memory') }));
}
export function createRoutes(deps) { export function createRoutes(deps) {
return [ return [
{ {