update
This commit is contained in:
@@ -94,6 +94,49 @@ app.post(
|
||||
}),
|
||||
);
|
||||
|
||||
app.delete(
|
||||
"/resources/:filename",
|
||||
verifyToken,
|
||||
asyncHandler(async (req, res) => {
|
||||
try {
|
||||
const { filename } = req.params;
|
||||
|
||||
if (!filename) {
|
||||
return res.status(400).json({ error: "Filename is required" });
|
||||
}
|
||||
|
||||
// Validate filename format (basic security check)
|
||||
if (!filename.match(/^F_S\d+T\d+_RV\d+\.md$/)) {
|
||||
return res.status(400).json({ error: "Invalid filename format" });
|
||||
}
|
||||
|
||||
const filePath = path.join(STATIC_DIR, filename);
|
||||
|
||||
// Check if file exists
|
||||
try {
|
||||
await fs.access(filePath);
|
||||
} catch (error) {
|
||||
return res.status(404).json({ error: "File not found" });
|
||||
}
|
||||
|
||||
// Delete the file
|
||||
await fs.unlink(filePath);
|
||||
|
||||
// Refresh the structure cache
|
||||
const structure = await getStructure({ refresh: true });
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
message: `File ${filename} deleted successfully`,
|
||||
structure,
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
res.status(500).json({ error: "Failed to delete file" });
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
app.use(errorRequestHandler);
|
||||
|
||||
const PORT = process.env.PORT || 3000;
|
||||
|
||||
Reference in New Issue
Block a user