From 84abaa7311d293760630f7983eafbf8c4c44d0c2 Mon Sep 17 00:00:00 2001 From: Francois Zbinden Date: Mon, 6 Nov 2023 17:12:12 +0100 Subject: [PATCH 1/3] Return real length in Content-Range instead of * --- .vscode/settings.json | 3 +++ src/manager/v2/fileSystem/FileSystem.ts | 2 +- src/manager/v2/fileSystem/Resource.ts | 2 +- src/resource/v1/physical/PhysicalGateway.ts | 2 +- src/server/v1/commands/Get.ts | 2 +- src/server/v2/commands/Get.ts | 2 +- src/server/v2/commands/Head.ts | 2 +- 7 files changed, 9 insertions(+), 6 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..7c2feb7e --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "editor.formatOnSave": false +} diff --git a/src/manager/v2/fileSystem/FileSystem.ts b/src/manager/v2/fileSystem/FileSystem.ts index 037d22d0..121ebd9d 100644 --- a/src/manager/v2/fileSystem/FileSystem.ts +++ b/src/manager/v2/fileSystem/FileSystem.ts @@ -2027,7 +2027,7 @@ export abstract class FileSystem implements ISerializableFileSystem .each(Object.keys(tree), (name, cb) => { const value = tree[name]; const childPath = rootPath.getChildPath(name); - if(value.constructor === ResourceType || value.constructor === String || value.constructor === Buffer) + if(value.constructor === ResourceType || typeof value === 'string' || value.constructor === Buffer) { this.addSubTree(ctx, childPath, value, cb) } diff --git a/src/manager/v2/fileSystem/Resource.ts b/src/manager/v2/fileSystem/Resource.ts index 3edb8f1f..fa3ebe47 100644 --- a/src/manager/v2/fileSystem/Resource.ts +++ b/src/manager/v2/fileSystem/Resource.ts @@ -9,7 +9,7 @@ import { import { Readable, Writable } from 'stream' import { IPropertyManager } from './PropertyManager' import { RequestContext } from '../../../server/v2/RequestContext' -import { ILockManager, ILockManagerAsync } from './LockManager' +import { ILockManagerAsync } from './LockManager' import { FileSystem } from './FileSystem' import { LockKind } from '../../../resource/v2/lock/LockKind' import { Lock } from '../../../resource/v2/lock/Lock' diff --git a/src/resource/v1/physical/PhysicalGateway.ts b/src/resource/v1/physical/PhysicalGateway.ts index 3ba90184..8faead87 100644 --- a/src/resource/v1/physical/PhysicalGateway.ts +++ b/src/resource/v1/physical/PhysicalGateway.ts @@ -16,7 +16,7 @@ export class PhysicalGateway extends PhysicalFolder [path : string] : PhysicalResource } - constructor(rootPath : string, protected customName ?: string, parent ?: IResource, fsManager ?: FSManager) + constructor(rootPath : string, public customName ?: string, parent ?: IResource, fsManager ?: FSManager) { super(rootPath, parent, fsManager ? fsManager : new PhysicalGFSManager()); diff --git a/src/server/v1/commands/Get.ts b/src/server/v1/commands/Get.ts index 069b0605..42b9831f 100644 --- a/src/server/v1/commands/Get.ts +++ b/src/server/v1/commands/Get.ts @@ -99,7 +99,7 @@ export function method(arg : MethodCallArgs, callback) arg.response.setHeader('Accept-Ranges', 'bytes') arg.response.setHeader('Content-Type', mimeType) arg.response.setHeader('Content-Length', (max - min).toString()) - arg.response.setHeader('Content-Range', 'bytes ' + min + '-' + max + '/*') + arg.response.setHeader('Content-Range', 'bytes ' + min + '-' + max + '/'+ (max - min).toString()) rstream.on('end', callback); rstream.pipe(new RangedStream(min, max)).pipe(arg.response); diff --git a/src/server/v2/commands/Get.ts b/src/server/v2/commands/Get.ts index 1a988ab1..03cd239c 100644 --- a/src/server/v2/commands/Get.ts +++ b/src/server/v2/commands/Get.ts @@ -216,7 +216,7 @@ export default class implements HTTPMethod if(ranges.length <= 1) { ctx.response.setHeader('Content-Type', mimeType) - ctx.response.setHeader('Content-Range', `bytes ${ranges[0].min}-${ranges[0].max}/*`) + ctx.response.setHeader('Content-Range', `bytes ${ranges[0].min}-${ranges[0].max}/${len.toString()}`) rstream.on('end', callback); return rstream.pipe(new RangedStream(ranges[0].min, ranges[0].max)).pipe(ctx.response); } diff --git a/src/server/v2/commands/Head.ts b/src/server/v2/commands/Head.ts index d118e644..239bb89a 100644 --- a/src/server/v2/commands/Head.ts +++ b/src/server/v2/commands/Head.ts @@ -52,7 +52,7 @@ export default class implements HTTPMethod if(ranges.length <= 1) { ctx.response.setHeader('Content-Type', mimeType) - ctx.response.setHeader('Content-Range', `bytes ${ranges[0].min}-${ranges[0].max}/*`) + ctx.response.setHeader('Content-Range', `bytes ${ranges[0].min}-${ranges[0].max}/${len.toString()}`) } else ctx.response.setHeader('Content-Type', `multipart/byteranges; boundary=${separator}`) From 1e56fa12bf863a2b0d7a7c4b2b65c18dd56ad39a Mon Sep 17 00:00:00 2001 From: Francois Zbinden Date: Tue, 7 Nov 2023 08:59:49 +0100 Subject: [PATCH 2/3] Better solution --- src/server/v1/commands/Get.ts | 28 ++++++++++++++++++---------- src/server/v2/commands/Get.ts | 2 +- src/server/v2/commands/Head.ts | 2 +- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/server/v1/commands/Get.ts b/src/server/v1/commands/Get.ts index 42b9831f..76b6a6d2 100644 --- a/src/server/v1/commands/Get.ts +++ b/src/server/v1/commands/Get.ts @@ -91,18 +91,26 @@ export function method(arg : MethodCallArgs, callback) const range = arg.findHeader('Range'); if(range) { - const rex = /([0-9]+)/g; - const min = parseInt(rex.exec(range)[1], 10); - const max = parseInt(rex.exec(range)[1], 10); + r.size(targetSource, (e, totalSize) => { + if(e) + { + arg.setCode(HTTPCodes.InternalServerError) + callback(); + return; + } + const rex = /([0-9]+)/g; + const min = parseInt(rex.exec(range)[1], 10); + const max = parseInt(rex.exec(range)[1], 10); - arg.setCode(HTTPCodes.PartialContent); - arg.response.setHeader('Accept-Ranges', 'bytes') - arg.response.setHeader('Content-Type', mimeType) - arg.response.setHeader('Content-Length', (max - min).toString()) - arg.response.setHeader('Content-Range', 'bytes ' + min + '-' + max + '/'+ (max - min).toString()) + arg.setCode(HTTPCodes.PartialContent); + arg.response.setHeader('Accept-Ranges', 'bytes') + arg.response.setHeader('Content-Type', mimeType) + arg.response.setHeader('Content-Length', (max - min).toString()) + arg.response.setHeader('Content-Range', 'bytes ' + min + '-' + max + '/'+totalSize.toString()) - rstream.on('end', callback); - rstream.pipe(new RangedStream(min, max)).pipe(arg.response); + rstream.on('end', callback); + rstream.pipe(new RangedStream(min, max)).pipe(arg.response); + }); } else { diff --git a/src/server/v2/commands/Get.ts b/src/server/v2/commands/Get.ts index 03cd239c..f00df13f 100644 --- a/src/server/v2/commands/Get.ts +++ b/src/server/v2/commands/Get.ts @@ -216,7 +216,7 @@ export default class implements HTTPMethod if(ranges.length <= 1) { ctx.response.setHeader('Content-Type', mimeType) - ctx.response.setHeader('Content-Range', `bytes ${ranges[0].min}-${ranges[0].max}/${len.toString()}`) + ctx.response.setHeader('Content-Range', `bytes ${ranges[0].min}-${ranges[0].max}/${size}`) rstream.on('end', callback); return rstream.pipe(new RangedStream(ranges[0].min, ranges[0].max)).pipe(ctx.response); } diff --git a/src/server/v2/commands/Head.ts b/src/server/v2/commands/Head.ts index 239bb89a..224851f1 100644 --- a/src/server/v2/commands/Head.ts +++ b/src/server/v2/commands/Head.ts @@ -52,7 +52,7 @@ export default class implements HTTPMethod if(ranges.length <= 1) { ctx.response.setHeader('Content-Type', mimeType) - ctx.response.setHeader('Content-Range', `bytes ${ranges[0].min}-${ranges[0].max}/${len.toString()}`) + ctx.response.setHeader('Content-Range', `bytes ${ranges[0].min}-${ranges[0].max}/${size}`) } else ctx.response.setHeader('Content-Type', `multipart/byteranges; boundary=${separator}`) From 7a53c3693bf1815639f31b6e53b1c8a7280bbbf3 Mon Sep 17 00:00:00 2001 From: Francois Zbinden Date: Tue, 7 Nov 2023 09:08:13 +0100 Subject: [PATCH 3/3] Remove settings --- .vscode/settings.json | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 7c2feb7e..00000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "editor.formatOnSave": false -}