fix: 删除冗余文件
This commit is contained in:
@@ -1,50 +0,0 @@
|
||||
import { json, type ActionFunctionArgs } from '@remix-run/node';
|
||||
import { difyClient } from '../services/dify-client.server';
|
||||
import { getSessionInfo, commitSession } from '../utils/session.server';
|
||||
|
||||
export async function action({ request }: ActionFunctionArgs) {
|
||||
try {
|
||||
const { user, session } = await getSessionInfo(request);
|
||||
|
||||
// console.log('💬 File Upload API - User:', user);
|
||||
|
||||
// 从请求中获取文件
|
||||
const formData = await request.formData();
|
||||
const file = formData.get('file') as File;
|
||||
|
||||
if (!file) {
|
||||
return json({ error: '没有找到文件' }, { status: 400 });
|
||||
}
|
||||
|
||||
// 获取文件内容
|
||||
const fileBuffer = await file.arrayBuffer();
|
||||
|
||||
// 这里需要在dify-client.server.ts中添加上传文件的方法
|
||||
// 目前我们返回一个临时响应
|
||||
// TODO: 实现文件上传功能
|
||||
|
||||
// 构造模拟响应
|
||||
const uploadId = `upload_${Date.now()}`;
|
||||
|
||||
// console.log('✅ File Upload API - Success:', { id: uploadId, fileName: file.name, size: file.size });
|
||||
|
||||
return json({ id: uploadId }, {
|
||||
headers: {
|
||||
'Set-Cookie': await commitSession(session),
|
||||
},
|
||||
});
|
||||
} catch (error: any) {
|
||||
console.error('❌ File Upload API - Error:', error);
|
||||
return json(
|
||||
{
|
||||
error: error.message || '文件上传失败'
|
||||
},
|
||||
{
|
||||
status: 500,
|
||||
headers: {
|
||||
'Set-Cookie': await commitSession((await getSessionInfo(request)).session),
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
import { json, type LoaderFunctionArgs } from '@remix-run/node';
|
||||
import { difyClient } from '../services/dify-client.server';
|
||||
import { getSessionInfo, commitSession } 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);
|
||||
const url = new URL(request.url);
|
||||
const conversationId = url.searchParams.get('conversation_id');
|
||||
|
||||
if (!conversationId) {
|
||||
return json(
|
||||
{ error: 'conversation_id is required' },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
// 检查 JWT 是否存在
|
||||
if (!frontendJWT) {
|
||||
console.error('❌ [API] Messages API - JWT不存在');
|
||||
return json(
|
||||
{ error: 'JWT认证失败,请重新登录' },
|
||||
{
|
||||
status: 401,
|
||||
headers: {
|
||||
'Set-Cookie': await commitSession(session),
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
console.log('📨 [API] Messages API - 获取会话消息:', {
|
||||
conversationId,
|
||||
hasJWT: !!frontendJWT
|
||||
});
|
||||
|
||||
const data = await difyClient.getConversationMessages(conversationId, frontendJWT);
|
||||
|
||||
console.log('✅ [API] Messages API - Success');
|
||||
|
||||
return json(data, {
|
||||
headers: {
|
||||
'Set-Cookie': await commitSession(session),
|
||||
},
|
||||
});
|
||||
} catch (error: any) {
|
||||
console.error('❌ [API] Messages API - Error:', error);
|
||||
|
||||
// 检查是否是JWT认证失败
|
||||
const status = error.message?.includes('JWT认证失败') ? 401 : 500;
|
||||
|
||||
return json(
|
||||
{ error: error.message || 'Failed to fetch messages' },
|
||||
{
|
||||
status,
|
||||
headers: {
|
||||
'Set-Cookie': await commitSession((await getSessionInfo(request)).session),
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
import { type ActionFunctionArgs, json } from "@remix-run/node";
|
||||
import { OAuthClient } from "~/api/login/oauth-client";
|
||||
import { getServerOAuthConfigRuntime } from "~/config/oauth-secret.server";
|
||||
|
||||
/**
|
||||
* 这个Action作为获取OAuth Access Token的服务器端代理。
|
||||
* 它接收来自前端回调的`code`,然后在后端安全地换取令牌,
|
||||
* 以避免在网络策略限制服务器直接访问外部服务时出现问题。
|
||||
*/
|
||||
export async function action({ request }: ActionFunctionArgs) {
|
||||
// 1. 只允许POST请求
|
||||
if (request.method !== "POST") {
|
||||
return json({ success: false, error: "Method Not Allowed" }, { status: 405 });
|
||||
}
|
||||
|
||||
try {
|
||||
// 2. 从请求体中获取`code`
|
||||
const { code } = await request.json();
|
||||
|
||||
if (!code || typeof code !== 'string') {
|
||||
return json({ success: false, error: "Missing or invalid 'code' in request body" }, { status: 400 });
|
||||
}
|
||||
|
||||
console.log("🔧 [/api/oauth/token] 收到代理请求, code:", code ? `${code.substring(0, 10)}...` : null);
|
||||
|
||||
// 3. 在服务器端使用OAuthClient安全地获取访问令牌
|
||||
// 🔒 安全:从 .server.ts 文件运行时读取配置,确保环境变量正确加载
|
||||
const oauthClient = new OAuthClient(getServerOAuthConfigRuntime());
|
||||
const tokenResponse = await oauthClient.getAccessToken(code);
|
||||
|
||||
// 4. 处理来自IDaaS服务器的响应
|
||||
if (!tokenResponse) {
|
||||
console.error("❌ [/api/oauth/token] 从IDaaS获取访问令牌失败。");
|
||||
// 502 Bad Gateway 表示上游服务器(IDaaS)响应无效
|
||||
return json({ success: false, error: "Failed to get access token from IDaaS" }, { status: 502 });
|
||||
}
|
||||
|
||||
console.log("✅ [/api/oauth/token] 已通过代理成功获取令牌。");
|
||||
|
||||
// 5. 将成功的令牌响应返回给调用方 (callback.tsx)
|
||||
return json({ success: true, ...tokenResponse });
|
||||
|
||||
} catch (error) {
|
||||
console.error("❌ [/api/oauth/token] 代理API发生意外错误:", error);
|
||||
const errorMessage = error instanceof Error ? error.message : "An unknown error occurred.";
|
||||
return json({ success: false, error: "Proxy internal error", details: errorMessage }, { status: 500 });
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
import { type ActionFunctionArgs, json } from "@remix-run/node";
|
||||
import { OAuthClient } from "~/api/login/oauth-client";
|
||||
import { getServerOAuthConfigRuntime } from "~/config/oauth-secret.server";
|
||||
|
||||
/**
|
||||
* 这个Action作为获取用户信息的服务器端代理。
|
||||
* 它接收来自前端的`access_token`,然后在后端安全地获取用户信息。
|
||||
*/
|
||||
export async function action({ request }: ActionFunctionArgs) {
|
||||
if (request.method !== "POST") {
|
||||
return json({ success: false, error: "Method Not Allowed" }, { status: 405 });
|
||||
}
|
||||
|
||||
try {
|
||||
const { accessToken } = await request.json();
|
||||
|
||||
if (!accessToken || typeof accessToken !== 'string') {
|
||||
return json({ success: false, error: "Missing or invalid 'accessToken' in request body" }, { status: 400 });
|
||||
}
|
||||
|
||||
console.log("🔧 [/api/oauth/userinfo] 收到代理请求。");
|
||||
|
||||
// 🔒 安全:从 .server.ts 文件运行时读取配置
|
||||
const oauthClient = new OAuthClient(getServerOAuthConfigRuntime());
|
||||
const userInfoResponse = await oauthClient.getUserInfo(accessToken);
|
||||
|
||||
if (!userInfoResponse || !userInfoResponse.success) {
|
||||
console.error("❌ [/api/oauth/userinfo] 从IDaaS获取用户信息失败。");
|
||||
return json({ success: false, error: "Failed to get user info from IDaaS" }, { status: 502 });
|
||||
}
|
||||
|
||||
console.log("✅ [/api/oauth/userinfo] 已通过代理成功获取用户信息。");
|
||||
|
||||
return json({ success: true, data: userInfoResponse.data });
|
||||
|
||||
} catch (error) {
|
||||
console.error("❌ [/api/oauth/userinfo] 代理API发生意外错误:", error);
|
||||
const errorMessage = error instanceof Error ? error.message : "An unknown error occurred.";
|
||||
return json({ success: false, error: "Proxy internal error", details: errorMessage }, { status: 500 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user