From 10cd9554a69bcd2d3e87d5ae1114ab9190a80369 Mon Sep 17 00:00:00 2001 From: kyle hoell Date: Mon, 7 Dec 2020 16:13:23 -0500 Subject: [PATCH] added resolve to await stream when it is a safari request, updated some comments --- .../ChunkService/FileSystemService.ts | 7 +++-- backend/services/ChunkService/MongoService.ts | 26 +++++++++++++------ backend/services/ChunkService/S3Service.ts | 7 +++-- .../ChunkService/utils/awaitStreamVideo.ts | 4 ++- 4 files changed, 31 insertions(+), 13 deletions(-) diff --git a/backend/services/ChunkService/FileSystemService.ts b/backend/services/ChunkService/FileSystemService.ts index 0a0893c..e719fd9 100644 --- a/backend/services/ChunkService/FileSystemService.ts +++ b/backend/services/ChunkService/FileSystemService.ts @@ -267,8 +267,11 @@ class FileSystemService implements ChunkInterface { // All browsers took many days, tears, and some of my sanity. // Shoutout to Tyzoid for helping me with the decryption // And and helping me understand how the IVs work. - // Also fuck you Apple, Safari is turning into - // Internet explorer at this point. + + // P.S I hate safari >:( + // Why do yall have to be weird with video streaming + // 90% of the issues with this are only in Safari + // Is safari going to be the next internet explorer? const userID = user._id; const currentFile: FileInterface = await dbUtilsFile.getFileInfo(fileID, userID); diff --git a/backend/services/ChunkService/MongoService.ts b/backend/services/ChunkService/MongoService.ts index b5d1f7a..6d743a9 100644 --- a/backend/services/ChunkService/MongoService.ts +++ b/backend/services/ChunkService/MongoService.ts @@ -278,12 +278,19 @@ class MongoService implements ChunkInterface { streamVideo = async(user: UserInterface, fileID: string, headers: any, res: Response, req: Request) => { + // THIS ISN'T WORKING FULLY WHEN USING MONGODB AND SAFARI, + // OTHER DATABASES SHOULD WORK, BUT I AM NOT SURE WHY + // IT WILL NOT WORK ON SAFARI SOMETIMES + // To get this all working correctly with encryption and across // All browsers took many days, tears, and some of my sanity. // Shoutout to Tyzoid for helping me with the decryption // And and helping me understand how the IVs work. - // Also fuck you Apple, Safari is turning into - // Internet explorer at this point. + + // P.S I hate safari >:( + // Why do yall have to be weird with video streaming + // 90% of the issues with this are only in Safari + // Is safari going to be the next internet explorer? const userID = user._id; const currentFile = await dbUtilsFile.getFileInfo(fileID, userID); @@ -323,7 +330,11 @@ class MongoService implements ChunkInterface { // 16 bytes. fixedStart = 0; - fixedEnd = 15; + fixedEnd = 16; + + // I am not sure why this needs to be 16 for mongoDB, on the other routes 15 works + // Fine, and I thought the start and end were inclusive, but I am really not sure + // At this point } else { @@ -363,7 +374,6 @@ class MongoService implements ChunkInterface { } const bucket = new mongoose.mongo.GridFSBucket(conn.db, { - chunkSizeBytes: 1024 }); const readStream = bucket.openDownloadStream(new ObjectID(fileID), { @@ -371,19 +381,19 @@ class MongoService implements ChunkInterface { end: fixedEnd, }); - const CIPHER_KEY = crypto.createHash('sha256').update(password).digest() + const CIPHER_KEY = crypto.createHash('sha256').update(password).digest() + + res.writeHead(206, head); const decipher = crypto.createDecipheriv('aes256', CIPHER_KEY, currentIV); decipher.setAutoPadding(false); - res.writeHead(206, head); - const allStreamsToErrorCatch = [readStream, decipher]; readStream.pipe(decipher); await awaitStreamVideo(start, end, differenceStart, decipher, res, req, allStreamsToErrorCatch, readStream); - + readStream.destroy(); } diff --git a/backend/services/ChunkService/S3Service.ts b/backend/services/ChunkService/S3Service.ts index b8df6dc..84d9fe9 100644 --- a/backend/services/ChunkService/S3Service.ts +++ b/backend/services/ChunkService/S3Service.ts @@ -249,8 +249,11 @@ class S3Service implements ChunkInterface { // All browsers took many days, tears, and some of my sanity. // Shoutout to Tyzoid for helping me with the decryption // And and helping me understand how the IVs work. - // Also fuck you Apple, Safari is turning into - // Internet explorer at this point. + + // P.S I hate safari >:( + // Why do yall have to be weird with video streaming + // 90% of the issues with this are only in Safari + // Is safari going to be the next internet explorer? const userID = user._id; const currentFile: FileInterface = await dbUtilsFile.getFileInfo(fileID, userID); diff --git a/backend/services/ChunkService/utils/awaitStreamVideo.ts b/backend/services/ChunkService/utils/awaitStreamVideo.ts index 3e12e9d..dcd7712 100644 --- a/backend/services/ChunkService/utils/awaitStreamVideo.ts +++ b/backend/services/ChunkService/utils/awaitStreamVideo.ts @@ -38,7 +38,7 @@ const awaitStreamVideo = (start: number, end:number, differenceStart: number, if (+start === 0 && +end === 1) { - // This is for Safri/iOS, for whatever reason they ask for the + // This is for Safari/iOS, for whatever reason they ask for the // First byte, but if I actually try to return the first byte // It will not work ???, but if I return the first 4 bytes it seems // To work fine. @@ -52,6 +52,8 @@ const awaitStreamVideo = (start: number, end:number, differenceStart: number, const dataBack = Buffer.from(neededData, "hex"); res.write(dataBack); + + resolve(); }) } else {