diff --git a/backend/database/src/index.ts b/backend/database/src/index.ts
index 1ef42b9..dc51770 100644
--- a/backend/database/src/index.ts
+++ b/backend/database/src/index.ts
@@ -52,6 +52,14 @@ export default {
const id = params.get("id") as string;
await db.delete(usersToSandboxes).where(eq(usersToSandboxes.sandboxId, id));
await db.delete(sandbox).where(eq(sandbox.id, id));
+
+ const deleteStorageRequest = new Request("https://storage.ishaan1013.workers.dev/api/project", {
+ method: "DELETE",
+ body: JSON.stringify({ sandboxId: id }),
+ headers: { "Content-Type": "application/json" },
+ });
+ const deleteStorageRes = await env.STORAGE.fetch(deleteStorageRequest);
+
return success;
} else {
return invalidRequest;
@@ -93,7 +101,7 @@ export default {
});
const initStorageRes = await env.STORAGE.fetch(initStorageRequest);
- const initStorage = await initStorageRes.text();
+ // const initStorage = await initStorageRes.text();
return new Response(sb.id, { status: 200 });
} else {
diff --git a/backend/storage/src/index.ts b/backend/storage/src/index.ts
index c580605..b5dd2b3 100644
--- a/backend/storage/src/index.ts
+++ b/backend/storage/src/index.ts
@@ -16,7 +16,24 @@ export default {
const path = url.pathname;
const method = request.method;
- if (path === '/api/size' && method === 'GET') {
+ if (path === '/api/project' && method === 'DELETE') {
+ const deleteSchema = z.object({
+ sandboxId: z.string(),
+ });
+
+ const body = await request.json();
+ const { sandboxId } = deleteSchema.parse(body);
+
+ const res = await env.R2.list({ prefix: 'projects/' + sandboxId });
+ // delete all files
+ await Promise.all(
+ res.objects.map(async (file) => {
+ await env.R2.delete(file.key);
+ })
+ );
+
+ return success;
+ } else if (path === '/api/size' && method === 'GET') {
const params = url.searchParams;
const sandboxId = params.get('sandboxId');
diff --git a/frontend/components/editor/editor.tsx b/frontend/components/editor/editor.tsx
index a18a149..b155ef4 100644
--- a/frontend/components/editor/editor.tsx
+++ b/frontend/components/editor/editor.tsx
@@ -732,7 +732,7 @@ export default function CodeEditor({
previewPanelRef.current?.expand();
setIsPreviewCollapsed(false);
}}
- sandboxId={sandboxData.id}
+ ip={ip}
/>
diff --git a/frontend/components/editor/preview/index.tsx b/frontend/components/editor/preview/index.tsx
index b937a34..34fbca7 100644
--- a/frontend/components/editor/preview/index.tsx
+++ b/frontend/components/editor/preview/index.tsx
@@ -15,11 +15,11 @@ import { toast } from "sonner";
export default function PreviewWindow({
collapsed,
open,
- sandboxId,
+ ip,
}: {
collapsed: boolean;
open: () => void;
- sandboxId: string;
+ ip: string;
}) {
const ref = useRef(null);
@@ -51,9 +51,7 @@ export default function PreviewWindow({
{
- navigator.clipboard.writeText(
- `http://${sandboxId}.sandbox.ishaand.com`
- );
+ navigator.clipboard.writeText(`http://${ip}:3000`);
toast.info("Copied preview link to clipboard");
}}
>
@@ -79,7 +77,7 @@ export default function PreviewWindow({
ref={ref}
width={"100%"}
height={"100%"}
- src={`http://${sandboxId}.sandbox.ishaand.com`}
+ src={`http://${ip}:3000`}
/>
)}
diff --git a/frontend/lib/utils.ts b/frontend/lib/utils.ts
index c94591c..137d45d 100644
--- a/frontend/lib/utils.ts
+++ b/frontend/lib/utils.ts
@@ -64,36 +64,6 @@ export function addNew(
}
}
-// export async function startServer(
-// sandboxId: string,
-// userId: string,
-// callback: (success: boolean) => void
-// ) {
-// try {
-// const res = await fetch("http://localhost:4001/start", {
-// method: "POST",
-// headers: {
-// "Content-Type": "application/json",
-// },
-// body: JSON.stringify({
-// sandboxId,
-// userId,
-// }),
-// });
-
-// if (res.status !== 200) {
-// console.error("Failed to start server", res);
-// callback(false);
-// }
-
-// callback(true);
-// } catch (error) {
-// console.error("Failed to start server", error);
-
-// callback(false);
-// }
-// }
-
export function checkServiceStatus(serviceName: string): Promise {
return new Promise((resolve, reject) => {
let tries = 0;