From c7b507bfdf03015e49f76e2e13c8e8363a0551d6 Mon Sep 17 00:00:00 2001 From: Filip Znachor Date: Wed, 23 Feb 2022 20:50:10 +0100 Subject: [PATCH] Small improvements --- downloader.ts | 7 ++++--- webserver.ts | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/downloader.ts b/downloader.ts index b909be6..f73e27e 100644 --- a/downloader.ts +++ b/downloader.ts @@ -35,7 +35,7 @@ export class Downloader { if(to > this.total_size) to = this.total_size; - let chunk_count = Math.ceil((to-from)/this.chunk_size); + let chunk_count = Math.max(Math.ceil((to-from)/this.chunk_size), 1); let chunks: Buffer[] = []; let completed = 0; @@ -59,8 +59,9 @@ export class Downloader { let url = await this.pool.get(); if(!url) throw "No available URL!"; - let lfrom = from+(part*this.chunk_size); - let lto = Math.min(lfrom+this.chunk_size-1, to); + let lfrom = from + (part * this.chunk_size) + (part > 0 ? 1 : 0); + let lto = Math.min(from + (part * this.chunk_size) + this.chunk_size, to); + if(lfrom == lto) lfrom--; let r = await axios.get(url[1], { responseType: 'arraybuffer', diff --git a/webserver.ts b/webserver.ts index f3c2c3a..ec112fa 100644 --- a/webserver.ts +++ b/webserver.ts @@ -70,12 +70,12 @@ export class Webserver { const contentLength = to - from + 1; const headers = { "Content-Range": `bytes ${from}-${to}/${d.total_size}`, + "Range": `bytes=${from}-${to}/${d.total_size}`, "Accept-Ranges": "bytes", "Content-Length": contentLength, - "Content-Type": "video/mp4", + "Content-Type": "application/octet-stream", }; - // HTTP Status 206 for Partial Content res.writeHead(206, headers); let stream = await d.download_range(from, to);