@@ -7,27 +7,31 @@
|
||||
// - 此接口不返回任何用户数据
|
||||
|
||||
import { setResponseStatus } from "h3";
|
||||
import { getSysConfig, maskApiKey } from "~~/server/utils/sysConfig";
|
||||
|
||||
import { apiErr, apiOk } from "~~/server/utils/response";
|
||||
import { getSysConfig, maskApiKey } from "~~/server/utils/sysConfig";
|
||||
import type { ISystemConfigResponse } from "~~/shared/types/settings";
|
||||
|
||||
export default defineEventHandler(async (event): Promise<ISystemConfigResponse> => {
|
||||
// 二次校验:必须是 superadmin 才能访问系统配置
|
||||
const role = (event.context.auth?.user as { role?: string } | undefined)
|
||||
?.role;
|
||||
if (role !== "superadmin") {
|
||||
setResponseStatus(event, 403);
|
||||
return apiErr(403, "权限不足") as ISystemConfigResponse;
|
||||
export default defineEventHandler(
|
||||
async (event): Promise<ISystemConfigResponse> => {
|
||||
// 二次校验:必须是 superadmin 才能访问系统配置
|
||||
const role = (event.context.auth?.user as { role?: string } | undefined)
|
||||
?.role;
|
||||
if (role !== "superadmin") {
|
||||
setResponseStatus(event, 403);
|
||||
return apiErr(403, "权限不足") as unknown as ISystemConfigResponse;
|
||||
}
|
||||
|
||||
const cfg = await getSysConfig();
|
||||
|
||||
return apiOk({
|
||||
openAiApiBase: cfg.openAiApiBase,
|
||||
openAiApiKeyPreview: maskApiKey(cfg.openAiApiKey),
|
||||
openAiModel: cfg.openAiModel,
|
||||
maxTokens: cfg.maxTokens,
|
||||
temperature: cfg.temperature,
|
||||
maxSseLineBytes: cfg.maxSseLineBytes,
|
||||
allowRegistration: cfg.allowRegistration
|
||||
});
|
||||
}
|
||||
|
||||
const cfg = await getSysConfig();
|
||||
|
||||
return apiOk({
|
||||
openAiApiBase: cfg.openAiApiBase,
|
||||
openAiApiKeyPreview: maskApiKey(cfg.openAiApiKey),
|
||||
openAiModel: cfg.openAiModel,
|
||||
maxTokens: cfg.maxTokens,
|
||||
temperature: cfg.temperature,
|
||||
maxSseLineBytes: cfg.maxSseLineBytes
|
||||
});
|
||||
});
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user