From 9901c8d6908a43ab4594406446eac770ee21176c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 25 Jul 2023 15:17:58 +0200 Subject: Add video file update hook tests --- shared/server-commands/videos/videos-command.ts | 30 +++++++++++++++++-------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'shared/server-commands') diff --git a/shared/server-commands/videos/videos-command.ts b/shared/server-commands/videos/videos-command.ts index 3fdbc348a..a58f1c545 100644 --- a/shared/server-commands/videos/videos-command.ts +++ b/shared/server-commands/videos/videos-command.ts @@ -394,6 +394,7 @@ export class VideosCommand extends AbstractCommand { attributes?: VideoEdit mode?: 'legacy' | 'resumable' // default legacy waitTorrentGeneration?: boolean // default true + completedExpectedStatus?: HttpStatusCode } = {}) { const { mode = 'legacy', waitTorrentGeneration = true } = options let defaultChannelId = 1 @@ -461,8 +462,9 @@ export class VideosCommand extends AbstractCommand { async buildResumeUpload (options: OverrideCommandOptions & { path: string attributes: { fixture?: string } & { [id: string]: any } + completedExpectedStatus?: HttpStatusCode // When the upload is finished }): Promise { - const { path, attributes, expectedStatus = HttpStatusCode.OK_200 } = options + const { path, attributes, expectedStatus = HttpStatusCode.OK_200, completedExpectedStatus } = options let size = 0 let videoFilePath: string @@ -503,7 +505,8 @@ export class VideosCommand extends AbstractCommand { path, pathUploadId, videoFilePath, - size + size, + expectedStatus: completedExpectedStatus }) if (result.statusCode === HttpStatusCode.OK_200) { @@ -600,12 +603,14 @@ export class VideosCommand extends AbstractCommand { try { readable.pause() + const byterangeStart = start + chunk.length - 1 + const headers = { 'Authorization': 'Bearer ' + token, 'Content-Type': 'application/octet-stream', 'Content-Range': contentRangeBuilder ? contentRangeBuilder(start, chunk) - : `bytes ${start}-${start + chunk.length - 1}/${size}`, + : `bytes ${start}-${byterangeStart}/${size}`, 'Content-Length': contentLength ? contentLength + '' : chunk.length + '' } @@ -625,13 +630,19 @@ export class VideosCommand extends AbstractCommand { start += chunk.length - if (res.statusCode === expectedStatus) { - return resolve(res) - } + // Last request, check final status + if (byterangeStart + 1 === size) { + if (res.statusCode === expectedStatus) { + return resolve(res) + } + + if (res.statusCode !== HttpStatusCode.PERMANENT_REDIRECT_308) { + readable.off('data', onData) - if (res.statusCode !== HttpStatusCode.PERMANENT_REDIRECT_308) { - readable.off('data', onData) - return reject(new Error('Incorrect transient behaviour sending intermediary chunks')) + // eslint-disable-next-line max-len + const message = `Incorrect transient behaviour sending intermediary chunks. Status code is ${res.statusCode} instead of ${expectedStatus}` + return reject(new Error(message)) + } } readable.resume() @@ -694,6 +705,7 @@ export class VideosCommand extends AbstractCommand { replaceSourceFile (options: OverrideCommandOptions & { videoId: number | string fixture: string + completedExpectedStatus?: HttpStatusCode }) { return this.buildResumeUpload({ ...options, -- cgit v1.2.3