Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 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
6 changes: 6 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": [
"next/core-web-vitals",
"next/typescript"
]
}
2 changes: 1 addition & 1 deletion app/api/crates/[name]/[version]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export async function GET(req: NextRequest, { params }: { params: { name: string
}

const versionInfo = versionRes.rows[0];
const dependencies = dependenciesRes.rows.map((row: any) => ({
const dependencies = dependenciesRes.rows.map((row) => ({
name: row.dependency_name,
version: row.dependency_version,
}));
Expand Down
2 changes: 1 addition & 1 deletion app/api/crates/[name]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export async function GET(req: NextRequest, { params }: { params: { name: string
[name]
);

const versions = versionsRes.rows.map((row: any) => row.version);
const versions = versionsRes.rows.map((row) => row.version);

client.release();

Expand Down
7 changes: 3 additions & 4 deletions app/api/crates/route.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { NextRequest, NextResponse } from 'next/server';

export async function GET(req: NextRequest) {
export async function GET() {
try {
// 发送 HTTP 请求获取外部数据
const externalApiUrl = 'http://210.28.134.203:6888/crates'; // 替换为你的外部 API URL
const externalApiUrl = 'http://210.28.134.203:6888/api/crates'; // 替换为你的外部 API URL
const externalRes = await fetch(externalApiUrl);

if (!externalRes.ok) {
throw new Error('Failed to fetch external data');
}

const externalData = await externalRes.json();

return NextResponse.json(externalData);
Expand All @@ -18,3 +16,4 @@ export async function GET(req: NextRequest) {
return NextResponse.json({ error: 'Internal Server Error' }, { status: 500 });
}
}

22 changes: 8 additions & 14 deletions app/api/submit/route.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
import { NextResponse } from 'next/server';

export async function POST(request: { json: () => any; }) {
const apiUrl = process.env.API_URL; // 读取环境变量,获取后端服务的基础 URL
const body = await request.json(); // 解析请求体
export async function POST(request: Request) {
const apiUrl = process.env.API_URL; // 读取环境变量
const formData = await request.formData(); // 解析请求体

console.log("Request FormData:", formData);

try {
const response = await fetch(`${apiUrl}/submit`, { //向后端发送服务请求
const response = await fetch(`${apiUrl}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(body), // 将请求体发送到后端
body: formData, // 保持 FormData
});
//请求失败直接返回
if (!response.ok) {
return NextResponse.json({ error: 'Failed to submit data' }, { status: 500 });
}
//解析成功的响应
const result = await response.json();
const result = await response.json(); // 确认返回的是 JSON 格式
return NextResponse.json({ message: 'Submission successful', data: result });
} catch (error) {
return NextResponse.json({ error: 'An error occurred while submitting data.' }, { status: 500 });
Expand Down
19 changes: 19 additions & 0 deletions app/newpage/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import '@/app/ui/global.css';
import { inter } from '@/app/ui/fonts';

export const metadata = {
title: 'cratespro',
description: 'Generated by Next.js',
}

export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
}
89 changes: 89 additions & 0 deletions app/newpage/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import React from 'react';
import '@/app/ui/global.css';


const HomePage = () => {
return (
//紫色渐变
// <div className="min-h-screen bg-gray-900 text-white">
// {/* 头部和搜索部分 */}
// <div className="bg-gradient-to-b from-[#4D004D] to-white">
// <header className="p-4 flex justify-between items-center">
// <div className="text-2xl font-bold">open/source/insights</div>
// <nav>
// <ul className="flex space-x-5">
// <li><a href="#" className="hover:underline">About</a></li>
// <li><a href="#" className="hover:underline">Documentation</a></li>
// <li><a href="#" className="hover:underline">Blog</a></li>
// </ul>
// </nav>
// </header>
// <div className="flex flex-col items-center justify-center h-80">
// <h1 className="text-4xl font-bold mb-4">Understand your dependencies</h1>
// <p className="text-center mb-4">Your software and your users rely not only on the code you write, but also on the code your code depends on, the code that code depends on, and so on.</p>
// <div className="flex items-center mb-4">
// <input
// type="text"
// placeholder="Search for open source packages, advisories and projects"
// className="p-2 border-none rounded-md text-gray-800 w-2/3 max-w-xl"
// />
// <button className="bg-teal-600 text-white rounded-md p-2 ml-2 hover:bg-teal-700">Search</button>
// </div>
// </div>
// </div>


//绿色渐变
< div className="min-h-screen bg-gray-900 text-white" >
<header className="bg-teal-500 p-4 flex justify-between items-center">
<div className="text-2xl font-bold">open/source/insights</div>
<nav>
<ul className="flex space-x-5">
<li><a href="#" className="hover:underline">About</a></li>
<li><a href="#" className="hover:underline">Documentation</a></li>
<li><a href="#" className="hover:underline">Blog</a></li>
</ul>
</nav>
</header>
{/* 搜索部分 */}
<div className="flex flex-col items-center justify-center h-80 bg-gradient-to-b from-teal-500 to-gray-800">
<h1 className="text-4xl font-bold mb-4 ">Understand your dependencies</h1>
<p className="text-center mb-4">Your software and your users rely not only on the code you write, but also on the code your code depends on, the code that code depends on, and so on.</p>
<div className="flex items-center mb-4">
<input
type="text"
placeholder="Search for open source crates"
className="p-2 border-none rounded-md text-gray-800 w-80 max-w-2xl"
/>
<button className="bg-teal-600 text-white rounded-md p-2 ml-2 hover:bg-teal-700">Search</button>
</div>
</div>


{/* 分割线部分 */}
<div className="border-t-4 border-green-500 h-1/4"></div>

{/* 一些介绍 */}
<div className="container mx-auto p-10">
<div className="bg-gray-800 p-5 mb-6 rounded shadow-md">
<h2 className="text-2xl font-semibold">New features in the deps.dev API</h2>
<p className="mt-2">The deps.dev API, which provides free access to the data that powers this website, now has experimental batch and pull support, as well as a new version that comes with a stability guarantee and deprecation policy.</p>
<p className="mt-2">Learn more about the new features on our blog, or get started with the API documentation, and code examples.</p>
</div>

<div className="bg-gray-800 p-5 mb-6 rounded shadow-md">
<h2 className="text-2xl font-semibold">Seeing the big picture can be difficult—but it shouldn't be</h2>
<p className="mt-2">The Open Source Insights page for each package shows the full dependency graph and updates it every day. The information provided can help you make informed decisions about using, building, and maintaining your software.</p>
<p className="mt-2">With Open Source Insights, you can actually see the dependency graph for a package, then isolate the paths to a particular dependency. Or see whether a vulnerability in a dependency might affect your code. Or compare two versions of a package to see how the dependencies have changed in a new release.</p>
</div>

<div className="bg-gray-800 p-5 mb-6 rounded shadow-md">
<h2 className="text-2xl font-semibold">How it works</h2>
<p className="mt-2">The service repeatedly examines sites such as github.com, npmjs.com, and pkg.go.dev to find up-to-date information about open source software packages. Using that information, it builds for each package the full dependency graph from scratch—not just from package lock files—connecting it to the packages it depends on and to those that depend on it. This transitive dependency graph allows problems in any package to be made visible to the owners and users of any software they affect.</p>
</div>
</div>
</div >
);
}

export default HomePage;
72 changes: 72 additions & 0 deletions app/newpage/search/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
"use client";

import { useState } from 'react';

export default function Home() {
const [query, setQuery] = useState('');
// 使用假数据进行测试
const [results, setResults] = useState([
{ crate_name: "tokio", version: "1.41.1", date: "2023-01-01" },
{ crate_name: "tokio", version: "0.1.2", date: "2023-02-01" },
]);

const search = async () => {
// 待替换api
const apiUrl = 'api';

try {
const response = await fetch(apiUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ query }),
});

const data = await response.json();
setResults(data.results);
} catch (error) {
console.error('Error fetching data:', error);
}
};

return (
<div className="min-h-screen bg-gray-100">
<header className="bg-white shadow p-4">
<div className="flex justify-between items-center">
<div className="text-xl font-bold flex items-center space-x-1">
<span>open</span>
<span className="text-green-500">/</span>
<span>source</span>
<span className="text-green-500">/</span>
<span>insights</span>
</div>
<div className="flex items-center space-x-2">
<input
type="text"
className="p-2 border border-gray-300 rounded-l-md focus:outline-none focus:ring-2 focus:ring-blue-500"
placeholder="Search..."
/>
<button className="bg-blue-600 text-white px-4 py-2 rounded-r-md hover:bg-blue-700">
Search
</button>
</div>
</div>
</header>

<div className="max-w-2xl ml-10 p-4">
<div id="results" className="space-y-4">
{results.map((item, index) => (
<div
key={index}
className="p-4 rounded-md hover:bg-blue-100 transition"
>
<strong>{item.crate_name}</strong>
<div>Crate {item.version} Published {item.date}</div>
</div>
))}
</div>
</div>
</div>
);
}
4 changes: 4 additions & 0 deletions app/newpage/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.height-1-3 {
height: 33.3333vh;
/* 使用视口高度的 1/3 */
}
10 changes: 7 additions & 3 deletions app/programs/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,21 @@ interface ObjectData {
interface CVE {
id: string;
description: string;

name: string;
version: string;
}

const ProgramsPage = () => {



const [objects, setObjects] = useState<ObjectData[]>([]); //从接口获取Rust程序数据
const [cveData, setCveData] = useState<CVE[]>([]); //从接口获取CVE数据

//获取数据
useEffect(() => {
fetch('/api/crates') //这里应调用后端接口:GET http://localhost:6888/api/crates (?)
fetch('/api/crates') //这里应调用nextjs路由
.then(response => response.json())
.then(data => {
console.log('Fetched crates data:', data); //调试输出
Expand All @@ -35,15 +39,15 @@ const ProgramsPage = () => {
}
});

fetch('/api/cves') //这里应调用后端接口: GET http://localhost:6888/api/crates/{name} (?)
fetch('/api/cves') //这里应调用nextjs路由
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.text(); // 暂时使用 text() 来调试
})
.then(text => {
console.log('Response text:', text);
//console.log('Response text:', text);
return JSON.parse(text); // 手动解析 JSON
})
.then(data => setCveData(data))
Expand Down
18 changes: 18 additions & 0 deletions app/ui/acme-logo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,29 @@ import { lusitana } from '@/app/ui/fonts';

export default function AcmeLogo() {
return (

<div
className={`${lusitana.className} flex flex-row items-center leading-none text-white`}
// style={{
// backgroundImage: 'url(/School-flag.jpg)', // 替换为您的图片路径
// //backgroundSize: 'cover', // 背景图片覆盖整个容器
// backgroundPosition: 'center', // 背景图片居中对齐
// backgroundSize: '100% 100%',
// backgroundRepeat: 'no-repeat',
// }}
>
{/* <div
className="absolute top-0 left-0 w-full h-full bg-cover bg-center "
style={{
backgroundImage: 'url(/School-flag.jpg)', // 替换为您的实际图片名
}}
/> */}
<FontAwesomeIcon icon={faRust} className="h-12 w-12 mr-2" />
<p className="text-[22px]">Crates Pro</p>


</div>
);
}


2 changes: 1 addition & 1 deletion app/ui/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ input[type='number']::-webkit-inner-spin-button {
input[type='number']::-webkit-outer-spin-button {
-webkit-appearance: none;
margin: 0;
}
}
Loading