fixed trashing and restoring files/folders that were inside parent folders
This commit is contained in:
@@ -63,7 +63,12 @@ class DbUtil {
|
||||
return file;
|
||||
};
|
||||
|
||||
trashFile = async (fileID: string, userID: string) => {
|
||||
trashFile = async (
|
||||
fileID: string,
|
||||
parent: string,
|
||||
parentList: string,
|
||||
userID: string
|
||||
) => {
|
||||
const result = await File.findByIdAndUpdate(
|
||||
{
|
||||
_id: new ObjectId(fileID),
|
||||
@@ -72,6 +77,8 @@ class DbUtil {
|
||||
{
|
||||
$set: {
|
||||
"metadata.trashed": true,
|
||||
"metadata.parent": parent,
|
||||
"metadata.parentList": parentList,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
@@ -183,6 +183,21 @@ class DbUtil {
|
||||
return result;
|
||||
};
|
||||
|
||||
trashFolder = async (folderID: string, userID: string) => {
|
||||
const result = await Folder.findByIdAndUpdate(
|
||||
{
|
||||
_id: new ObjectId(folderID),
|
||||
owner: userID,
|
||||
},
|
||||
{
|
||||
$set: {
|
||||
trashed: true,
|
||||
},
|
||||
}
|
||||
);
|
||||
return result;
|
||||
};
|
||||
|
||||
getMoveFolderList = async (
|
||||
userID: string,
|
||||
parent = "/",
|
||||
|
||||
@@ -10,6 +10,11 @@ import {
|
||||
getQuickListValidationRules,
|
||||
getSuggestedListValidationRules,
|
||||
getThumbnailValidationRules,
|
||||
moveFileValidationRules,
|
||||
renameFileValidationRules,
|
||||
restoreFileValidationRules,
|
||||
trashFileValidationRules,
|
||||
trashMultiValidationRules,
|
||||
} from "../middleware/files/files-middleware";
|
||||
|
||||
const fileController = new FileController();
|
||||
@@ -108,15 +113,40 @@ router.patch(
|
||||
fileController.makeOneTimePublic
|
||||
);
|
||||
|
||||
router.patch("/file-service/rename", auth, fileController.renameFile);
|
||||
router.patch(
|
||||
"/file-service/rename",
|
||||
auth,
|
||||
renameFileValidationRules,
|
||||
fileController.renameFile
|
||||
);
|
||||
|
||||
router.patch("/file-service/move", auth, fileController.moveFile);
|
||||
router.patch(
|
||||
"/file-service/move",
|
||||
auth,
|
||||
moveFileValidationRules,
|
||||
fileController.moveFile
|
||||
);
|
||||
|
||||
router.patch("/file-service/trash", auth, fileController.trashFile);
|
||||
router.patch(
|
||||
"/file-service/trash",
|
||||
auth,
|
||||
trashFileValidationRules,
|
||||
fileController.trashFile
|
||||
);
|
||||
|
||||
router.patch("/file-service/trash-multi", auth, fileController.trashMulti);
|
||||
router.patch(
|
||||
"/file-service/trash-multi",
|
||||
auth,
|
||||
trashMultiValidationRules,
|
||||
fileController.trashMulti
|
||||
);
|
||||
|
||||
router.patch("/file-service/restore", auth, fileController.restoreFile);
|
||||
router.patch(
|
||||
"/file-service/restore",
|
||||
auth,
|
||||
restoreFileValidationRules,
|
||||
fileController.restoreFile
|
||||
);
|
||||
|
||||
router.patch("/file-service/restore-multi", auth, fileController.restoreMulti);
|
||||
|
||||
@@ -139,11 +169,3 @@ router.post(
|
||||
);
|
||||
|
||||
export default router;
|
||||
|
||||
// NO longer needed left for reference
|
||||
|
||||
//router.delete("/file-service/remove/token-video/:tempToken/:uuid", auth, fileController.removeTempToken);
|
||||
//router.get("/file-service/stream-video/:id/:tempToken/:uuid", auth, fileController.streamVideo);
|
||||
//router.get("/file-service/stream-video/:id", auth, fileController.streamVideo);
|
||||
//router.get("/file-service/download/get-token", authFullUser, fileController.getDownloadToken);
|
||||
//router.get("/file-service/download/get-token-video", auth, fileController.getDownloadTokenVideo);
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { param, query, validationResult } from "express-validator";
|
||||
import { body, param, query, validationResult } from "express-validator";
|
||||
import { Request, Response, NextFunction } from "express";
|
||||
import { middlewareValidationFunction } from "../utils/middleware-utils";
|
||||
|
||||
// GET
|
||||
|
||||
export const getThumbnailValidationRules = [
|
||||
param("id").isString().withMessage("ID must be a string"),
|
||||
middlewareValidationFunction,
|
||||
@@ -46,12 +48,6 @@ export const getListValidationRules = [
|
||||
middlewareValidationFunction,
|
||||
];
|
||||
|
||||
export const moveFileValidationRules = [
|
||||
query("fileID").isString().withMessage("Parent must be a string"),
|
||||
query("parentID").isString().withMessage("Parent must be a string"),
|
||||
middlewareValidationFunction,
|
||||
];
|
||||
|
||||
export const getSuggestedListValidationRules = [
|
||||
query("search")
|
||||
.optional()
|
||||
@@ -68,3 +64,32 @@ export const getSuggestedListValidationRules = [
|
||||
.withMessage("Media Mode must be a boolean"),
|
||||
middlewareValidationFunction,
|
||||
];
|
||||
|
||||
// PATCH
|
||||
|
||||
export const renameFileValidationRules = [
|
||||
body("id").isString().withMessage("ID must be a string"),
|
||||
body("title").isString().withMessage("Title must be a string"),
|
||||
middlewareValidationFunction,
|
||||
];
|
||||
|
||||
export const moveFileValidationRules = [
|
||||
body("id").isString().withMessage("FileID must be a string"),
|
||||
body("parentID").isString().optional().withMessage("Parent must be a string"),
|
||||
middlewareValidationFunction,
|
||||
];
|
||||
|
||||
export const trashFileValidationRules = [
|
||||
body("id").isString().withMessage("ID must be a string"),
|
||||
middlewareValidationFunction,
|
||||
];
|
||||
|
||||
export const trashMultiValidationRules = [
|
||||
body("items").isArray().withMessage("Items must be an array"),
|
||||
middlewareValidationFunction,
|
||||
];
|
||||
|
||||
export const restoreFileValidationRules = [
|
||||
body("id").isString().withMessage("ID must be a string"),
|
||||
middlewareValidationFunction,
|
||||
];
|
||||
|
||||
@@ -210,7 +210,24 @@ class MongoFileService {
|
||||
};
|
||||
|
||||
trashFile = async (userID: string, fileID: string) => {
|
||||
const trashedFile = await fileDB.trashFile(fileID, userID);
|
||||
const file = await fileDB.getFileInfo(fileID, userID);
|
||||
|
||||
if (!file) throw new NotFoundError("Trash File Not Found Error");
|
||||
|
||||
let parent = file.metadata.parent;
|
||||
let parentList = file.metadata.parentList;
|
||||
|
||||
if (file.metadata.parent !== "/") {
|
||||
parent = "/";
|
||||
parentList = ["/"].toString();
|
||||
}
|
||||
|
||||
const trashedFile = await fileDB.trashFile(
|
||||
fileID,
|
||||
parent,
|
||||
parentList,
|
||||
userID
|
||||
);
|
||||
if (!trashedFile) throw new NotFoundError("Trash File Not Found Error");
|
||||
return trashedFile;
|
||||
};
|
||||
|
||||
@@ -194,10 +194,16 @@ class FolderService {
|
||||
|
||||
if (!folder) throw new NotFoundError("Trash Folder Not Found Error");
|
||||
|
||||
folder.trashed = true;
|
||||
await folder.save();
|
||||
const parentList = [];
|
||||
|
||||
const parentList = [...folder.parentList, folder._id!.toString()];
|
||||
if (folder.parent !== "/") {
|
||||
await folderDB.moveFolder(folderID, userID, "/", ["/"]);
|
||||
parentList.push("/", folder._id!.toString());
|
||||
} else {
|
||||
parentList.push(...folder.parentList, folder._id!.toString());
|
||||
}
|
||||
|
||||
await folderDB.trashFolder(folderID, userID);
|
||||
|
||||
await folderDB.trashFoldersByParent(parentList, userID);
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ const createQuery = ({
|
||||
query = { ...query, filename: { $gt: startAtName } };
|
||||
}
|
||||
|
||||
if (trashMode) {
|
||||
if (trashMode && parent === "/") {
|
||||
query = { ...query, "metadata.trashed": true };
|
||||
} else {
|
||||
query = { ...query, "metadata.trashed": null };
|
||||
|
||||
Reference in New Issue
Block a user