diff --git a/packages/canyon-platform/app/api/sourcecode/route.ts b/packages/canyon-platform/app/api/sourcecode/route.ts index 27627e9a..f75ada5c 100644 --- a/packages/canyon-platform/app/api/sourcecode/route.ts +++ b/packages/canyon-platform/app/api/sourcecode/route.ts @@ -2,16 +2,25 @@ // import prisma from "@/lib/prisma"; // import {decompressedData} from "@/utils/zstd"; +import axios from "axios"; + +const owner = "canyon-project"; +const repo = "canyon"; +const path = "packages/canyon-report/src/index.tsx"; +const sha = "f721bf684d49254717e03ca14e53a1b1f8882019"; +const token = "YOUR_PERSONAL_ACCESS_TOKEN"; +const url = `https://api.github.com/repos/${owner}/${repo}/contents/${path}?ref=${sha}`; +const headers = { + // Authorization: `token ${token}`, + // Accept: "application/vnd.github.v3+json", +}; + export async function GET() { - return Response.json({ - data: [ - { - id: "id", - pathWithNamespace: "canyon/canyon", - description: "sss", - lastReported: "2024-04-30", - }, - ], + console.log(url, "url"); + const res = await axios.get(url, { headers }).then((response) => { + return response.data; }); + console.log(res, "res"); + return Response.json(res); } -bb5adc06534d19947e6bfc97e3eeecfd55564bed +// bb5adc06534d19947e6bfc97e3eeecfd55564bed diff --git a/packages/canyon-platform/app/projects/[id]/commits/[sha]/[...filepath]/page.tsx b/packages/canyon-platform/app/projects/[id]/commits/[sha]/[...filepath]/page.tsx index 564b9f40..eae0d5b6 100644 --- a/packages/canyon-platform/app/projects/[id]/commits/[sha]/[...filepath]/page.tsx +++ b/packages/canyon-platform/app/projects/[id]/commits/[sha]/[...filepath]/page.tsx @@ -8,9 +8,18 @@ import useSWR from "swr"; import axios from "axios"; import MainBox from "@/components/main-box"; -// http://localhost:3000/projects/123/commits/xxx/main/nihao/nihao/main.js -// http://localhost:3000/projects/59069994/commits/47bc7263d0ebf506bcfbaa2c053495bfc5d2c74a/src/main.ts +function getDecode(str: string) { + return decodeURIComponent( + atob(str) + .split("") + .map(function (c) { + return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2); + }) + .join(""), + ); +} +// http://localhost:3000/projects/490316875/commits/f721bf684d49254717e03ca14e53a1b1f8882019/src/index.tsx const fetcher = ({ url, params }) => axios .get(url, { @@ -38,6 +47,18 @@ export default function Page() { fetcher, ); + const { data: fileData } = useSWR( + { + url: "/api/sourcecode", + params: { + project_id: id, + sha, + filepath: filePath, + }, + }, + fetcher, + ); + return (

文件路径: {filePath}

@@ -46,6 +67,11 @@ export default function Page() { value={JSON.stringify(data || {}, null, 2)} language={"json"} /> + {/*{JSON.stringify(data||{})}*/} {/*