file saving
This commit is contained in:
18
backend/server/dist/index.js
vendored
18
backend/server/dist/index.js
vendored
@ -70,21 +70,23 @@ io.on("connection", (socket) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const file = sandboxFiles.fileData.find((f) => f.id === fileId);
|
||||
if (!file)
|
||||
return;
|
||||
console.log("file " + file.id + ": ", file.data);
|
||||
callback(file.data);
|
||||
});
|
||||
socket.on("saveFile", (activeId, body, callback) => {
|
||||
// const file = sandboxFiles.fileData.find((f) => f.id === fileId)
|
||||
// if (!file) return
|
||||
// console.log("file " + file.id + ": ", file.data)
|
||||
// callback(file.data)
|
||||
});
|
||||
// todo: send diffs + debounce for efficiency
|
||||
socket.on("saveFile", (fileId, body) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const file = sandboxFiles.fileData.find((f) => f.id === fileId);
|
||||
if (!file)
|
||||
return;
|
||||
file.data = body;
|
||||
console.log("save file " + file.id + ": ", file.data);
|
||||
yield (0, utils_1.saveFile)(fileId, body);
|
||||
}));
|
||||
socket.on("renameFile", (fileId, newName) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const file = sandboxFiles.fileData.find((f) => f.id === fileId);
|
||||
if (!file)
|
||||
return;
|
||||
yield (0, utils_1.renameFile)(fileId, newName, file.data);
|
||||
file.id = newName;
|
||||
yield (0, utils_1.renameFile)(fileId, newName, file.data);
|
||||
}));
|
||||
}));
|
||||
httpServer.listen(port, () => {
|
||||
|
15
backend/server/dist/utils.js
vendored
15
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.renameFile = exports.getSandboxFiles = void 0;
|
||||
exports.saveFile = exports.renameFile = 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();
|
||||
@ -47,7 +47,7 @@ const processFiles = (paths, id) => __awaiter(void 0, void 0, void 0, function*
|
||||
}
|
||||
else {
|
||||
const folder = {
|
||||
id: path, // issue todo: for example, folder "src" ID is: projects/a7vgttfqbgy403ratp7du3ln/src/App.css
|
||||
id: path, // todo: wrong id. for example, folder "src" ID is: projects/a7vgttfqbgy403ratp7du3ln/src/App.css
|
||||
type: "folder",
|
||||
name: part,
|
||||
children: [],
|
||||
@ -90,3 +90,14 @@ const renameFile = (fileId, newName, data) => __awaiter(void 0, void 0, void 0,
|
||||
return res.ok;
|
||||
});
|
||||
exports.renameFile = renameFile;
|
||||
const saveFile = (fileId, data) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const res = yield fetch(`https://storage.ishaan1013.workers.dev/api/save`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({ fileId, data }),
|
||||
});
|
||||
return res.ok;
|
||||
});
|
||||
exports.saveFile = saveFile;
|
||||
|
Reference in New Issue
Block a user