移除了所有Hermes相关的命名引用,包括: - 从.gitignore中清理相关构建缓存文件 - 将README中的beaver-home路径配置更新 - 完善backend/README.md文档说明Beaver后端主线实现 - 移除Hermes风格的相关注释和兼容性代码 - 清理nanobot环境变量兼容性处理 - 删除技能迁移和服务迁移相关功能代码 - 更新测试用例中相关命名和函数名 BREAKING CHANGE: 移除了Hermes迁移相关API和CLI命令,不再支持nanobot环境变量兼容性
54 lines
1.6 KiB
TypeScript
54 lines
1.6 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server';
|
|
|
|
import type { TokenResponse } from '@/types/auth';
|
|
import { normalizePortalLocale, pickPortalText } from '@/lib/i18n/core';
|
|
import { HttpError, REGISTER_REQUEST_TIMEOUT_MS, callAuthzService } from '@/lib/runtime-control';
|
|
|
|
function errorStatus(error: unknown): number {
|
|
if (error instanceof HttpError) {
|
|
return error.status;
|
|
}
|
|
return 500;
|
|
}
|
|
|
|
function errorDetail(error: unknown): string {
|
|
if (error instanceof HttpError) {
|
|
return error.message;
|
|
}
|
|
return error instanceof Error ? error.message : 'registration failed';
|
|
}
|
|
|
|
export async function POST(request: NextRequest) {
|
|
const locale = normalizePortalLocale(
|
|
request.cookies.get('beaver_locale')?.value ||
|
|
request.headers.get('accept-language')
|
|
);
|
|
|
|
try {
|
|
const body = (await request.json()) as {
|
|
username?: string;
|
|
email?: string;
|
|
password?: string;
|
|
};
|
|
const username = body.username?.trim() || '';
|
|
const email = body.email?.trim() || '';
|
|
const password = body.password || '';
|
|
|
|
if (!username || !password) {
|
|
return NextResponse.json({
|
|
detail: pickPortalText(locale, '用户名和密码不能为空', 'Username and password are required'),
|
|
}, { status: 400 });
|
|
}
|
|
|
|
const response = await callAuthzService<TokenResponse>('/portal/register', {
|
|
username,
|
|
email,
|
|
password,
|
|
}, REGISTER_REQUEST_TIMEOUT_MS);
|
|
|
|
return NextResponse.json(response);
|
|
} catch (error) {
|
|
return NextResponse.json({ detail: errorDetail(error) }, { status: errorStatus(error) });
|
|
}
|
|
}
|