fix: stabilize review detail and collabora loading
This commit is contained in:
@@ -1,50 +1,52 @@
|
||||
import { json, type LoaderFunctionArgs } from '@remix-run/node';
|
||||
import { difyClient } from '~/api/dify-chat/client.server';
|
||||
import { commitSession, getSessionInfo } from '../utils/session.server';
|
||||
|
||||
export async function loader({ request }: LoaderFunctionArgs) {
|
||||
try {
|
||||
// 获取用户会话信息和 JWT
|
||||
const { getUserSession } = await import("~/api/login/auth.server");
|
||||
const { frontendJWT } = await getUserSession(request);
|
||||
const { session } = await getSessionInfo(request);
|
||||
|
||||
// 检查 JWT 是否存在
|
||||
if (!frontendJWT) {
|
||||
console.error('❌ [API] Parameters API - JWT不存在');
|
||||
return json(
|
||||
{ error: 'JWT认证失败,请重新登录' },
|
||||
{
|
||||
status: 401,
|
||||
headers: {
|
||||
'Set-Cookie': await commitSession(session),
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
const data = await difyClient.getApplicationParameters(frontendJWT);
|
||||
|
||||
return json(data, {
|
||||
headers: {
|
||||
'Set-Cookie': await commitSession(session),
|
||||
},
|
||||
});
|
||||
} catch (error: any) {
|
||||
console.error('❌ [API] Parameters API - Error:', error);
|
||||
|
||||
// 检查是否是JWT认证失败
|
||||
const sm = error.message?.match(/(\d{3})/); const os = sm ? parseInt(sm[1]) : 0;
|
||||
const status = error.message?.includes('JWT认证失败') ? 401 : os >= 400 && os < 500 ? os : 500;
|
||||
|
||||
return json(
|
||||
{ error: error.message || 'Failed to fetch parameters' },
|
||||
{
|
||||
status,
|
||||
headers: {
|
||||
'Set-Cookie': await commitSession((await getSessionInfo(request)).session),
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
import { json, type LoaderFunctionArgs } from '@remix-run/node';
|
||||
import { difyClient } from '~/api/dify-chat/client.server';
|
||||
import { commitSession, getSessionInfo } from '../utils/session.server';
|
||||
|
||||
export async function loader({ request }: LoaderFunctionArgs) {
|
||||
try {
|
||||
// 获取用户会话信息和 JWT
|
||||
const { getUserSession } = await import("~/api/login/auth.server");
|
||||
const { frontendJWT } = await getUserSession(request);
|
||||
const { session } = await getSessionInfo(request);
|
||||
|
||||
// 检查 JWT 是否存在
|
||||
if (!frontendJWT) {
|
||||
console.error('❌ [API] Parameters API - JWT不存在');
|
||||
return json(
|
||||
{ error: 'JWT认证失败,请重新登录' },
|
||||
{
|
||||
status: 401,
|
||||
headers: {
|
||||
'Set-Cookie': await commitSession(session),
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
const url = new URL(request.url);
|
||||
const appId = url.searchParams.get('app_id') || undefined;
|
||||
const data = await difyClient.getApplicationParameters(frontendJWT, appId);
|
||||
|
||||
return json(data, {
|
||||
headers: {
|
||||
'Set-Cookie': await commitSession(session),
|
||||
},
|
||||
});
|
||||
} catch (error: any) {
|
||||
console.error('❌ [API] Parameters API - Error:', error);
|
||||
|
||||
// 检查是否是JWT认证失败
|
||||
const sm = error.message?.match(/(\d{3})/); const os = sm ? parseInt(sm[1]) : 0;
|
||||
const status = error.message?.includes('JWT认证失败') ? 401 : os >= 400 && os < 500 ? os : 500;
|
||||
|
||||
return json(
|
||||
{ error: error.message || 'Failed to fetch parameters' },
|
||||
{
|
||||
status,
|
||||
headers: {
|
||||
'Set-Cookie': await commitSession((await getSessionInfo(request)).session),
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user