add project deletion in storage & connect to ip port 3000
This commit is contained in:
@ -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 {
|
||||
|
@ -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');
|
||||
|
||||
|
Reference in New Issue
Block a user