more renaming and project structure changes

This commit is contained in:
subnub
2024-08-10 01:28:31 -04:00
parent cfe99132c0
commit 5c59a4baad
18 changed files with 88 additions and 97 deletions
@@ -1,5 +1,5 @@
import mongoose from "mongoose";
import env from "../enviroment/env";
import env from "../../enviroment/env";
import fs from "fs";
const DBUrl = env.mongoURL as string;
@@ -1,5 +1,5 @@
import mongoose from "mongoose";
import env from "../enviroment/env";
import env from "../../enviroment/env";
mongoose.connect(env.mongoURL!, {
socketTimeoutMS: 30000000,
+12
View File
@@ -0,0 +1,12 @@
import AWS from "aws-sdk";
import env from "../../enviroment/env";
AWS.config.update({
accessKeyId: env.s3ID,
secretAccessKey: env.s3Key,
});
const s3 = new AWS.S3();
export default s3;
module.exports = s3;
@@ -1,8 +1,8 @@
import mongoose from "../../mongoose";
import mongoose from "../connections/mongoose";
import { ObjectId } from "mongodb";
import File from "../../../models/file";
import { UserInterface } from "../../../models/user";
import { QueryInterface } from "../../../utils/createQuery";
import File from "../../models/file";
import { UserInterface } from "../../models/user";
import { QueryInterface } from "../../utils/createQuery";
class DbUtil {
constructor() {}
@@ -1,4 +1,4 @@
import Folder, { FolderInterface } from "../../../models/folder";
import Folder, { FolderInterface } from "../../models/folder";
import { ObjectId } from "mongodb";
class DbUtil {
-12
View File
@@ -1,12 +0,0 @@
import AWS from "aws-sdk";
import env from "../enviroment/env";
AWS.config.update({
accessKeyId: env.s3ID,
secretAccessKey: env.s3Key
});
const s3 = new AWS.S3();
export default s3;
module.exports = s3;
@@ -1,4 +1,4 @@
import s3 from "../../../db/s3";
import s3 from "../../../db/connections/s3";
import env from "../../../enviroment/env";
import { GenericParams, IStorageActions } from "./../StoreTypes";
import internal from "stream";
+14 -20
View File
@@ -7,8 +7,8 @@ import getBusboyData from "./utils/getBusboyData";
import videoChecker from "../../utils/videoChecker";
import uuid from "uuid";
import File, { FileInterface } from "../../models/file";
import DbUtilFile from "../../db/utils/fileUtils/index";
import DbUtilFolder from "../../db/utils/folderUtils/index";
import FileDB from "../../db/mongoDB/fileDB";
import FolderDB from "../../db/mongoDB/folderDB";
import Thumbnail, { ThumbnailInterface } from "../../models/thumbnail";
import User from "../../models/user";
import env from "../../enviroment/env";
@@ -20,8 +20,8 @@ import { S3Actions } from "./Actions/S3Actions";
import { FilesystemActions } from "./Actions/FileSystemActions";
import { createGenericParams } from "./utils/storageHelper";
const dbUtilsFile = new DbUtilFile();
const dbUtilsFolder = new DbUtilFolder();
const fileDB = new FileDB();
const folderDB = new FolderDB();
const storageActions =
env.dbType === "s3" ? new S3Actions() : new FilesystemActions();
@@ -52,7 +52,7 @@ class StorageService {
const parentList = [];
if (parent !== "/") {
const parentFolder = await dbUtilsFolder.getFolderInfo(
const parentFolder = await folderDB.getFolderInfo(
parent,
user._id.toString()
);
@@ -96,10 +96,7 @@ class StorageService {
};
downloadFile = async (user: UserInterface, fileID: string, res: Response) => {
const currentFile = await dbUtilsFile.getFileInfo(
fileID,
user._id.toString()
);
const currentFile = await fileDB.getFileInfo(fileID, user._id.toString());
if (!currentFile) throw new NotFoundError("Download File Not Found");
@@ -162,7 +159,7 @@ class StorageService {
getFullThumbnail = async (user: UserInterface, fileID: string) => {
const userID = user._id;
const file = await dbUtilsFile.getFileInfo(fileID, userID.toString());
const file = await fileDB.getFileInfo(fileID, userID.toString());
if (!file) throw new NotFoundError("File Thumbnail Not Found");
@@ -192,10 +189,7 @@ class StorageService {
streamVideo = async (user: UserInterface, fileID: string, headers: any) => {
const userID = user._id;
const currentFile = await dbUtilsFile.getFileInfo(
fileID,
userID.toString()
);
const currentFile = await fileDB.getFileInfo(fileID, userID.toString());
if (!currentFile) throw new NotFoundError("Video File Not Found");
@@ -268,14 +262,14 @@ class StorageService {
};
getPublicDownload = async (fileID: string, tempToken: any, res: Response) => {
const file = await dbUtilsFile.getPublicFile(fileID);
const file = await fileDB.getPublicFile(fileID);
if (!file || !file.metadata.link || file.metadata.link !== tempToken) {
throw new NotAuthorizedError("File Not Public");
}
if (file.metadata.linkType === "one") {
await dbUtilsFile.removeOneTimePublicLink(fileID);
await fileDB.removeOneTimePublicLink(fileID);
}
const user = (await User.findById(file.metadata.owner)) as UserInterface;
@@ -332,7 +326,7 @@ class StorageService {
};
deleteFile = async (userID: string, fileID: string) => {
const file = await dbUtilsFile.getFileInfo(fileID, userID);
const file = await fileDB.getFileInfo(fileID, userID);
if (!file) throw new NotFoundError("Delete File Not Found Error");
@@ -361,7 +355,7 @@ class StorageService {
};
deleteFolder = async (userID: string, folderID: string) => {
const folder = await dbUtilsFolder.getFolderInfo(folderID, userID);
const folder = await folderDB.getFolderInfo(folderID, userID);
if (!folder) throw new NotFoundError("Delete Folder Not Found Error");
@@ -373,7 +367,7 @@ class StorageService {
});
await Folder.deleteMany({ owner: userID, _id: folderID });
const fileList = await dbUtilsFile.getFileListByIncludedParent(
const fileList = await fileDB.getFileListByIncludedParent(
userID,
parentList.toString()
);
@@ -419,7 +413,7 @@ class StorageService {
deleteAll = async (userID: string) => {
await Folder.deleteMany({ owner: userID });
const fileList = await dbUtilsFile.getFileListByOwner(userID);
const fileList = await fileDB.getFileListByOwner(userID);
if (!fileList)
throw new NotFoundError("Delete All File List Not Found Error");
@@ -1,5 +1,5 @@
import { ManagedUpload } from "aws-sdk/clients/s3";
import s3 from "../../../db/s3";
import s3 from "../../../db/connections/s3";
const uploadStreamS3 = (params: any) => {
return new Promise<void>((resolve, reject) => {
@@ -1,4 +1,4 @@
import mongoose from "../../../db/mongoose";
import mongoose from "../../../db/connections/mongoose";
import crypto from "crypto";
import Thumbnail from "../../../models/thumbnail";
import sharp from "sharp";
@@ -1,4 +1,4 @@
import mongoose from "../../../db/mongoose";
import mongoose from "../../../db/connections/mongoose";
import crypto from "crypto";
import Thumbnail from "../../../models/thumbnail";
import sharp from "sharp";
@@ -1,4 +1,4 @@
import mongoose from "../../../db/mongoose";
import mongoose from "../../../db/connections/mongoose";
import crypto from "crypto";
import Thumbnail from "../../../models/thumbnail";
import sharp from "sharp";
@@ -6,7 +6,7 @@ import { FileInterface } from "../../../models/file";
import { UserInterface } from "../../../models/user";
import uuid from "uuid";
import env from "../../../enviroment/env";
import s3 from "../../../db/s3";
import s3 from "../../../db/connections/s3";
import { ObjectId } from "mongodb";
const conn = mongoose.connection;
@@ -1,4 +1,4 @@
import mongoose from "../../../db/mongoose";
import mongoose from "../../../db/connections/mongoose";
import crypto from "crypto";
import Thumbnail from "../../../models/thumbnail";
import sharp from "sharp";
@@ -1,4 +1,4 @@
import mongoose from "../../../db/mongoose";
import mongoose from "../../../db/connections/mongoose";
import crypto from "crypto";
import Thumbnail from "../../../models/thumbnail";
import sharp from "sharp";
@@ -1,4 +1,4 @@
import mongoose from "../../../db/mongoose";
import mongoose from "../../../db/connections/mongoose";
import crypto from "crypto";
import Thumbnail from "../../../models/thumbnail";
import sharp from "sharp";
@@ -1,4 +1,4 @@
import mongoose from "../../../db/mongoose";
import mongoose from "../../../db/connections/mongoose";
import crypto from "crypto";
import Thumbnail from "../../../models/thumbnail";
import sharp from "sharp";
+21 -24
View File
@@ -5,15 +5,15 @@ import jwt from "jsonwebtoken";
import Folder, { FolderInterface } from "../../models/folder";
import sortBySwitch from "../../utils/sortBySwitch";
import createQuery from "../../utils/createQuery";
import DbUtilFile from "../../db/utils/fileUtils/index";
import DbUtilFolder from "../../db/utils/folderUtils";
import FileDB from "../../db/mongoDB/fileDB";
import FolderDB from "../../db/mongoDB/folderDB";
import { UserInterface } from "../../models/user";
import { FileInterface } from "../../models/file";
import tempStorage from "../../tempStorage/tempStorage";
import FolderService from "../FolderService";
const dbUtilsFile = new DbUtilFile();
const dbUtilsFolder = new DbUtilFolder();
const fileDB = new FileDB();
const folderDB = new FolderDB();
const folderService = new FolderService();
type userAccessType = {
@@ -31,12 +31,12 @@ class MongoFileService {
if (!fileID) return;
if (currentFile.metadata.linkType === "one") {
await dbUtilsFile.removeOneTimePublicLink(fileID);
await fileDB.removeOneTimePublicLink(fileID);
}
};
removeLink = async (userID: string, fileID: string) => {
const file = await dbUtilsFile.removeLink(fileID, userID);
const file = await fileDB.removeLink(fileID, userID);
if (!file) throw new NotFoundError("Remove Link File Not Found Error");
@@ -46,7 +46,7 @@ class MongoFileService {
makePublic = async (userID: string, fileID: string) => {
const token = jwt.sign({ _id: userID.toString() }, env.passwordAccess!);
const file = await dbUtilsFile.makePublic(fileID, userID, token);
const file = await fileDB.makePublic(fileID, userID, token);
if (!file) throw new NotFoundError("Make Public File Not Found Error");
@@ -54,7 +54,7 @@ class MongoFileService {
};
getPublicInfo = async (fileID: string, tempToken: string) => {
const file = await dbUtilsFile.getPublicInfo(fileID, tempToken);
const file = await fileDB.getPublicInfo(fileID, tempToken);
if (!file || !file.metadata.link || file.metadata.link !== tempToken) {
throw new NotFoundError("Public Info Not Found");
@@ -66,7 +66,7 @@ class MongoFileService {
makeOneTimePublic = async (userID: string, fileID: string) => {
const token = jwt.sign({ _id: userID.toString() }, env.passwordAccess!);
const file = await dbUtilsFile.makeOneTimePublic(fileID, userID, token);
const file = await fileDB.makeOneTimePublic(fileID, userID, token);
if (!file) throw new NotFoundError("Make One Time Public Not Found Error");
@@ -74,7 +74,7 @@ class MongoFileService {
};
getFileInfo = async (userID: string, fileID: string) => {
let currentFile = await dbUtilsFile.getFileInfo(fileID, userID);
let currentFile = await fileDB.getFileInfo(fileID, userID);
if (!currentFile) throw new NotFoundError("Get File Info Not Found Error");
@@ -106,7 +106,7 @@ class MongoFileService {
) => {
const userID = user._id;
const quickList = await dbUtilsFile.getQuickList(userID.toString(), +limit);
const quickList = await fileDB.getQuickList(userID.toString(), +limit);
if (!quickList) throw new NotFoundError("Quick List Not Found Error");
@@ -148,7 +148,7 @@ class MongoFileService {
mediaMode
);
const fileList = await dbUtilsFile.getList(queryObj, sortBy, limit);
const fileList = await fileDB.getList(queryObj, sortBy, limit);
if (!fileList) throw new NotFoundError("File List Not Found");
@@ -190,10 +190,7 @@ class MongoFileService {
const encryptedToken = user.encryptToken(tempToken, key, publicKey);
const removedTokenUser = await dbUtilsFile.removeTempToken(
user,
encryptedToken
);
const removedTokenUser = await fileDB.removeTempToken(user, encryptedToken);
if (!removedTokenUser)
throw new NotFoundError("Remove Temp Token User Not Found Errors");
@@ -211,7 +208,7 @@ class MongoFileService {
) => {
searchQuery = new RegExp(searchQuery, "i");
const fileList = await dbUtilsFile.getFileSearchList(
const fileList = await fileDB.getFileSearchList(
userID,
searchQuery,
trashMode,
@@ -227,7 +224,7 @@ class MongoFileService {
};
}
const folderList = await dbUtilsFolder.getFolderSearchList(
const folderList = await folderDB.getFolderSearchList(
userID,
searchQuery,
trashMode
@@ -242,7 +239,7 @@ class MongoFileService {
};
trashFile = async (userID: string, fileID: string) => {
const trashedFile = await dbUtilsFile.trashFile(fileID, userID);
const trashedFile = await fileDB.trashFile(fileID, userID);
if (!trashedFile) throw new NotFoundError("Trash File Not Found Error");
return trashedFile;
};
@@ -275,7 +272,7 @@ class MongoFileService {
};
restoreFile = async (userID: string, fileID: string) => {
const restoredFile = await dbUtilsFile.restoreFile(fileID, userID);
const restoredFile = await fileDB.restoreFile(fileID, userID);
if (!restoredFile) throw new NotFoundError("Restore File Not Found Error");
return restoredFile;
};
@@ -308,7 +305,7 @@ class MongoFileService {
};
renameFile = async (userID: string, fileID: string, title: string) => {
const file = await dbUtilsFile.renameFile(fileID, userID, title);
const file = await fileDB.renameFile(fileID, userID, title);
if (!file) throw new NotFoundError("Rename File Not Found Error");
@@ -316,14 +313,14 @@ class MongoFileService {
};
moveFile = async (userID: string, fileID: string, parentID: string) => {
const file = await dbUtilsFile.getFileInfo(fileID, userID);
const file = await fileDB.getFileInfo(fileID, userID);
if (!file) throw new NotFoundError("Move File Not Found Error");
const newParentList = [];
if (parentID !== "/") {
const folder = await dbUtilsFolder.getFolderInfo(parentID, userID);
const folder = await folderDB.getFolderInfo(parentID, userID);
if (!folder) throw new NotFoundError("Move Folder Not Found Error");
@@ -334,7 +331,7 @@ class MongoFileService {
console.log("new parent list", newParentList, parentID);
const updatedFile = await dbUtilsFile.moveFile(
const updatedFile = await fileDB.moveFile(
fileID,
userID,
parentID,
+24 -24
View File
@@ -1,8 +1,8 @@
import Folder, { FolderInterface } from "../../models/folder";
import InternalServerError from "../../utils/InternalServerError";
import NotFoundError from "../../utils/NotFoundError";
import UtilsFile from "../../db/utils/fileUtils";
import UtilsFolder from "../../db/utils/folderUtils";
import FileDB from "../../db/mongoDB/fileDB";
import FolderDB from "../../db/mongoDB/folderDB";
import sortBySwitch from "../../utils/sortBySwitchFolder";
import { UserInterface } from "../../models/user";
@@ -13,14 +13,14 @@ type userAccessType = {
s3Enabled: boolean;
};
const utilsFile = new UtilsFile();
const utilsFolder = new UtilsFolder();
const fileDB = new FileDB();
const folderDB = new FolderDB();
class FolderService {
createFolder = async (userID: string, name: string, parent: string) => {
const newFolderParentList = [];
if (parent && parent !== "/") {
const parentFolder = await utilsFolder.getFolderInfo(parent, userID);
const parentFolder = await folderDB.getFolderInfo(parent, userID);
if (!parentFolder) throw new Error("Parent not found");
newFolderParentList.push(
@@ -46,13 +46,13 @@ class FolderService {
};
getFolderInfo = async (userID: string, folderID: string) => {
const currentFolder = await utilsFolder.getFolderInfo(folderID, userID);
const currentFolder = await folderDB.getFolderInfo(folderID, userID);
if (!currentFolder) throw new NotFoundError("Folder Info Not Found Error");
return currentFolder;
};
getFolderSublist = async (userID: string, folderID: string) => {
const folder = await utilsFolder.getFolderInfo(folderID, userID);
const folder = await folderDB.getFolderInfo(folderID, userID);
if (!folder) throw new NotFoundError("Folder Sublist Not Found Error");
@@ -68,7 +68,7 @@ class FolderService {
folderIDList.push("/");
folderNameList.push("Home");
} else {
const currentFolder = await utilsFolder.getFolderInfo(
const currentFolder = await folderDB.getFolderInfo(
currentSubFolderID,
userID
);
@@ -105,7 +105,7 @@ class FolderService {
const s3Enabled = user.s3Enabled ? true : false;
if (searchQuery.length === 0) {
const folderList = await utilsFolder.getFolderListByParent(
const folderList = await folderDB.getFolderListByParent(
userID.toString(),
parent,
sortBy,
@@ -121,7 +121,7 @@ class FolderService {
return folderList;
} else {
searchQuery = new RegExp(searchQuery, "i");
const folderList = await utilsFolder.getFolderListBySearch(
const folderList = await folderDB.getFolderListBySearch(
userID.toString(),
searchQuery,
sortBy,
@@ -141,7 +141,7 @@ class FolderService {
};
renameFolder = async (userID: string, folderID: string, title: string) => {
const folder = await utilsFolder.renameFolder(folderID, userID, title);
const folder = await folderDB.renameFolder(folderID, userID, title);
if (!folder) throw new NotFoundError("Rename Folder Not Found");
};
@@ -149,7 +149,7 @@ class FolderService {
getSubfolderFullList = async (user: userAccessType, id: string) => {
const userID = user._id;
const folder = await utilsFolder.getFolderInfo(id, userID);
const folder = await folderDB.getFolderInfo(id, userID);
if (!folder) throw new NotFoundError("Folder Info Not Found");
@@ -190,7 +190,7 @@ class FolderService {
};
trashFolder = async (userID: string, folderID: string) => {
const folder = await utilsFolder.getFolderInfo(folderID, userID);
const folder = await folderDB.getFolderInfo(folderID, userID);
if (!folder) throw new NotFoundError("Trash Folder Not Found Error");
@@ -199,13 +199,13 @@ class FolderService {
const parentList = [...folder.parentList, folder._id!.toString()];
await utilsFolder.trashFoldersByParent(parentList, userID);
await folderDB.trashFoldersByParent(parentList, userID);
await utilsFile.trashFilesByParent(parentList.toString(), userID);
await fileDB.trashFilesByParent(parentList.toString(), userID);
};
restoreFolder = async (userID: string, folderID: string) => {
const folder = await utilsFolder.getFolderInfo(folderID, userID);
const folder = await folderDB.getFolderInfo(folderID, userID);
if (!folder) throw new NotFoundError("Restore Folder Not Found Error");
@@ -214,13 +214,13 @@ class FolderService {
const parentList = [...folder.parentList, folder._id!.toString()];
await utilsFolder.restoreFoldersByParent(parentList, userID);
await folderDB.restoreFoldersByParent(parentList, userID);
await utilsFile.restoreFilesByParent(parentList.toString(), userID);
await fileDB.restoreFilesByParent(parentList.toString(), userID);
};
renameFolder2 = async (folderID: string, userID: string, title: string) => {
const folder = await utilsFolder.getFolderInfo(folderID, userID);
const folder = await folderDB.getFolderInfo(folderID, userID);
if (!folder) throw new NotFoundError("Rename Folder Not Found");
@@ -236,7 +236,7 @@ class FolderService {
folderID?: string,
currentParent?: string
) => {
const folderList = await utilsFolder.getMoveFolderList(
const folderList = await folderDB.getMoveFolderList(
userID,
parent,
search,
@@ -249,12 +249,12 @@ class FolderService {
moveFolder = async (userID: string, folderID: string, parentID: string) => {
const foldersByIncludedParent =
await utilsFolder.getFolderListByIncludedParent(userID, folderID);
await folderDB.getFolderListByIncludedParent(userID, folderID);
const startParentList = [];
if (parentID !== "/") {
const folderToMoveTo = await utilsFolder.getFolderInfo(parentID, userID);
const folderToMoveTo = await folderDB.getFolderInfo(parentID, userID);
if (!folderToMoveTo) {
throw new NotFoundError("Move Folder Not Found Error");
}
@@ -279,8 +279,8 @@ class FolderService {
);
await Promise.all([
utilsFolder.moveFolder(folderID, userID, parentID, newParentList),
utilsFile.moveMultipleFiles(
folderDB.moveFolder(folderID, userID, parentID, newParentList),
fileDB.moveMultipleFiles(
userID,
currentFolder._id.toString(),
parentID,