Skip to content

Commit 26b5aac

Browse files
committed
The main features have been implemented
2 parents 4ed7b7d + 764aefd commit 26b5aac

File tree

23 files changed

+1448
-165
lines changed

23 files changed

+1448
-165
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
type Params = Promise<{ cratename: string, version: string }>
2+
import { NextRequest, NextResponse } from "next/server";
3+
4+
export async function GET(req: NextRequest, props: { params: Params }) {
5+
try {
6+
const params = await props.params
7+
const { cratename, version } = params;
8+
9+
const externalApiUrl = `http://210.28.134.203:6888/api/crates/${cratename}/${version}/dependencies`; // 替换为你的外部 API URL
10+
const externalRes = await fetch(externalApiUrl);
11+
if (!externalRes.ok) {
12+
throw new Error('Failed to fetch external data');
13+
}
14+
const externalData = await externalRes.json();
15+
console.log('External API Response:', externalData);
16+
return NextResponse.json(externalData);
17+
} catch (error) {
18+
console.error('Error:', error);
19+
return NextResponse.json({ error: 'Internal Server Error' }, { status: 500 });
20+
21+
}
22+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { NextRequest, NextResponse } from "next/server";
2+
type Params = Promise<{ cratename: string, version: string }>
3+
export async function GET(req: NextRequest, props: { params: Params }) {
4+
try {
5+
const params = await props.params
6+
const { cratename, version } = params;
7+
const externalApiUrl = `http://210.28.134.203:6888/api/crates/${cratename}/${version}/dependents`; // 替换为你的外部 API URL
8+
const externalRes = await fetch(externalApiUrl);
9+
if (!externalRes.ok) {
10+
throw new Error('Failed to fetch external data');
11+
}
12+
const externalData = await externalRes.json();
13+
console.log('External API Response:', externalData);
14+
return NextResponse.json(externalData);
15+
} catch (error) {
16+
console.error('Error:', error);
17+
return NextResponse.json({ error: 'Internal Server Error' }, { status: 500 });
18+
19+
}
20+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { NextRequest, NextResponse } from "next/server";
2+
type Params = Promise<{ cratename: string, version: string }>
3+
4+
export async function GET(req: NextRequest, props: { params: Params }) {
5+
try {
6+
const params = await props.params
7+
const { cratename, version } = params;
8+
9+
const externalApiUrl = `http://210.28.134.203:6888/api/crates/${cratename}/${version}`; // 替换为你的外部 API URL
10+
const externalRes = await fetch(externalApiUrl);
11+
if (!externalRes.ok) {
12+
throw new Error('Failed to fetch external data');
13+
}
14+
const externalData = await externalRes.json();
15+
console.log('crateinfo 11111111', externalData);
16+
return NextResponse.json(externalData);
17+
} catch (error) {
18+
console.error('Error:', error);
19+
return NextResponse.json({ error: 'Internal Server Error' }, { status: 500 });
20+
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { NextRequest, NextResponse } from 'next/server';
2+
type Params = Promise<{ cratename: string, version: string }>
3+
export async function GET(req: NextRequest, props: { params: Params }) {
4+
try {
5+
const params = await props.params
6+
const { cratename, version } = params;
7+
console.log('cratename', cratename, 'version', version);
8+
const externalApiUrl = `http://210.28.134.203:6888/api/crates/${cratename}`; // 替换为你的外部 API URL
9+
const externalRes = await fetch(externalApiUrl);
10+
if (!externalRes.ok) {
11+
throw new Error('Failed to fetch external data');
12+
}
13+
const externalData = await externalRes.json();
14+
15+
return NextResponse.json(externalData);
16+
} catch (error) {
17+
console.error('Error:', error);
18+
return NextResponse.json({ error: 'Internal Server Error' }, { status: 500 });
19+
20+
}
21+
}
22+

app/api/crates/[name]/[version]/route.ts

Lines changed: 0 additions & 84 deletions
This file was deleted.

app/api/crates/[name]/route.ts

Lines changed: 0 additions & 60 deletions
This file was deleted.
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
import { NextResponse } from 'next/server';
1+
import { NextRequest, NextResponse } from 'next/server';
22

3-
export async function GET() {
3+
export async function GET(req: NextRequest) {
44
try {
55
// 发送 HTTP 请求获取外部数据
6-
const externalApiUrl = 'http://210.28.134.203:6888/crates'; // 替换为你的外部 API URL
6+
console.log(req);
7+
const externalApiUrl = 'http://210.28.134.203:6888/api/crates'; // 替换为你的外部 API URL
78
const externalRes = await fetch(externalApiUrl);
8-
99
if (!externalRes.ok) {
1010
throw new Error('Failed to fetch external data');
1111
}
12-
1312
const externalData = await externalRes.json();
1413

1514
return NextResponse.json(externalData);
@@ -18,3 +17,4 @@ export async function GET() {
1817
return NextResponse.json({ error: 'Internal Server Error' }, { status: 500 });
1918
}
2019
}
20+

app/api/cvelist/route.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { NextRequest, NextResponse } from 'next/server';
2+
3+
export async function GET(req: NextRequest) {
4+
try {
5+
// 发送 HTTP 请求获取外部数据
6+
console.log(req);
7+
const externalApiUrl = 'http://210.28.134.203:6888/api/cvelist'; // 替换为你的外部 API URL
8+
const externalRes = await fetch(externalApiUrl);
9+
if (!externalRes.ok) {
10+
throw new Error('Failed to fetch external data');
11+
}
12+
const externalData = await externalRes.json();
13+
14+
return NextResponse.json(externalData);
15+
} catch (error) {
16+
console.error('Error:', error);
17+
return NextResponse.json({ error: 'Internal Server Error' }, { status: 500 });
18+
}
19+
}

app/api/cves/route.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ export async function GET() {
3434
try {
3535
const randomCVEs = Array.from({ length: 7 }, generateRandomCVE);
3636
return NextResponse.json(randomCVEs);
37-
} catch {
37+
} catch (error) {
38+
console.log(error);
3839
return NextResponse.json({ error: 'Internal Server Error' }, { status: 500 });
3940
}
4041
}

app/api/search/route.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { NextResponse } from 'next/server';
2+
3+
export async function POST(request: Request) {
4+
const apiUrl = `http://210.28.134.203:6888/api/search`;
5+
const requestBody = await request.json();
6+
console.log("Request Body:", requestBody);
7+
8+
const { query, pagination } = requestBody; //请求体
9+
try {
10+
const response = await fetch(apiUrl, {
11+
method: 'POST',
12+
headers: {
13+
'Content-Type': 'application/json', // 确保发送 JSON
14+
},
15+
body: JSON.stringify({
16+
query, // 发送 query 字段
17+
pagination, // 发送 pagination 字段
18+
}), // 发送 name 字段
19+
});
20+
console.log("response:", response);
21+
if (!response.ok) {
22+
return NextResponse.json({ error: 'Failed to submit data' }, { status: response.status });
23+
}
24+
25+
const result = await response.json(); // 确认返回的是 JSON 格式
26+
console.log("results:", result);
27+
return NextResponse.json({ message: 'Submission successful', code: 2012, data: result });
28+
} catch (error) {
29+
console.log(error);
30+
return NextResponse.json({ error: 'An error occurred while submitting data.' }, { status: 500 });
31+
}
32+
}

0 commit comments

Comments
 (0)