Skip to content

Commit f0b5277

Browse files
authored
fixed some bugs (#107)
1 parent cb1f7bd commit f0b5277

File tree

23 files changed

+249
-1111
lines changed

23 files changed

+249
-1111
lines changed

app/[nsfront]/[nsbehind]/[name]/[version]/dependencies/graph/page.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const CratePage = () => {
2424
try {
2525
setError(null);
2626
const response = await fetch(
27-
`/api/crates/${params.nsfront}/${params.nsbehind}/${params.name}/${params.version}/dependencies`
27+
`/api/crates/${params.nsfront}/${params.nsbehind}/${params.name}/${params.version}/dependencies/graphpage`
2828
);
2929

3030
if (!response.ok) {
@@ -34,6 +34,7 @@ const CratePage = () => {
3434
const data = await response.json();
3535

3636
setResults(data); // 设置获取的数据
37+
console.log('resultssssssss', results);
3738
} catch (error) {
3839
console.log("Error fetching data:", error);
3940
setError("Failed to fetch data.");
@@ -52,7 +53,7 @@ const CratePage = () => {
5253

5354

5455

55-
<DependencyGraph crateName={params.name as string} currentVersion={params.version as string} />
56+
<DependencyGraph />
5657

5758
</div>
5859
);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'use client';
2+
3+
import React from 'react';
4+
import { useParams } from 'next/navigation';
5+
import CrateNav from '@/components/CrateNav';
6+
7+
export default function Layout({
8+
children,
9+
}: {
10+
children: React.ReactNode;
11+
}) {
12+
const params = useParams();
13+
14+
return (
15+
<div>
16+
<CrateNav
17+
nsfront={params.nsfront as string}
18+
nsbehind={params.nsbehind as string}
19+
name={params.name as string}
20+
version={params.version as string}
21+
/>
22+
{children}
23+
</div>
24+
);
25+
}

app/[nsfront]/[nsbehind]/[name]/[version]/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const CratePage = () => {
3030

3131
fetchCrateData();
3232
}, [params.name, params.version, params.nsfront, params.nsbehind]);
33-
33+
console.log('results in overviewwwwwwwww:', results);
3434
if (loading) return <p>Loading...</p>;
3535
if (error) return <p>Error: {error}</p>;
3636

@@ -92,7 +92,7 @@ const CratePage = () => {
9292

9393
<h3 className="text-xl mt-10">In the dependencies</h3>
9494
<div>
95-
{results && results.cves && results.cves.length > 0 ? (
95+
{results && results.dep_cves && results.dep_cves.length > 0 ? (
9696
results.dep_cves.map((dep_cves, index) => (
9797
<>
9898
<p key={index} className="text-sm mt-4" style={{ color: 'rgb(179,20,18)' }}>

app/[nsfront]/[nsbehind]/[name]/[version]/versions/page.tsx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,22 @@
33
import React, { useEffect, useState } from 'react';
44

55
import VersionsTable from '@/components/VersionsTable';
6-
import { cratesInfo } from '@/app/lib/all_interface';
6+
// import { VersionsInfo } from '@/app/lib/all_interface';
77
import { useParams } from 'next/navigation';
88

9+
interface VersionInfo {
10+
version: string;
11+
// publishDay: string;
12+
dependents_number: number;
13+
}
914

15+
// interface VersionsTableProps {
16+
// data: VersionInfo[] | undefined;
17+
18+
// }
1019

1120
const CratePage = () => {
12-
const [results, setResults] = useState<cratesInfo | null>(null);
21+
const [results, setResults] = useState<VersionInfo[] | undefined>(undefined);
1322
const [loading, setLoading] = useState(true);
1423
const [error, setError] = useState(null);
1524

@@ -20,7 +29,7 @@ const CratePage = () => {
2029
useEffect(() => {
2130
const fetchCrateData = async () => {
2231
try {
23-
const response = await fetch(`/api/crates/${params.nsfront}/${params.nsbehind}/${params.name}/${params.version}`);
32+
const response = await fetch(`/api/crates/${params.nsfront}/${params.nsbehind}/${params.name}/${params.version}/versions`);
2433

2534
if (!response.ok) {
2635
throw new Error(`HTTP error! status: ${response.status}`);
@@ -40,7 +49,7 @@ const CratePage = () => {
4049
};
4150
fetchCrateData(); // 调用函数来获取数据
4251
}, [params.name, params.version, params.nsfront, params.nsbehind]); // 依赖项数组,确保在 crateName 或 version 改变时重新获取数据
43-
52+
console.log('results in versionsssssss', results);
4453
if (loading) return <div>Loading...</div>;
4554
if (error) return <div className="text-red-500">Error: {error}</div>;
4655

@@ -49,7 +58,7 @@ const CratePage = () => {
4958
return (
5059
<div>
5160

52-
<VersionsTable data={results?.versions} />
61+
<VersionsTable />
5362

5463
</div>
5564
);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
import { NextRequest, NextResponse } from "next/server";
3+
type Params = Promise<{ nsfront: string, nsbehind: string, cratename: string, version: string }>
4+
export async function GET(req: NextRequest, props: { params: Params }) {
5+
try {
6+
const params = await props.params
7+
const { nsfront, nsbehind, cratename, version } = params;
8+
9+
const endpoint = process.env.CRATES_PRO_INTERNAL_HOST;
10+
11+
const externalApiUrl = `${endpoint}/api/crates/${nsfront}/${nsbehind}/${cratename}/${version}/dependencies/graphpage`; // 替换为你的外部 API URL
12+
13+
const externalRes = await fetch(externalApiUrl);
14+
if (!externalRes.ok) {
15+
throw new Error('Failed to fetch external data');
16+
}
17+
const externalData = await externalRes.json();
18+
console.log('graphhhhhhhhhh:', externalData);
19+
return NextResponse.json(externalData);
20+
} catch (error) {
21+
console.error('Error:', error);
22+
return NextResponse.json({ error: 'Internal Server Error' }, { status: 500 });
23+
24+
}
25+
}
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<{ nsfront: string, nsbehind: string, cratename: string, version: string }>
3+
export async function GET(req: NextRequest, props: { params: Params }) {
4+
try {
5+
const params = await props.params
6+
const { nsfront, nsbehind, cratename, version } = params;
7+
const endpoint = process.env.CRATES_PRO_INTERNAL_HOST;
8+
9+
const externalApiUrl = `${endpoint}/api/crates/${nsfront}/${nsbehind}/${cratename}/${version}/versions`; // 替换为你的外部 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+
}

app/homepage/[nsfront]/[nsbehind]/[name]/[version]/dependencies/page.tsx

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

app/homepage/[nsfront]/[nsbehind]/[name]/[version]/dependents/page.tsx

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

0 commit comments

Comments
 (0)