UI-React refactor

This commit is contained in:
MatrixSeven
2025-07-30 10:26:11 +08:00
parent adacb453ef
commit 9e59806192
42 changed files with 7151 additions and 397 deletions

View File

@@ -0,0 +1,28 @@
import { NextRequest, NextResponse } from 'next/server';
const GO_BACKEND_URL = process.env.GO_BACKEND_URL || 'http://localhost:8080';
export async function POST(request: NextRequest) {
try {
const body = await request.json();
// 转发请求到Go后端
const response = await fetch(`${GO_BACKEND_URL}/api/create-room`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(body),
});
const data = await response.json();
return NextResponse.json(data, { status: response.status });
} catch (error) {
console.error('Error creating room:', error);
return NextResponse.json(
{ success: false, message: '创建房间失败' },
{ status: 500 }
);
}
}

View File

@@ -0,0 +1,35 @@
import { NextRequest, NextResponse } from 'next/server';
const GO_BACKEND_URL = process.env.GO_BACKEND_URL || 'http://localhost:8080';
export async function GET(request: NextRequest) {
try {
const { searchParams } = new URL(request.url);
const code = searchParams.get('code');
if (!code) {
return NextResponse.json(
{ success: false, message: '缺少取件码' },
{ status: 400 }
);
}
// 转发请求到Go后端
const response = await fetch(`${GO_BACKEND_URL}/api/room-info?code=${code}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
});
const data = await response.json();
return NextResponse.json(data, { status: response.status });
} catch (error) {
console.error('Error getting room info:', error);
return NextResponse.json(
{ success: false, message: '获取房间信息失败' },
{ status: 500 }
);
}
}

View File

@@ -0,0 +1,35 @@
import { NextRequest, NextResponse } from 'next/server';
const GO_BACKEND_URL = process.env.GO_BACKEND_URL || 'http://localhost:8080';
export async function GET(request: NextRequest) {
try {
const { searchParams } = new URL(request.url);
const code = searchParams.get('code');
if (!code) {
return NextResponse.json(
{ success: false, message: '缺少取件码' },
{ status: 400 }
);
}
// 转发请求到Go后端
const response = await fetch(`${GO_BACKEND_URL}/api/room-status?code=${code}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
});
const data = await response.json();
return NextResponse.json(data, { status: response.status });
} catch (error) {
console.error('Error getting room status:', error);
return NextResponse.json(
{ success: false, message: '获取房间状态失败' },
{ status: 500 }
);
}
}

View File

@@ -0,0 +1,38 @@
import { NextRequest, NextResponse } from 'next/server';
export async function POST(request: NextRequest) {
try {
const body = await request.json();
const { code, files } = body;
if (!code || !files) {
return NextResponse.json(
{ success: false, message: '缺少必要参数' },
{ status: 400 }
);
}
// 转发请求到Go后端
const backendUrl = process.env.NODE_ENV === 'production'
? `https://${process.env.VERCEL_URL || 'localhost'}/api/update-files`
: 'http://localhost:8080/api/update-files';
const response = await fetch(backendUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ code, files }),
});
const data = await response.json();
return NextResponse.json(data);
} catch (error) {
console.error('Update files API error:', error);
return NextResponse.json(
{ success: false, message: '服务器错误' },
{ status: 500 }
);
}
}