From b99ae6df848fabefd32492f56a937a252947893f Mon Sep 17 00:00:00 2001 From: yorn <1057707203@qq.com> Date: Thu, 6 Nov 2025 14:51:31 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=E8=AF=8D=E6=A8=A1=E6=9D=BF=E7=9A=84=E5=88=9B=E5=BB=BA=E8=80=85?= =?UTF-8?q?=E7=9A=84=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/prompts/prompts.ts | 50 ++++++++++++----------------------- app/config/api-config.ts | 6 ++--- app/routes/prompts._index.tsx | 3 ++- app/routes/prompts.new.tsx | 5 ++-- 4 files changed, 25 insertions(+), 39 deletions(-) diff --git a/app/api/prompts/prompts.ts b/app/api/prompts/prompts.ts index 6a41eb9..b721a0a 100644 --- a/app/api/prompts/prompts.ts +++ b/app/api/prompts/prompts.ts @@ -27,6 +27,7 @@ export interface PromptTemplateUI { status: 'active' | 'inactive' | 'system'; version: string; created_by: number; + created_by_username?: string; // 创建者用户名 created_at: string; updated_at: string; } @@ -91,10 +92,10 @@ function mapStatusToAPI(status: string): number { /** * 将数据库模板转换为UI模板 - * @param template 数据库模板 + * @param template 数据库模板(可能包含关联的用户信息) * @returns UI模板 */ -export function convertToUITemplate(template: PromptTemplate): PromptTemplateUI { +export function convertToUITemplate(template: PromptTemplate & { sso_users?: { username: string } }): PromptTemplateUI { return { id: template.id ? template.id.toString() : '', template_name: template.template_name, @@ -105,6 +106,7 @@ export function convertToUITemplate(template: PromptTemplate): PromptTemplateUI status: mapStatusToUI(template.status), version: template.version, created_by: template.created_by, + created_by_username: template.sso_users?.username, // 从关联的用户信息中提取用户名 created_at: formatDate(template.created_at), updated_at: formatDate(template.updated_at) }; @@ -127,21 +129,9 @@ export async function getPromptTemplates(searchParams: PromptSearchParams = {}, const page = searchParams.page || 1; const pageSize = searchParams.pageSize || 10; - // 构建查询参数 + // 构建查询参数,包含对 sso_users 表的左连接 const params: PostgrestParams = { - select: ` - id, - template_name, - template_type, - description, - template_content, - variables, - status, - version, - created_by, - created_at, - updated_at - `, + select: `id,template_name,template_type,description,template_content,variables,status,version,created_by,created_at,updated_at,sso_users!created_by(username)`, order: 'updated_at.desc', headers: { 'Prefer': 'count=exact' @@ -242,19 +232,7 @@ export async function getPromptTemplate(id: string, frontendJWT?: string): Promi } const params: PostgrestParams = { - select: ` - id, - template_name, - template_type, - description, - template_content, - variables, - status, - version, - created_by, - created_at, - updated_at - `, + select: `id,template_name,template_type,description,template_content,variables,status,version,created_by,created_at,updated_at,sso_users!created_by(username)`, filter: { 'id': `eq.${id}` }, @@ -286,10 +264,11 @@ export async function getPromptTemplate(id: string, frontendJWT?: string): Promi /** * 创建提示词模板 * @param template 提示词模板数据 + * @param userId 当前用户ID * @param frontendJWT JWT token (可选) * @returns 创建的提示词模板 */ -export async function createPromptTemplate(template: Partial, frontendJWT?: string): Promise<{ +export async function createPromptTemplate(template: Partial, userId: number, frontendJWT?: string): Promise<{ data?: PromptTemplateUI; error?: string; status?: number; @@ -299,7 +278,12 @@ export async function createPromptTemplate(template: Partial, if (!template.template_name || !template.template_type || !template.template_content) { return { error: '模板名称、类型和内容不能为空', status: 400 }; } - + + // 验证用户ID + if (!userId) { + return { error: '用户ID不能为空', status: 400 }; + } + // 准备变量数据 let variablesData: Record = {}; if (typeof template.variables === 'string') { @@ -311,7 +295,7 @@ export async function createPromptTemplate(template: Partial, } else if (template.variables) { variablesData = template.variables; } - + // 准备API数据 const apiTemplate: Partial = { template_name: template.template_name, @@ -321,7 +305,7 @@ export async function createPromptTemplate(template: Partial, variables: variablesData, status: mapStatusToAPI(template.status || 'active'), version: template.version || 'v1.0', - created_by: 1 // 固定创建者为1 + created_by: userId // 使用当前登录用户ID }; if(apiTemplate){ diff --git a/app/config/api-config.ts b/app/config/api-config.ts index 2aee851..6b78c4e 100644 --- a/app/config/api-config.ts +++ b/app/config/api-config.ts @@ -72,9 +72,9 @@ const portConfigs: Record> = { // 主要 // 梅州 '51703': { - baseUrl: 'http://nas.7bm.co:8073', - documentUrl: 'http://nas.7bm.co:8073/docauditai/', - uploadUrl: 'http://nas.7bm.co:8073/admin/documents' + baseUrl: 'http://172.16.0.58:8073', + documentUrl: 'http://172.16.0.58:8073/docauditai/', + uploadUrl: 'http://172.16.0.58:8073/admin/documents' // baseUrl: 'http://nas.7bm.co:8873', // documentUrl: 'http://nas.7bm.co:8873/docauditai/', // uploadUrl: 'http://nas.7bm.co:8873/admin/documents' diff --git a/app/routes/prompts._index.tsx b/app/routes/prompts._index.tsx index aa3c4d2..47529d1 100644 --- a/app/routes/prompts._index.tsx +++ b/app/routes/prompts._index.tsx @@ -334,7 +334,8 @@ export default function PromptsIndex() { key: "created_by", width: "100px", render: (_: unknown, record: PromptTemplateUI) => ( - 用户 {record.created_by} + // 用户 {record.created_by} + {record.created_by_username} ) }, { diff --git a/app/routes/prompts.new.tsx b/app/routes/prompts.new.tsx index 3fb158d..8efa694 100644 --- a/app/routes/prompts.new.tsx +++ b/app/routes/prompts.new.tsx @@ -109,8 +109,9 @@ export async function loader({ request }: LoaderFunctionArgs) { // Action函数 - 处理表单提交 export async function action({ request }: ActionFunctionArgs) { const { getUserSession } = await import("~/api/login/auth.server"); - const { frontendJWT } = await getUserSession(request); + const { userInfo, frontendJWT } = await getUserSession(request); + const userId = userInfo.get('user_id') const formData = await request.formData(); const id = formData.get("id") as string; const template_name = formData.get("template_name") as string; @@ -168,7 +169,7 @@ export async function action({ request }: ActionFunctionArgs) { result = await updatePromptTemplate(id, apiTemplate, frontendJWT); } else { // 创建模板 - result = await createPromptTemplate(apiTemplate, frontendJWT); + result = await createPromptTemplate(apiTemplate, userId, frontendJWT); } if (result.error) { From 1f9c8293a845628325217a8fb5a46085a057f3cb Mon Sep 17 00:00:00 2001 From: yorn <1057707203@qq.com> Date: Thu, 6 Nov 2025 14:52:50 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0.env=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 9 +++++++++ .gitignore | 1 - 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 .env diff --git a/.env b/.env new file mode 100644 index 0000000..9629a70 --- /dev/null +++ b/.env @@ -0,0 +1,9 @@ +# APP ID +NEXT_PUBLIC_APP_ID=http://nas.7bm.co:12980/app/46539478-3281-4e98-a445-6da9dc078e95/configuration +# APP API key +NEXT_PUBLIC_APP_KEY=app-3t4oRQd88YCTKhhFUnkohef6 +NEXT_PUBLIC_API_URL=http://172.16.0.55:8000/dify + +# JWT Secret - 用于签名和验证前端JWT token +# 生产环境请务必修改为强随机字符串(至少32个字符) +JWT_SECRET=gdyc-super-secrets-jjwtt-key-change-this-in-production-20250721-from-login-callback \ No newline at end of file diff --git a/.gitignore b/.gitignore index b1d59c7..77a35df 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,6 @@ node_modules /.cache /build /public/build/ -.env .idea .history