Skip to content

Commit

Permalink
return build errors
Browse files Browse the repository at this point in the history
  • Loading branch information
yongenaelf committed Jul 28, 2024
1 parent e32a703 commit d11c989
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
12 changes: 6 additions & 6 deletions data/build.ts → app/api/build/route.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"use server";

import { FileContent } from "@/data/db";
import { getBuildServerBaseUrl } from "@/lib/env";
import { strToU8, Zippable, zipSync } from "fflate";
import { FileContent } from "./db";
import { type NextRequest } from "next/server";
import { v4 as uuidv4 } from "uuid";

export async function build(files: FileContent[]) {
export async function POST(request: NextRequest) {
const { files } = (await request.json()) as { files: FileContent[] };
const data: Zippable = files.reduce((acc, { path, contents }) => {
acc[path] = strToU8(contents);

Expand Down Expand Up @@ -35,8 +35,8 @@ export async function build(files: FileContent[]) {

if (!response.ok) {
const { message } = await response.json();
throw new Error(message);
return Response.json({ error: message }, { status: response.status });
}

return await response.text();
return Response.json({ dll: await response.text() });
}
1 change: 0 additions & 1 deletion app/workspace/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import { BuildDeployPanel } from "@/components/build-deploy-panel";
import TopBottom from "@/components/top-bottom";
import { Button } from "@/components/ui/button";
import {
ResizablePanelGroup,
ResizablePanel,
Expand Down
13 changes: 8 additions & 5 deletions components/workspace/use-cli-commands.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { build } from "@/data/build";
import { db } from "@/data/db";
import { useWallet } from "@/data/wallet";
import { Loader2 } from "lucide-react";
Expand Down Expand Up @@ -57,9 +56,13 @@ export function useCliCommands() {
);

try {
const str = await build(files);
if (typeof str === "string") {
await db.workspaces.update(id, { dll: str });
const res = await fetch(`/api/build`, {
method: "POST",
body: JSON.stringify({ files }),
});
const { dll, error } = await res.json();
if (typeof dll === "string") {
await db.workspaces.update(id, { dll });
terminalContext.setBufferedContent(
<>
<p>Build successful.</p>
Expand All @@ -70,7 +73,7 @@ export function useCliCommands() {
terminalContext.setBufferedContent(
<>
{terminalContext.bufferedContent}
<p>Build failed.</p>
<p>{error}</p>
</>
);
return;
Expand Down

0 comments on commit d11c989

Please sign in to comment.