diff --git a/app/api/get-share/route.ts b/app/api/get-share/route.ts
new file mode 100644
index 0000000..ba10106
--- /dev/null
+++ b/app/api/get-share/route.ts
@@ -0,0 +1,37 @@
+import { FileContent } from "@/data/db";
+import { getBuildServerBaseUrl } from "@/lib/env";
+import { unzipSync, strFromU8 } from "fflate";
+
+export async function GET(request: Request) {
+ const { searchParams } = new URL(request.url);
+ const id = searchParams.get("id");
+
+ if (!id) {
+ throw new Error("no id");
+ }
+
+ const res = await fetch(
+ `${getBuildServerBaseUrl()}/playground/share/get/${id}`
+ );
+
+ const data = await res.arrayBuffer();
+
+ try {
+ const unzipped = unzipSync(Buffer.from(data));
+
+ let files: FileContent[] = [];
+
+ Object.entries(unzipped).forEach(([k, v]) => {
+ files.push({
+ path: k,
+ contents: strFromU8(v)
+ })
+ })
+
+ return Response.json(files);
+ } catch (err) {
+ if (err instanceof Error) {
+ return Response.json({ message: err.message }, { status: 500 });
+ }
+ }
+}
diff --git a/app/api/share/route.ts b/app/api/share/route.ts
new file mode 100644
index 0000000..7af5a54
--- /dev/null
+++ b/app/api/share/route.ts
@@ -0,0 +1,37 @@
+import { FileContent } from "@/data/db";
+import { getBuildServerBaseUrl } from "@/lib/env";
+import { fileContentToZip } from "@/lib/file-content-to-zip";
+import { type NextRequest } from "next/server";
+import { v4 as uuidv4 } from "uuid";
+
+export async function POST(request: NextRequest) {
+ const { files } = (await request.json()) as { files: FileContent[] };
+
+ const zippedData = fileContentToZip(files);
+
+ const formData = new FormData();
+ const filePath = uuidv4() + ".zip";
+ formData.append(
+ "file",
+ new File([zippedData], filePath, { type: "application/zip" }),
+ filePath
+ );
+
+ const requestInit: RequestInit = {
+ method: "POST",
+ body: formData,
+ redirect: "follow",
+ };
+
+ const response = await fetch(
+ `${getBuildServerBaseUrl()}/playground/share/create`,
+ requestInit
+ );
+
+ if (!response.ok) {
+ const { message } = await response.json();
+ return Response.json({ error: message }, { status: response.status });
+ }
+
+ return Response.json(await response.json());
+}
diff --git a/app/api/test/route.ts b/app/api/test/route.ts
index bebfc3c..3e86d25 100644
--- a/app/api/test/route.ts
+++ b/app/api/test/route.ts
@@ -1,9 +1,8 @@
import { FileContent } from "@/data/db";
-import { getBuildServerBaseUrl, getSolangBuildServerBaseUrl } from "@/lib/env";
+import { getBuildServerBaseUrl } from "@/lib/env";
import { fileContentToZip } from "@/lib/file-content-to-zip";
import { type NextRequest } from "next/server";
import { v4 as uuidv4 } from "uuid";
-import { strFromU8, strToU8 } from "fflate";
export async function POST(request: NextRequest) {
const { files } = (await request.json()) as { files: FileContent[] };
diff --git a/app/layout.tsx b/app/layout.tsx
index 2394bfd..0f5cc7d 100644
--- a/app/layout.tsx
+++ b/app/layout.tsx
@@ -7,6 +7,7 @@ import clsx from "clsx";
import { GoogleAnalytics } from "@next/third-parties/google";
import { getGoogleAnalyticsTag } from "@/lib/env";
import Providers from "@/components/providers";
+import { Toaster } from "@/components/ui/toaster"
const font = Poppins({
weight: ["100", "200", "300", "400", "500", "600", "700", "800", "900"],
@@ -30,6 +31,7 @@ export default function RootLayout({ children }: PropsWithChildren) {
{children}
+