continued dep injectiong

This commit is contained in:
subnub
2024-07-02 15:10:03 -04:00
parent 09cb81f96d
commit 7bd81a9aa5
16 changed files with 413 additions and 336 deletions
@@ -2,6 +2,7 @@ import { UserInterface } from "../../../models/user";
import { FileInterface } from "../../../models/file";
import { Request, Response } from "express";
import { FolderInterface } from "../../../models/folder";
import crypto from "crypto";
interface ChunkInterface {
uploadFile: (
@@ -1,23 +1,23 @@
const awaitStream = <T>(inputSteam: any, outputStream: any, allStreamsToErrorCatch: any[]) => {
const awaitStream = <T>(
inputSteam: any,
outputStream: any,
allStreamsToErrorCatch: any[]
) => {
return new Promise<T>((resolve, reject) => {
allStreamsToErrorCatch.forEach((currentStream: any) => {
currentStream.on("error", (e: Error) => {
reject({
message: "Await Stream Input Error",
code: 500,
error: e,
});
});
});
return new Promise<T>((resolve, reject) => {
inputSteam.pipe(outputStream).on("finish", (data: T) => {
resolve(data);
});
});
};
allStreamsToErrorCatch.forEach((currentStream: any) => {
currentStream.on("error", (e: Error) => {
reject({
message: "Await Stream Input Error",
code: 500,
error: e
})
})
})
inputSteam.pipe(outputStream).on("finish", (data: T) => {
resolve(data);
})
})
}
export default awaitStream;
export default awaitStream;
@@ -1,3 +1,4 @@
import { ManagedUpload } from "aws-sdk/clients/s3";
import s3 from "../../../db/s3";
const awaitUploadStreamS3 = (
@@ -6,7 +7,7 @@ const awaitUploadStreamS3 = (
s3Data: { id: string; key: string; bucket: string }
) => {
return new Promise<void>((resolve, reject) => {
s3.upload(params, (err: any, data: any) => {
s3.upload(params, (err: any, data: ManagedUpload.SendData) => {
if (err) {
console.log("Amazon upload err", err);
reject("Amazon upload error");
@@ -0,0 +1,22 @@
import env from "../../../enviroment/env";
type GenericParmasType = {
filePath?: string;
Key?: string;
Bucket?: string;
};
export const createGenericParams = ({ filePath, Key }: GenericParmasType) => {
// TODO: Remove file split after migration
if (env.dbType === "fs") {
const filePathSplit = filePath!.split("/");
const fileName = filePathSplit[filePathSplit.length - 1];
return {
filePath: env.fsDirectory + fileName,
};
} else {
return {
Key,
};
}
};