更新 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";
/** Route constants — kept in one place so the client half can reuse them. */
export const ROUTES = {
page: '/cloud-memory',
status: '/cloud-memory/status',
config: '/cloud-memory/config',
login: '/cloud-memory/login',
test: '/cloud-memory/test',
flush: '/cloud-memory/flush',
skills: '/cloud-memory/skills',
page: '/dsh-brain',
status: '/dsh-brain/status',
config: '/dsh-brain/config',
login: '/dsh-brain/login',
test: '/dsh-brain/test',
flush: '/dsh-brain/flush',
skills: '/dsh-brain/skills',
};
/** Largest request body we accept (a settings patch is tiny). */
const MAX_BODY_BYTES = 64 * 1024;
@ -97,7 +97,7 @@ function servePage(deps, req, res) {
else
res.end(html);
}
/** `GET /cloud-memory/status`. */
/** `GET /dsh-brain/status`. */
function serveStatus(deps, req, res) {
if (req.method !== 'GET') {
fail(res, 405, 'method-not-allowed');
@ -105,7 +105,7 @@ function serveStatus(deps, req, res) {
}
json(res, 200, statusPayload(deps));
}
/** `PUT /cloud-memory/config`. */
/** `PUT /dsh-brain/config`. */
async function serveConfig(deps, req, res) {
if (req.method !== 'PUT' && req.method !== 'POST') {
fail(res, 405, 'method-not-allowed');
@ -139,7 +139,7 @@ async function serveConfig(deps, req, res) {
}
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) {
if (req.method !== 'POST') {
fail(res, 405, 'method-not-allowed');
@ -181,7 +181,7 @@ async function serveTest(deps, req, res) {
})();
json(res, 200, { ok: true, activity, memory, summary });
}
/** `POST /cloud-memory/flush`. */
/** `POST /dsh-brain/flush`. */
async function serveFlush(deps, req, res) {
if (req.method !== 'POST') {
fail(res, 405, 'method-not-allowed');
@ -201,7 +201,7 @@ const TOKEN_LABELS = {
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.
*
* 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:
* `GET /cloud-memory/skills` the management page
* `GET /cloud-memory/skills/api` inventory JSON (skills + trash)
* `POST /cloud-memory/skills/toggle` { folder, enabled }
* `POST /cloud-memory/skills/remove` { folder }
* `POST /cloud-memory/skills/install` { url }
* `GET /dsh-brain/skills` the management page
* `GET /dsh-brain/skills/api` inventory JSON (skills + trash)
* `POST /dsh-brain/skills/toggle` { folder, enabled }
* `POST /dsh-brain/skills/remove` { folder }
* `POST /dsh-brain/skills/install` { url }
*/
async function serveSkills(deps, req, res) {
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. */
/** 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) {
return [
{