delete file ui + logic
This commit is contained in:
13
backend/server/dist/index.js
vendored
13
backend/server/dist/index.js
vendored
@ -129,6 +129,19 @@ io.on("connection", (socket) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
});
|
||||
yield (0, utils_1.renameFile)(fileId, newFileId, file.data);
|
||||
}));
|
||||
socket.on("deleteFile", (fileId, callback) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const file = sandboxFiles.fileData.find((f) => f.id === fileId);
|
||||
if (!file)
|
||||
return;
|
||||
fs_1.default.unlink(path_1.default.join(dirName, fileId), function (err) {
|
||||
if (err)
|
||||
throw err;
|
||||
});
|
||||
sandboxFiles.fileData = sandboxFiles.fileData.filter((f) => f.id !== fileId);
|
||||
yield (0, utils_1.deleteFile)(fileId);
|
||||
const newFiles = yield (0, utils_1.getSandboxFiles)(data.id);
|
||||
callback(newFiles.files);
|
||||
}));
|
||||
socket.on("createTerminal", ({ id }) => {
|
||||
console.log("creating terminal, id=" + id);
|
||||
const pty = (0, node_pty_1.spawn)(os_1.default.platform() === "win32" ? "cmd.exe" : "bash", [], {
|
||||
|
13
backend/server/dist/utils.js
vendored
13
backend/server/dist/utils.js
vendored
@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.saveFile = exports.renameFile = exports.createFile = exports.getSandboxFiles = void 0;
|
||||
exports.deleteFile = exports.saveFile = exports.renameFile = exports.createFile = exports.getSandboxFiles = void 0;
|
||||
const getSandboxFiles = (id) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const sandboxRes = yield fetch(`https://storage.ishaan1013.workers.dev/api?sandboxId=${id}`);
|
||||
const sandboxData = yield sandboxRes.json();
|
||||
@ -110,3 +110,14 @@ const saveFile = (fileId, data) => __awaiter(void 0, void 0, void 0, function* (
|
||||
return res.ok;
|
||||
});
|
||||
exports.saveFile = saveFile;
|
||||
const deleteFile = (fileId) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const res = yield fetch(`https://storage.ishaan1013.workers.dev/api`, {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({ fileId }),
|
||||
});
|
||||
return res.ok;
|
||||
});
|
||||
exports.deleteFile = deleteFile;
|
||||
|
@ -8,7 +8,13 @@ import { Server } from "socket.io"
|
||||
|
||||
import { z } from "zod"
|
||||
import { User } from "./types"
|
||||
import { createFile, getSandboxFiles, renameFile, saveFile } from "./utils"
|
||||
import {
|
||||
createFile,
|
||||
deleteFile,
|
||||
getSandboxFiles,
|
||||
renameFile,
|
||||
saveFile,
|
||||
} from "./utils"
|
||||
import { IDisposable, IPty, spawn } from "node-pty"
|
||||
|
||||
dotenv.config()
|
||||
@ -148,6 +154,21 @@ io.on("connection", async (socket) => {
|
||||
await renameFile(fileId, newFileId, file.data)
|
||||
})
|
||||
|
||||
socket.on("deleteFile", async (fileId: string, callback) => {
|
||||
const file = sandboxFiles.fileData.find((f) => f.id === fileId)
|
||||
if (!file) return
|
||||
|
||||
fs.unlink(path.join(dirName, fileId), function (err) {
|
||||
if (err) throw err
|
||||
})
|
||||
sandboxFiles.fileData = sandboxFiles.fileData.filter((f) => f.id !== fileId)
|
||||
|
||||
await deleteFile(fileId)
|
||||
|
||||
const newFiles = await getSandboxFiles(data.id)
|
||||
callback(newFiles.files)
|
||||
})
|
||||
|
||||
socket.on("createTerminal", ({ id }: { id: string }) => {
|
||||
console.log("creating terminal, id=" + id)
|
||||
const pty = spawn(os.platform() === "win32" ? "cmd.exe" : "bash", [], {
|
||||
|
@ -123,3 +123,14 @@ export const saveFile = async (fileId: string, data: string) => {
|
||||
})
|
||||
return res.ok
|
||||
}
|
||||
|
||||
export const deleteFile = async (fileId: string) => {
|
||||
const res = await fetch(`https://storage.ishaan1013.workers.dev/api`, {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({ fileId }),
|
||||
})
|
||||
return res.ok
|
||||
}
|
||||
|
Reference in New Issue
Block a user