Skip to content

Commit cff5f4f

Browse files
CHanges
1 parent 9ad5a86 commit cff5f4f

File tree

2 files changed

+78
-10
lines changed

2 files changed

+78
-10
lines changed

client/src/Components/DasboardComponents/IDE.jsx

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,20 @@ const IDE = () => {
178178
clerkID: user.id,
179179
};
180180

181-
console.log(payload);
182-
183-
const response = await axios.post(`${process.env.REACT_APP_API_URL}/editor/delete`, payload);
184-
if (response.data.success) {
185-
await fetchProjectData();
186-
} else {
187-
console.log(response)
188-
alert(response.data.message);
189-
}
181+
//console.log(payload);
182+
183+
console.log(payload.dirPath.includes('.'))
184+
185+
// const response = await axios.post(`${process.env.REACT_APP_API_URL}/editor/delete`, {
186+
// dirPath: `${projectPath}/${currentFolder}`,
187+
// clerkID: user.id,
188+
// });
189+
// if (response.data.success) {
190+
// await fetchProjectData();
191+
// } else {
192+
// console.log(response)
193+
// alert(response.data.message);
194+
// }
190195
} catch (error) {
191196
console.error('Error deleting folder:', error);
192197
}

server/routes/EditorRouter.js

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,70 @@ EditorRouter.get('/:filePath/:clerkID', ReadfileContents);
66
EditorRouter.post('/save-file', SaveCurrentFile)
77
EditorRouter.post('/new-file', CreateNewFile)
88
EditorRouter.post('/new-folder', CreateNewFolder);
9-
EditorRouter.post('/delete', DeleteController);
9+
// Route to delete a folder
10+
EditorRouter.post('/delete-folder', async (req, res) => {
11+
const { folderPath } = req.body;
12+
13+
try {
14+
// Verify folderPath is provided and is a string
15+
if (!folderPath || typeof folderPath !== 'string') {
16+
return res.status(400).json({ error: 'Invalid folder path' });
17+
}
18+
19+
// Construct absolute path
20+
const absolutePath = path.join(__dirname, folderPath);
21+
22+
// Check if the path exists
23+
const pathExists = await fs.access(absolutePath)
24+
.then(() => true)
25+
.catch(() => false);
26+
27+
if (!pathExists) {
28+
return res.status(404).json({ error: 'Folder not found' });
29+
}
30+
31+
// Delete folder recursively
32+
await fs.rmdir(absolutePath, { recursive: true });
33+
34+
res.json({ message: 'Folder deleted successfully' });
35+
} catch (error) {
36+
console.error('Error deleting folder:', error);
37+
res.status(500).json({ error: 'Internal server error' });
38+
}
39+
});
40+
41+
// Route to delete a file
42+
EditorRouter.post('/delete-file', async (req, res) => {
43+
const { filePath } = req.body;
44+
45+
try {
46+
// Verify filePath is provided and is a string
47+
if (!filePath || typeof filePath !== 'string') {
48+
return res.status(400).json({ error: 'Invalid file path' });
49+
}
50+
51+
// Construct absolute path
52+
const absolutePath = path.join(__dirname, filePath);
53+
54+
// Check if the file exists
55+
const fileExists = await fs.access(absolutePath)
56+
.then(() => true)
57+
.catch(() => false);
58+
59+
if (!fileExists) {
60+
return res.status(404).json({ error: 'File not found' });
61+
}
62+
63+
// Delete the file
64+
await fs.unlink(absolutePath);
65+
66+
res.json({ message: 'File deleted successfully' });
67+
} catch (error) {
68+
console.error('Error deleting file:', error);
69+
res.status(500).json({ error: 'Internal server error' });
70+
}
71+
});
72+
1073
EditorRouter.post('/rename', RenameController);
1174

1275

0 commit comments

Comments
 (0)