fix (rangeRequest)
This commit is contained in:
parent
99feef3fe6
commit
006aaf3613
|
@ -168,7 +168,7 @@ export class FileServerService {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!image) {
|
if (!image) {
|
||||||
if (request.headers.range) {
|
if (request.headers.range && file.file.size > 0) {
|
||||||
const range = request.headers.range as string;
|
const range = request.headers.range as string;
|
||||||
const parts = range.replace(/bytes=/, '').split('-');
|
const parts = range.replace(/bytes=/, '').split('-');
|
||||||
const start = parseInt(parts[0], 10);
|
const start = parseInt(parts[0], 10);
|
||||||
|
@ -228,7 +228,7 @@ export class FileServerService {
|
||||||
reply.header('Cache-Control', 'max-age=31536000, immutable');
|
reply.header('Cache-Control', 'max-age=31536000, immutable');
|
||||||
reply.header('Content-Disposition', contentDisposition('inline', filename));
|
reply.header('Content-Disposition', contentDisposition('inline', filename));
|
||||||
|
|
||||||
if (request.headers.range) {
|
if (request.headers.range && file.file.size > 0) {
|
||||||
const range = request.headers.range as string;
|
const range = request.headers.range as string;
|
||||||
const parts = range.replace(/bytes=/, '').split('-');
|
const parts = range.replace(/bytes=/, '').split('-');
|
||||||
const start = parseInt(parts[0], 10);
|
const start = parseInt(parts[0], 10);
|
||||||
|
@ -254,7 +254,7 @@ export class FileServerService {
|
||||||
reply.header('Cache-Control', 'max-age=31536000, immutable');
|
reply.header('Cache-Control', 'max-age=31536000, immutable');
|
||||||
reply.header('Content-Disposition', contentDisposition('inline', file.filename));
|
reply.header('Content-Disposition', contentDisposition('inline', file.filename));
|
||||||
|
|
||||||
if (request.headers.range) {
|
if (request.headers.range && file.file.size > 0) {
|
||||||
const range = request.headers.range as string;
|
const range = request.headers.range as string;
|
||||||
const parts = range.replace(/bytes=/, '').split('-');
|
const parts = range.replace(/bytes=/, '').split('-');
|
||||||
const start = parseInt(parts[0], 10);
|
const start = parseInt(parts[0], 10);
|
||||||
|
@ -407,11 +407,35 @@ export class FileServerService {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!image) {
|
if (!image) {
|
||||||
image = {
|
if (request.headers.range && file.file && file.file.size > 0) {
|
||||||
data: fs.createReadStream(file.path),
|
const range = request.headers.range as string;
|
||||||
ext: file.ext,
|
const parts = range.replace(/bytes=/, '').split('-');
|
||||||
type: file.mime,
|
const start = parseInt(parts[0], 10);
|
||||||
};
|
let end = parts[1] ? parseInt(parts[1], 10) : file.file.size - 1;
|
||||||
|
if (end > file.file.size) {
|
||||||
|
end = file.file.size - 1;
|
||||||
|
}
|
||||||
|
const chunksize = end - start + 1;
|
||||||
|
|
||||||
|
image = {
|
||||||
|
data: fs.createReadStream(file.path, {
|
||||||
|
start,
|
||||||
|
end,
|
||||||
|
}),
|
||||||
|
ext: file.ext,
|
||||||
|
type: file.mime,
|
||||||
|
};
|
||||||
|
|
||||||
|
reply.header('Content-Range', `bytes ${start}-${end}/${file.file.size}`);
|
||||||
|
reply.header('Accept-Ranges', 'bytes');
|
||||||
|
reply.header('Content-Length', chunksize);
|
||||||
|
} else {
|
||||||
|
image = {
|
||||||
|
data: fs.createReadStream(file.path),
|
||||||
|
ext: file.ext,
|
||||||
|
type: file.mime,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('cleanup' in file) {
|
if ('cleanup' in file) {
|
||||||
|
|
Loading…
Reference in a new issue