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;
|
||||
|
Reference in New Issue
Block a user