diff --git a/backend/services/chunk-service/chunk-service.ts b/backend/services/chunk-service/chunk-service.ts index 5be75f4..733ab79 100644 --- a/backend/services/chunk-service/chunk-service.ts +++ b/backend/services/chunk-service/chunk-service.ts @@ -385,8 +385,6 @@ class StorageService { const chunksize = end - start + 1; const IV = currentFile.metadata.IV; - console.log("chunksize", start, end, chunksize); - const head = { "Content-Range": "bytes " + start + "-" + end + "/" + fileSize, "Accept-Ranges": "bytes", diff --git a/backend/services/chunk-service/utils/awaitStreamVideo.ts b/backend/services/chunk-service/utils/awaitStreamVideo.ts deleted file mode 100644 index 86919b1..0000000 --- a/backend/services/chunk-service/utils/awaitStreamVideo.ts +++ /dev/null @@ -1,76 +0,0 @@ -import { Response, Request } from "express"; -const StreamSkip = require("stream-skip"); - -const awaitStreamVideo = ( - start: number, - end: number, - differenceStart: number, - decipher: any, - res: Response, - req: Request, - streamsToErrorCatch: any[], - readStream: any -) => { - return new Promise((resolve, reject) => { - req.on("close", () => { - // readStream.close(); - decipher.destroy(); - resolve(); - }); - - req.on("end", () => { - streamsToErrorCatch.forEach((stream) => { - stream.destroy(); - }); - resolve(); - }); - - streamsToErrorCatch.forEach((currentStream) => { - currentStream.on("error", (e: Error) => { - reject({ - message: "Await Video Stream Input Error", - code: 500, - error: e, - }); - }); - }); - - readStream.on("close", () => { - decipher.destroy(); - }); - - if (+start === 0 && +end === 1) { - // 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. - - decipher.on("data", (data: Buffer | string) => { - const dataCoverted = data.toString("hex"); - - let neededData = dataCoverted.substring(0, 8); - - const dataBack = Buffer.from(neededData, "hex"); - - res.write(dataBack); - - resolve(); - }); - } else { - // This is where the differnce start comes into play, as I said before - // There will be an offset caused by the 16 block size of AES256. - // So if there was an offset we need to skip over those bytes - // To make sure it returns the exact position the browser is requesting. - // Most browsers will still work fine without this, such as Chrome and Firefox. - // But one browser needs to be pampered and fed the exact right bytes in - // Order to function correctly, can you guess what browser? If you - // Guessed Safari you would be correct. - - const streamSkip = new StreamSkip({ skip: differenceStart }); - - decipher.pipe(streamSkip).pipe(res); - } - }); -}; - -export default awaitStreamVideo; diff --git a/backend/services/chunk-service/utils/getFileData.ts b/backend/services/chunk-service/utils/getFileData.ts index 06f7ceb..8693132 100644 --- a/backend/services/chunk-service/utils/getFileData.ts +++ b/backend/services/chunk-service/utils/getFileData.ts @@ -42,7 +42,6 @@ const getFileAndRemoveActiveStream = async ( readStream.destroy(); // @ts-ignore decipherStream.destroy(); - console.log("Destroyed streams"); } catch (e) { console.log("Error destroying streams", e); } @@ -140,16 +139,20 @@ const proccessData = ( let bytesSent = 0; decipher.on("data", (data: Buffer) => { - if (bytesSent + data.length > range.chunksize) { + if (bytesSent === 0 && range.skip > 0) { + const neededData = data.slice(range.skip, data.length); + res.write(neededData); + bytesSent += neededData.length; + } else if (bytesSent + data.length > range.chunksize) { const currentDataLength = bytesSent + data.length; const difference = currentDataLength - range.chunksize; const neededData = data.slice(0, data.length - difference); res.write(neededData); + bytesSent += neededData.length; } else { res.write(data); + bytesSent += data.length; } - - bytesSent += data.length; }); decipher.on("finish", () => { diff --git a/package.json b/package.json index c2faa08..6529f40 100755 --- a/package.json +++ b/package.json @@ -91,7 +91,6 @@ "redux": "^5.0.1", "regenerator-runtime": "^0.13.3", "sharp": "^0.33.4", - "stream-skip": "^1.0.3", "supertest-session": "^4.1.0", "sweetalert2": "^11.6.13", "temp": "^0.9.1",