Skip to content

Commit

Permalink
feat: use redis server
Browse files Browse the repository at this point in the history
  • Loading branch information
yongenaelf committed Nov 5, 2024
1 parent df12937 commit aeff086
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 30 deletions.
4 changes: 2 additions & 2 deletions .env
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
BUILD_SERVER_BASE_URL=https://playground.test.aelf.dev
SOLANG_BUILD_SERVER_BASE_URL=https://playground-next.test.aelf.dev
BUILD_SERVER_BASE_URL=
SOLANG_BUILD_SERVER_BASE_URL=
SOLIDITY_ENABLED=false
GA_TAG=
GITHUB_API_KEY=
4 changes: 2 additions & 2 deletions app/api/build/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export async function POST(request: NextRequest) {
const formData = new FormData();
const filePath = uuidv4() + ".zip";
formData.append(
"contractFiles",
"file",
new File([zippedData], filePath, { type: "application/zip" }),
filePath
);
Expand All @@ -26,7 +26,7 @@ export async function POST(request: NextRequest) {
};

const response = await fetch(
`${getBuildServerBaseUrl()}/playground/build`,
`${getBuildServerBaseUrl()}/build`,
requestInit
);

Expand Down
11 changes: 5 additions & 6 deletions app/api/get-share/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { FileContent } from "@/data/db";
import { unzipBlob } from "@/data/unzip-blob";
import { getBuildServerBaseUrl } from "@/lib/env";
import { unzipSync, strFromU8 } from "fflate";
import { strFromU8 } from "fflate";

export async function GET(request: Request) {
const { searchParams } = new URL(request.url);
Expand All @@ -11,13 +12,11 @@ export async function GET(request: Request) {
}

try {
const res = await fetch(
`${getBuildServerBaseUrl()}/playground/share/get/${id}`
);
const res = await fetch(`${getBuildServerBaseUrl()}/share/get?key=${id}`);

const data = await res.arrayBuffer();
const blob = await res.blob();

const unzipped = unzipSync(Buffer.from(data));
const unzipped = await unzipBlob(blob);

let files: FileContent[] = [];

Expand Down
2 changes: 1 addition & 1 deletion app/api/get-template-data/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export async function GET(request: Request) {
throw new Error("no name");
}

const res = await getTemplateData(id, name);
const res = await getTemplateData(id);

const data = Object.entries(res).map(([key, value]) => ({
path: encodeURIComponent(key),
Expand Down
4 changes: 2 additions & 2 deletions app/api/share/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export async function POST(request: NextRequest) {
};

const response = await fetch(
`${getBuildServerBaseUrl()}/playground/share/create`,
`${getBuildServerBaseUrl()}/share/create`,
requestInit
);

Expand All @@ -33,5 +33,5 @@ export async function POST(request: NextRequest) {
return Response.json({ error: message }, { status: response.status });
}

return Response.json(await response.json());
return Response.json({ id: await response.text() });
}
4 changes: 2 additions & 2 deletions app/api/test/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export async function POST(request: NextRequest) {
const formData = new FormData();
const filePath = uuidv4() + ".zip";
formData.append(
"contractFiles",
"file",
new File([zippedData], filePath, { type: "application/zip" }),
filePath
);
Expand All @@ -25,7 +25,7 @@ export async function POST(request: NextRequest) {
};

const response = await fetch(
`${getBuildServerBaseUrl()}/playground/test`,
`${getBuildServerBaseUrl()}/test`,
requestInit
);

Expand Down
5 changes: 1 addition & 4 deletions components/workspace/format-errors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import { processTestOutput } from "./process-test-output";
export function FormatErrors({ inputString }: { inputString?: string }) {
if (!inputString) return "";
// Detect and remove the dynamic path
const cleanedString = inputString.replace(
/\/tmp\/playground\/[a-f0-9\-]+\//g,
""
);
const cleanedString = inputString.replace(/\/tmp\/[a-f0-9\-]+\//g, "");

// Regular expression to match lines containing errors and warnings
const errorMessages = cleanedString.match(
Expand Down
17 changes: 6 additions & 11 deletions data/template.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
import { getBuildServerBaseUrl } from "@/lib/env";
import { unzipSync } from "fflate";
import { unzipBlob } from "./unzip-blob";

export async function getTemplateData(id: string, name: string = "test") {
const res = await fetch(
`${getBuildServerBaseUrl()}/playground/template?template=${id}&projectName=${name}`
);
export async function getTemplateData(id: string) {
const res = await fetch(`${getBuildServerBaseUrl()}/template?template=${id}`);

const data = await res.text();

const zipData = Buffer.from(data, "base64");

return unzipSync(zipData);
const blob = await res.blob();
return unzipBlob(blob);
}

export async function getTemplateNames() {
const res = await fetch(`${getBuildServerBaseUrl()}/playground/templates`);
const res = await fetch(`${getBuildServerBaseUrl()}/templates`);
const data = await res.json();

return data as string[];
Expand Down
6 changes: 6 additions & 0 deletions data/unzip-blob.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { unzipSync } from "fflate";

export async function unzipBlob(blob: Blob) {
const arrayBuffer = await blob.arrayBuffer();
return unzipSync(new Uint8Array(arrayBuffer));
}

0 comments on commit aeff086

Please sign in to comment.