From 7cf0c18f83f82416c9b1bb5bca5b669e77240527 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=8B=E3=81=A3=E3=81=93=E3=81=8B=E3=82=8A?= <67428053+kakkokari-gtyih@users.noreply.github.com> Date: Sun, 14 Apr 2024 10:22:03 +0900 Subject: [PATCH] =?UTF-8?q?fix(backend):=20FileServerService=E3=81=A7?= =?UTF-8?q?=E3=83=AC=E3=83=B3=E3=82=B8=E3=83=AA=E3=82=AF=E3=82=A8=E3=82=B9?= =?UTF-8?q?=E3=83=88=E3=81=AE=E5=A0=B4=E5=90=88=E3=81=AB=E9=81=A9=E5=88=87?= =?UTF-8?q?=E3=81=AA=E3=83=AC=E3=82=B9=E3=83=9D=E3=83=B3=E3=82=B9=E3=82=B3?= =?UTF-8?q?=E3=83=BC=E3=83=89=E3=81=8C=E8=BF=94=E3=82=89=E3=81=AA=E3=81=84?= =?UTF-8?q?=E5=95=8F=E9=A1=8C=E3=82=92=E4=BF=AE=E6=AD=A3=20(#13701)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * return 206 for every ranged response - fixes #494 (cherry picked from commit 92eec2178fd103e9ea2bcd646aacab1fb496a33b) * detect size of remote files - fixes #494 without this, remote files are assumed to have size 0 (even if we just downloaded them!) and the range-related code won't run (cherry picked from commit 960f4fcff78a1f019c9a9377853fcd90dbfb7575) --------- Co-authored-by: dakkar --- packages/backend/src/server/FileServerService.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/backend/src/server/FileServerService.ts b/packages/backend/src/server/FileServerService.ts index f51d7aebca..ce7702143e 100644 --- a/packages/backend/src/server/FileServerService.ts +++ b/packages/backend/src/server/FileServerService.ts @@ -194,6 +194,7 @@ export class FileServerService { reply.header('Content-Range', `bytes ${start}-${end}/${file.file.size}`); reply.header('Accept-Ranges', 'bytes'); reply.header('Content-Length', chunksize); + reply.code(206); } else { image = { data: fs.createReadStream(file.path), @@ -263,7 +264,6 @@ export class FileServerService { const parts = range.replace(/bytes=/, '').split('-'); const start = parseInt(parts[0], 10); let end = parts[1] ? parseInt(parts[1], 10) : file.file.size - 1; - console.log(end); if (end > file.file.size) { end = file.file.size - 1; } @@ -433,6 +433,7 @@ export class FileServerService { reply.header('Content-Range', `bytes ${start}-${end}/${file.file.size}`); reply.header('Accept-Ranges', 'bytes'); reply.header('Content-Length', chunksize); + reply.code(206); } else { image = { data: fs.createReadStream(file.path), @@ -529,6 +530,9 @@ export class FileServerService { if (!file.storedInternal) { if (!(file.isLink && file.uri)) return '204'; const result = await this.downloadAndDetectTypeFromUrl(file.uri); + if (!file.size) { + file.size = (await fs.promises.stat(result.path)).size; + } return { ...result, url: file.uri,