From 92eec2178fd103e9ea2bcd646aacab1fb496a33b Mon Sep 17 00:00:00 2001 From: dakkar Date: Tue, 9 Apr 2024 15:42:29 +0100 Subject: [PATCH 1/2] return 206 for every ranged response - fixes #494 --- packages/backend/src/server/FileServerService.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/backend/src/server/FileServerService.ts b/packages/backend/src/server/FileServerService.ts index 6d24898acc..183f7cb8d7 100644 --- a/packages/backend/src/server/FileServerService.ts +++ b/packages/backend/src/server/FileServerService.ts @@ -192,6 +192,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), @@ -431,6 +432,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), From 960f4fcff78a1f019c9a9377853fcd90dbfb7575 Mon Sep 17 00:00:00 2001 From: dakkar Date: Tue, 9 Apr 2024 16:21:30 +0100 Subject: [PATCH 2/2] 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 --- packages/backend/src/server/FileServerService.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/backend/src/server/FileServerService.ts b/packages/backend/src/server/FileServerService.ts index 183f7cb8d7..3cb353f2b3 100644 --- a/packages/backend/src/server/FileServerService.ts +++ b/packages/backend/src/server/FileServerService.ts @@ -262,7 +262,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; } @@ -529,6 +528,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,