feat: 大量优化和bug修复
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
// server/api/user/settings.get.ts - 读取当前用户的自定义 API 配置
|
||||
//
|
||||
// 流程:鉴权 → 读 user_config 单行 JSON 配置 → 遮蔽 key → 返回
|
||||
// 安全边界:key 只返回遮蔽预览(前4...后4),不返回明文;不涉及系统配置
|
||||
|
||||
import { prisma } from "~~/server/utils/db";
|
||||
import { apiOk } from "~~/server/utils/response";
|
||||
import { maskApiKey } from "~~/server/utils/sysConfig";
|
||||
import { normalizeUserConfigValue } from "~~/server/utils/userConfig";
|
||||
import type { IUserSettingsResponse } from "~~/shared/types/settings";
|
||||
|
||||
export default defineEventHandler(async (event): Promise<IUserSettingsResponse> => {
|
||||
// middleware 已确保此处 auth 不为空
|
||||
const userId = event.context.auth!.user.id;
|
||||
|
||||
const row = await prisma.userConfig.findUnique({
|
||||
where: { userId },
|
||||
select: { value: true }
|
||||
});
|
||||
const userConfig = normalizeUserConfigValue(row?.value);
|
||||
|
||||
return apiOk({
|
||||
useCustomConfig: userConfig.useCustomConfig,
|
||||
customApiBase: userConfig.customApiBase,
|
||||
customApiKeyPreview: maskApiKey(userConfig.customApiKey ?? ""),
|
||||
customModel: userConfig.customModel,
|
||||
customMaxTokens: userConfig.customMaxTokens,
|
||||
customTemperature: userConfig.customTemperature
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user