Skip to content

Commit

Permalink
chore: repo overall update
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangtao25 committed Nov 20, 2024
1 parent f721bf6 commit c3544e8
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 12 deletions.
29 changes: 19 additions & 10 deletions packages/canyon-platform/app/api/sourcecode/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down Expand Up @@ -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 (
<MainBox>
<h1>文件路径: {filePath}</h1>
Expand All @@ -46,6 +67,11 @@ export default function Page() {
value={JSON.stringify(data || {}, null, 2)}
language={"json"}
/>
<Editor
height={"90vh"}
value={getDecode(fileData?.content || "")}
language={"json"}
/>
{/*{JSON.stringify(data||{})}*/}
{/*<Report*/}
{/* reportName={"reportName"}*/}
Expand Down

0 comments on commit c3544e8

Please sign in to comment.