Small improvements
This commit is contained in:
parent
9bd1efdb8d
commit
c7b507bfdf
|
@ -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',
|
||||
|
|
|
@ -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);
|
||||
|
|
Reference in a new issue