Skip to content

Commit 379891f

Browse files
committed
fix component
Signed-off-by: xizheyin <[email protected]>
1 parent dc72d27 commit 379891f

File tree

10 files changed

+92
-109
lines changed

10 files changed

+92
-109
lines changed

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

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,51 @@
1-
// app/api/crates/[name]/[version]/route.ts
21
import { NextRequest, NextResponse } from 'next/server';
32
import pool from '../../../../lib/db';
3+
import { Vulnerability } from '@/components/VulnerabilitiesList';
44

55
interface CrateVersionInfo {
66
name: string;
77
version: string;
88
documentation: string;
99
dependencies: Dependency[];
10+
vulnerabilities: Vulnerability[];
1011
}
1112

1213
interface Dependency {
1314
name: string;
1415
version: string;
1516
}
17+
18+
function generateRandomVulnerabilities(): Vulnerability[] {
19+
const severities: Vulnerability['severity'][] = ['low', 'medium', 'high'];
20+
const randomVulnerabilities: Vulnerability[] = [];
21+
22+
const numberOfVulnerabilities = Math.floor(Math.random() * 5); // 0 to 4 vulnerabilities
23+
24+
for (let i = 0; i < numberOfVulnerabilities; i++) {
25+
const severity = severities[Math.floor(Math.random() * severities.length)];
26+
randomVulnerabilities.push({
27+
id: `vul-${i}`,
28+
title: `Random Vulnerability ${i + 1}`,
29+
description: `This is a randomly generated vulnerability of ${severity} severity.`,
30+
severity,
31+
});
32+
}
33+
34+
return randomVulnerabilities;
35+
}
36+
1637
export async function GET(req: NextRequest, { params }: { params: { name: string, version: string } }) {
1738
const { name, version } = params;
1839
const nameAndVersion = `${name}/${version}`;
1940

2041
try {
2142
const client = await pool.connect();
2243

23-
// 查询 program_versions 表
2444
const versionRes = await client.query(
2545
'SELECT * FROM program_versions WHERE name_and_version = \$1',
2646
[nameAndVersion]
2747
);
2848

29-
// 查询 program_dependencies 表
3049
const dependenciesRes = await client.query(
3150
'SELECT dependency_name, dependency_version FROM program_dependencies WHERE name_and_version = \$1',
3251
[nameAndVersion]
@@ -44,16 +63,19 @@ export async function GET(req: NextRequest, { params }: { params: { name: string
4463
version: row.dependency_version,
4564
}));
4665

66+
const vulnerabilities = generateRandomVulnerabilities();
67+
4768
const crateVersionInfo: CrateVersionInfo = {
4869
name: versionInfo.name,
4970
version: versionInfo.version,
5071
documentation: versionInfo.documentation,
5172
dependencies: dependencies,
73+
vulnerabilities: vulnerabilities
5274
};
5375

5476
return NextResponse.json(crateVersionInfo);
5577
} catch (error) {
5678
console.error('Database query error:', error);
5779
return NextResponse.json({ error: 'Internal Server Error' }, { status: 500 });
5880
}
59-
}
81+
}

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { NextRequest, NextResponse } from 'next/server';
22
import pool from '../../../lib/db';
3+
import { CrateInfo } from '@/app/lib/crate_info';
34

45
export async function GET(req: NextRequest, { params }: { params: { name: string } }) {
56
const { name } = params;
@@ -30,20 +31,20 @@ export async function GET(req: NextRequest, { params }: { params: { name: string
3031

3132
client.release();
3233

34+
const crateInfo: CrateInfo = {
35+
id: programInfo.id,
36+
name: programInfo.name,
37+
//description: programInfo.description,
38+
description: "The ark-curve-constraint-tests crate is a comprehensive testing suite designed for validating the constraint systems of elliptic curves in the Arkworks ecosystem. It ensures that cryptographic curves are implemented correctly and efficiently within constraint systems, which are crucial for zero-knowledge proofs and other cryptographic protocols.",
39+
repository: programInfo.github_url,
40+
documentation: programInfo.doc_url,
41+
downloads: programInfo.downloads,
42+
cratesio: programInfo.cratesio,
43+
publishedDate: '2024.8.24'
44+
}
45+
3346
return NextResponse.json({
34-
crateInfo: {
35-
id: programInfo.id,
36-
name: programInfo.name,
37-
description: programInfo.description,
38-
namespace: programInfo.namespace,
39-
maxVersion: programInfo.max_version,
40-
githubUrl: programInfo.github_url,
41-
megaUrl: programInfo.mega_url,
42-
docUrl: programInfo.doc_url,
43-
programType: programInfo.program_type,
44-
downloads: programInfo.downloads,
45-
cratesio: programInfo.cratesio,
46-
},
47+
crateInfo: crateInfo,
4748
versions: versions, // 添加版本信息
4849
vulnerabilities: [], // 如果有漏洞信息,可以在这里添加查询逻辑
4950
});

app/lib/crate_info.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export interface CrateInfo {
2+
id: string,
3+
name: string;
4+
description: string;
5+
repository: string;
6+
downloads: number;
7+
documentation: string;
8+
cratesio: string
9+
publishedDate: string;
10+
}
11+

app/programs/[name]/[version]/page.tsx

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@ import React, { useEffect, useState } from 'react';
44
import { useParams } from 'next/navigation';
55
import Header from '../../../../components/Header';
66
import Footer from '../../../../components/Footer';
7-
import CrateInfoCard, { CrateInfo } from '../../../../components/CrateInfoCard';
7+
import CrateInfoCard from '../../../../components/CrateInfoCard';
88
import DependenciesList, { Dependency } from '../../../../components/DependenciesList';
99
import DependencyGraph, {GraphDependency} from '../../../../components/DependencyGraph';
1010
import VulnerabilitiesList, { Vulnerability } from '../../../../components/VulnerabilitiesList';
1111
import SecurityAdvisories from '../../../../components/SecurityAdvisories';
12-
import LicensesInfo from '../../../../components/LicensesInfo';
13-
import MetadataSection from '@/components/MetadataSection';
1412
import BenchmarkResults from '../../../../components/BenchmarkResults';
1513
import VersionsSelector from '../../../../components/VersionsSelector';
14+
import { CrateInfo } from '@/app/lib/crate_info';
1615

1716

1817
async function fetchDependencyTree(name: string, version: string) {
@@ -56,7 +55,7 @@ const CratePage = () => {
5655
.then(data => {
5756
setCrateInfo(data.crateInfo || {});
5857
setVersions(data.versions || []);
59-
setVulnerabilities(data.vulnerabilities || []);
58+
6059
setBenchmarks(data.benchmarks || []);
6160
})
6261
.catch(error => {
@@ -65,6 +64,20 @@ const CratePage = () => {
6564

6665
}, [crateName, currentVersion]);
6766

67+
useEffect(()=>{
68+
fetch(`/api/crates/${name}/${version}`)
69+
.then(response => response.json())
70+
.then(data => {
71+
setVulnerabilities(data.vulnerabilities);
72+
setDependencies(data.dependencies);
73+
})
74+
.catch(error => {
75+
console.error('Error fetching data:', error);
76+
});
77+
78+
79+
}, [crateName, currentVersion]);
80+
6881

6982
useEffect(() => {
7083
async function loadDependencies() {
@@ -102,9 +115,8 @@ const CratePage = () => {
102115
<div className="container mx-auto p-2 flex">
103116
<div className="w-full md:w-2/3 pr-2">
104117
<CrateInfoCard crateInfo={crateInfo} />
105-
<LicensesInfo licenses={crateInfo.licenses} dependencyLicenses={crateInfo.dependencyLicenses} />
106-
<MetadataSection publishedDate={crateInfo.publishedDate} description={crateInfo.description} links={crateInfo.links} />
107118
<SecurityAdvisories vulnerabilities={vulnerabilities} />
119+
<VulnerabilitiesList vulnerabilities={vulnerabilities} />
108120
<BenchmarkResults benchmarks={benchmarks} />
109121
</div>
110122
<div className="w-full md:w-1/3 pl-2 border-l-2">
@@ -114,7 +126,7 @@ const CratePage = () => {
114126
crateName={crateInfo.name}
115127
onVersionChange={handleVersionChange}
116128
/>
117-
<VulnerabilitiesList vulnerabilities={vulnerabilities} />
129+
118130
<DependenciesList dependencies={dependencies} onDependencyClick={handleDependencyClick} />
119131
<DependencyGraph crateName={name} currentVersion={version} dependencies={graphDependencies} />
120132
</div>

components/CrateInfoCard.tsx

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,29 @@
1-
export interface CrateInfo {
2-
name: string;
3-
description: string;
4-
repository: string;
5-
downloads: number;
6-
maintainers: Maintainer[];
7-
documentation: string;
8-
publishedDate: string;
9-
licenses: string[];
10-
dependencyLicenses: Record<string, number>;
11-
links: Record<string, string>;
12-
}
13-
interface Maintainer {
14-
name: string;
15-
email: string;
16-
}
1+
import { CrateInfo } from "@/app/lib/crate_info";
2+
173
const CrateInfoCard = ({ crateInfo }: { crateInfo: CrateInfo }) => (
184
<section className="bg-white p-4 mb-2 shadow-lg rounded-lg">
19-
<h3 className="text-xl font-bold mb-2">Crate Infomation</h3>
20-
<p>Name: {crateInfo.name}</p>
21-
<p>Description: {crateInfo.description}</p>
22-
<p>Downloads: {crateInfo.downloads}</p>
5+
<h3 className="text-xl font-bold mb-2">Crate Information</h3>
6+
<div className="space-y-2">
7+
<p className="border border-gray-300 hover:bg-gray-100 hover:border-gray-400 p-2 rounded mb-2"><strong>Name:</strong> {crateInfo.name}</p>
8+
<div className="border border-gray-300 hover:bg-gray-100 hover:border-gray-400 p-2 rounded text-left mb-2">
9+
<p><strong>Description:</strong></p>
10+
<p>{crateInfo.description}</p>
11+
</div>
12+
<p className="border border-gray-300 hover:bg-gray-100 hover:border-gray-400 p-2 rounded mb-2"><strong>Downloads:</strong> {crateInfo.downloads}</p>
13+
<p className="border border-gray-300 hover:bg-gray-100 hover:border-gray-400 p-2 rounded mb-2"><strong>Published:</strong> {crateInfo.publishedDate}</p>
2314
{crateInfo.repository && (
24-
<a href={crateInfo.repository} className="text-blue-500 underline mb-2 inline-block" target="_blank" rel="noopener noreferrer">
15+
<a href={crateInfo.repository} className="text-blue-500 underline mb-2 inline-block border border-gray-300 hover:bg-gray-100 hover:border-gray-400 p-2 rounded" target="_blank" rel="noopener noreferrer">
2516
Repository
2617
</a>
2718
)}
2819
{crateInfo.documentation && (
29-
<a href={crateInfo.documentation} className="text-blue-500 underline mb-2 inline-block ml-4" target="_blank" rel="noopener noreferrer">
20+
<a href={crateInfo.documentation} className="text-blue-500 underline mb-2 inline-block ml-4 border border-gray-300 hover:bg-gray-100 hover:border-gray-400 p-2 rounded" target="_blank" rel="noopener noreferrer">
3021
Documentation
3122
</a>
3223
)}
24+
</div>
3325
</section>
3426
);
3527

28+
3629
export default CrateInfoCard;

components/LicensesInfo.tsx

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

components/MetadataSection.tsx

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

components/SecurityAdvisories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ interface SecurityAdvisoriesProps {
88
const SecurityAdvisories: React.FC<SecurityAdvisoriesProps> = ({ vulnerabilities }) => {
99
return (
1010
<div className="bg-white p-4 mb-2 shadow-lg rounded-lg">
11-
<h2 className="text-xl font-bold mb-2">Security Advisories</h2>
11+
<h2 className="text-xl font-bold mb-2">Testing or Static Analysis Results</h2>
1212
<ul className="list-disc ml-6">
1313
{vulnerabilities.map((vuln, index) => (
1414
<li key={index}>

components/VulnerabilitiesList.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ export interface Vulnerability {
77

88
const VulnerabilitiesList = ({ vulnerabilities }: { vulnerabilities: Vulnerability[] }) => (
99
<section className="bg-white p-4 mb-2 shadow-lg rounded-lg">
10-
<h2 className="text-xl font-semibold mb-2 text-gray-800">Vulnerabilities</h2>
10+
<h2 className="text-xl font-bold mb-2">Vulnerabilities</h2>
1111
{vulnerabilities.length > 0 ? (
12-
<ul className="space-y-6">
12+
<ul className="grid grid-cols-1 md:grid-cols-4 gap-2">
1313
{vulnerabilities.map(vul => (
14-
<li key={vul.id} className="p-6 bg-gray-50 rounded-lg shadow-md border border-gray-200">
15-
<h3 className="text-2xl font-bold mb-2 text-gray-800">{vul.title}</h3>
16-
<p className="text-gray-700 mb-4">{vul.description}</p>
17-
<span className={`inline-block rounded-full px-3 py-1 text-sm font-semibold ${getSeverityColor(vul.severity)}`}>
14+
<li key={vul.id} className="p-4 bg-gray-50 rounded-md shadow-sm border border-gray-200">
15+
<h3 className="text-x font-bold mb-1 text-gray-800">{vul.title}</h3>
16+
<p className="text-gray-600 text-xs mb-2">{vul.description}</p>
17+
<span className={`inline-block rounded-full px-2 py-0.5 text-xs font-semibold ${getSeverityColor(vul.severity)}`}>
1818
{vul.severity}
1919
</span>
2020
</li>

images/demo.png

190 KB
Loading

0 commit comments

Comments
 (0)