feat:文件传输优化

This commit is contained in:
MatrixSeven
2025-08-01 18:38:28 +08:00
parent 652dbed722
commit ecde1b40c0
12 changed files with 1421 additions and 119 deletions

View File

@@ -0,0 +1,43 @@
import { NextRequest, NextResponse } from 'next/server';
export async function POST(req: NextRequest) {
try {
const { text } = await req.json();
if (!text || text.trim().length === 0) {
return NextResponse.json({ error: '文本内容不能为空' }, { status: 400 });
}
if (text.length > 50000) {
return NextResponse.json({ error: '文本内容过长最大支持50,000字符' }, { status: 400 });
}
// 调用后端API创建文字传输房间
const response = await fetch('http://localhost:8080/api/create-text-room', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ text }),
});
if (!response.ok) {
throw new Error('创建文字传输房间失败');
}
const data = await response.json();
return NextResponse.json({
success: true,
code: data.code,
message: '文字传输房间创建成功'
});
} catch (error) {
console.error('创建文字传输房间错误:', error);
return NextResponse.json(
{ error: '服务器错误,请重试' },
{ status: 500 }
);
}
}

View File

@@ -0,0 +1,41 @@
import { NextRequest, NextResponse } from 'next/server';
export async function POST(req: NextRequest) {
try {
const { code } = await req.json();
if (!code || code.length !== 6) {
return NextResponse.json({ error: '请输入正确的6位房间码' }, { status: 400 });
}
// 调用后端API获取文字内容
const response = await fetch(`http://localhost:8080/api/get-text-content/${code}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
});
if (!response.ok) {
if (response.status === 404) {
return NextResponse.json({ error: '房间不存在或已过期' }, { status: 404 });
}
throw new Error('获取文字内容失败');
}
const data = await response.json();
return NextResponse.json({
success: true,
text: data.text,
message: '文字内容获取成功'
});
} catch (error) {
console.error('获取文字内容错误:', error);
return NextResponse.json(
{ error: '服务器错误,请重试' },
{ status: 500 }
);
}
}