(FEAT): Can no delete, but it is buggy.
It selects the first element after a delete, not sure why and don't want to worry about it right now.
This commit is contained in:
parent
4cd88c6505
commit
b31626dce9
@ -308,6 +308,20 @@ v1.post("/create", (req: Request, res: Response): void => {
|
|||||||
res.status(201).json({ code: 201, message: "Success" });
|
res.status(201).json({ code: 201, message: "Success" });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
v1.post("/delete", (req: Request, res: Response): void => {
|
||||||
|
// Get the array of paths and the root
|
||||||
|
const { files, root } = req.body;
|
||||||
|
|
||||||
|
// Delete the files
|
||||||
|
// NOTE: These are not moved somewhere, they're just raw deleted
|
||||||
|
for (const file of files) {
|
||||||
|
const absPath = "/" + path.join(...file);
|
||||||
|
rmSync(absPath, { recursive: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
res.status(201).json({ code: 201, message: `Deleted ${files.length} files.` });
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Files are not deleted from the file system, just moved to a hidden folder where
|
* Files are not deleted from the file system, just moved to a hidden folder where
|
||||||
* they can be recovered if needed.
|
* they can be recovered if needed.
|
||||||
|
|||||||
@ -58,7 +58,7 @@ export default function Dashboard() {
|
|||||||
return t;
|
return t;
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
const fetchFiles = () => {
|
||||||
const getData = async (token) => {
|
const getData = async (token) => {
|
||||||
const response = await fetch(`${backendUrl}/v1/children?path=/${path.join("/")}`, {
|
const response = await fetch(`${backendUrl}/v1/children?path=/${path.join("/")}`, {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
@ -90,7 +90,10 @@ export default function Dashboard() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
setSelected([]);
|
setSelected([]);
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
fetchFiles();
|
||||||
}, [path, uploading, creating]);
|
}, [path, uploading, creating]);
|
||||||
|
|
||||||
|
|
||||||
@ -398,7 +401,7 @@ export default function Dashboard() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const remove = async (files) => {
|
const remove = async (files) => {
|
||||||
const resp = await fetch(`${backendUrl}/v1/remove`, {
|
const resp = await fetch(`${backendUrl}/v1/delete`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@ -426,6 +429,9 @@ export default function Dashboard() {
|
|||||||
if (data.code === 201) {
|
if (data.code === 201) {
|
||||||
console.log(data);
|
console.log(data);
|
||||||
setSelected([]);
|
setSelected([]);
|
||||||
|
|
||||||
|
// Fetch the new files & deselect everything
|
||||||
|
fetchFiles();
|
||||||
}
|
}
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
setError(error);
|
setError(error);
|
||||||
|
|||||||
Reference in New Issue
Block a user