Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const CratePage = () => {
try {
setError(null);
const response = await fetch(
`/api/crates/${params.nsfront}/${params.nsbehind}/${params.name}/${params.version}/dependencies`
`/api/crates/${params.nsfront}/${params.nsbehind}/${params.name}/${params.version}/dependencies/graphpage`
);

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

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



<DependencyGraph crateName={params.name as string} currentVersion={params.version as string} />
<DependencyGraph />

</div>
);
Expand Down
25 changes: 25 additions & 0 deletions app/[nsfront]/[nsbehind]/[name]/[version]/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use client';

import React from 'react';
import { useParams } from 'next/navigation';
import CrateNav from '@/components/CrateNav';

export default function Layout({
children,
}: {
children: React.ReactNode;
}) {
const params = useParams();

return (
<div>
<CrateNav
nsfront={params.nsfront as string}
nsbehind={params.nsbehind as string}
name={params.name as string}
version={params.version as string}
/>
{children}
</div>
);
}
4 changes: 2 additions & 2 deletions app/[nsfront]/[nsbehind]/[name]/[version]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const CratePage = () => {

fetchCrateData();
}, [params.name, params.version, params.nsfront, params.nsbehind]);

console.log('results in overviewwwwwwwww:', results);
if (loading) return <p>Loading...</p>;
if (error) return <p>Error: {error}</p>;

Expand Down Expand Up @@ -92,7 +92,7 @@ const CratePage = () => {

<h3 className="text-xl mt-10">In the dependencies</h3>
<div>
{results && results.cves && results.cves.length > 0 ? (
{results && results.dep_cves && results.dep_cves.length > 0 ? (
results.dep_cves.map((dep_cves, index) => (
<>
<p key={index} className="text-sm mt-4" style={{ color: 'rgb(179,20,18)' }}>
Expand Down
19 changes: 14 additions & 5 deletions app/[nsfront]/[nsbehind]/[name]/[version]/versions/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,22 @@
import React, { useEffect, useState } from 'react';

import VersionsTable from '@/components/VersionsTable';
import { cratesInfo } from '@/app/lib/all_interface';
// import { VersionsInfo } from '@/app/lib/all_interface';
import { useParams } from 'next/navigation';

interface VersionInfo {
version: string;
// publishDay: string;
dependents_number: number;
}

// interface VersionsTableProps {
// data: VersionInfo[] | undefined;

// }

const CratePage = () => {
const [results, setResults] = useState<cratesInfo | null>(null);
const [results, setResults] = useState<VersionInfo[] | undefined>(undefined);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);

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

if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
Expand All @@ -40,7 +49,7 @@ const CratePage = () => {
};
fetchCrateData(); // 调用函数来获取数据
}, [params.name, params.version, params.nsfront, params.nsbehind]); // 依赖项数组,确保在 crateName 或 version 改变时重新获取数据

console.log('results in versionsssssss', results);
if (loading) return <div>Loading...</div>;
if (error) return <div className="text-red-500">Error: {error}</div>;

Expand All @@ -49,7 +58,7 @@ const CratePage = () => {
return (
<div>

<VersionsTable data={results?.versions} />
<VersionsTable />

</div>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

import { NextRequest, NextResponse } from "next/server";
type Params = Promise<{ nsfront: string, nsbehind: string, cratename: string, version: string }>
export async function GET(req: NextRequest, props: { params: Params }) {
try {
const params = await props.params
const { nsfront, nsbehind, cratename, version } = params;

const endpoint = process.env.CRATES_PRO_INTERNAL_HOST;

const externalApiUrl = `${endpoint}/api/crates/${nsfront}/${nsbehind}/${cratename}/${version}/dependencies/graphpage`; // 替换为你的外部 API URL

const externalRes = await fetch(externalApiUrl);
if (!externalRes.ok) {
throw new Error('Failed to fetch external data');
}
const externalData = await externalRes.json();
console.log('graphhhhhhhhhh:', externalData);
return NextResponse.json(externalData);
} catch (error) {
console.error('Error:', error);
return NextResponse.json({ error: 'Internal Server Error' }, { status: 500 });

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { NextRequest, NextResponse } from "next/server";
type Params = Promise<{ nsfront: string, nsbehind: string, cratename: string, version: string }>
export async function GET(req: NextRequest, props: { params: Params }) {
try {
const params = await props.params
const { nsfront, nsbehind, cratename, version } = params;
const endpoint = process.env.CRATES_PRO_INTERNAL_HOST;

const externalApiUrl = `${endpoint}/api/crates/${nsfront}/${nsbehind}/${cratename}/${version}/versions`; // 替换为你的外部 API URL
const externalRes = await fetch(externalApiUrl);
if (!externalRes.ok) {
throw new Error('Failed to fetch external data');
}
const externalData = await externalRes.json();
console.log('External API Response:', externalData);
return NextResponse.json(externalData);
} catch (error) {
console.error('Error:', error);
return NextResponse.json({ error: 'Internal Server Error' }, { status: 500 });

}
}

This file was deleted.

This file was deleted.

Loading
Loading