Skip to content

Commit

Permalink
fix: endpoint url
Browse files Browse the repository at this point in the history
  • Loading branch information
yongenaelf committed Aug 8, 2024
1 parent de47fc4 commit 2c95cc7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
21 changes: 15 additions & 6 deletions data/audit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import { FileContent } from "./db";
import { fileContentToZip } from "@/lib/file-content-to-zip";
import { v4 as uuidv4 } from "uuid";

const uploadContractCodeSchema = z.object({ codeHash: z.string() });

export async function uploadContractCode(files: FileContent[]) {
const zippedData = fileContentToZip(files);

const formData = new FormData();
const filePath = uuidv4() + ".zip";
formData.append(
"file",
"contractFiles",
new File([zippedData], filePath, { type: "application/zip" }),
filePath
);
Expand All @@ -23,15 +25,22 @@ export async function uploadContractCode(files: FileContent[]) {
redirect: "follow",
};

const res = await fetch(`/api/audit/uploadContractCode`, requestInit);
const res = await fetch(
`/api/playground/audit/uploadContractCode`,
requestInit
);

const message = await res.text();
const message = await res.clone().text();

if (!res.ok) {
throw new Error(message);
}

return message;
const data = await res.json();

const { codeHash } = uploadContractCodeSchema.parse(data);

return codeHash;
}

const auditSchema = z.object({ reportUrl: z.string() });
Expand All @@ -41,7 +50,7 @@ export function useAudit(auditId?: string, transactionId?: string) {
auditId && transactionId ? `audit-${auditId}-${transactionId}` : undefined,
async () => {
const res = await fetch(
`/api/audit/auditContractCode?auditId=${auditId}&transactionId=${transactionId}`
`/api/playground/audit/auditContractCode?auditId=${auditId}&transactionId=${transactionId}`
);

const data = await res.json();
Expand All @@ -65,7 +74,7 @@ const auditReportSchema = z.record(

export function useAuditReport(auditId?: string) {
return useSWR(auditId ? `audit-report-${auditId}` : undefined, async () => {
const res = await fetch(`/api/audit/report/${auditId}`);
const res = await fetch(`/api/playground/report/${auditId}`);

const data = await res.json();

Expand Down
8 changes: 6 additions & 2 deletions next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ if (process.env.NODE_ENV === "development") {
nextConfig.rewrites = async () => {
return [
{
source: "/api/audit/:path*",
destination: `https://playground-next.test.aelf.dev/api/audit/:path*`,
source: "/api/playground/audit/:path*",
destination: `https://playground-next.test.aelf.dev/api/playground/audit/:path*`,
},
{
source: "/api/playground/report/:path*",
destination: `https://playground-next.test.aelf.dev/api/playground/report/:path*`,
},
];
};
Expand Down

0 comments on commit 2c95cc7

Please sign in to comment.