diff options
author | Chocobozzz <me@florianbigard.com> | 2023-07-25 15:17:58 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2023-07-25 15:17:58 +0200 |
commit | 9901c8d6908a43ab4594406446eac770ee21176c (patch) | |
tree | cc59c2c45d96bd51053e283db1121baa2723b765 /shared | |
parent | 3b46eec8aeb95eb0dce763e3569c0509b1da7607 (diff) | |
download | PeerTube-9901c8d6908a43ab4594406446eac770ee21176c.tar.gz PeerTube-9901c8d6908a43ab4594406446eac770ee21176c.tar.zst PeerTube-9901c8d6908a43ab4594406446eac770ee21176c.zip |
Add video file update hook tests
Diffstat (limited to 'shared')
-rw-r--r-- | shared/server-commands/videos/videos-command.ts | 30 |
1 files changed, 21 insertions, 9 deletions
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 { | |||
394 | attributes?: VideoEdit | 394 | attributes?: VideoEdit |
395 | mode?: 'legacy' | 'resumable' // default legacy | 395 | mode?: 'legacy' | 'resumable' // default legacy |
396 | waitTorrentGeneration?: boolean // default true | 396 | waitTorrentGeneration?: boolean // default true |
397 | completedExpectedStatus?: HttpStatusCode | ||
397 | } = {}) { | 398 | } = {}) { |
398 | const { mode = 'legacy', waitTorrentGeneration = true } = options | 399 | const { mode = 'legacy', waitTorrentGeneration = true } = options |
399 | let defaultChannelId = 1 | 400 | let defaultChannelId = 1 |
@@ -461,8 +462,9 @@ export class VideosCommand extends AbstractCommand { | |||
461 | async buildResumeUpload (options: OverrideCommandOptions & { | 462 | async buildResumeUpload (options: OverrideCommandOptions & { |
462 | path: string | 463 | path: string |
463 | attributes: { fixture?: string } & { [id: string]: any } | 464 | attributes: { fixture?: string } & { [id: string]: any } |
465 | completedExpectedStatus?: HttpStatusCode // When the upload is finished | ||
464 | }): Promise<VideoCreateResult> { | 466 | }): Promise<VideoCreateResult> { |
465 | const { path, attributes, expectedStatus = HttpStatusCode.OK_200 } = options | 467 | const { path, attributes, expectedStatus = HttpStatusCode.OK_200, completedExpectedStatus } = options |
466 | 468 | ||
467 | let size = 0 | 469 | let size = 0 |
468 | let videoFilePath: string | 470 | let videoFilePath: string |
@@ -503,7 +505,8 @@ export class VideosCommand extends AbstractCommand { | |||
503 | path, | 505 | path, |
504 | pathUploadId, | 506 | pathUploadId, |
505 | videoFilePath, | 507 | videoFilePath, |
506 | size | 508 | size, |
509 | expectedStatus: completedExpectedStatus | ||
507 | }) | 510 | }) |
508 | 511 | ||
509 | if (result.statusCode === HttpStatusCode.OK_200) { | 512 | if (result.statusCode === HttpStatusCode.OK_200) { |
@@ -600,12 +603,14 @@ export class VideosCommand extends AbstractCommand { | |||
600 | try { | 603 | try { |
601 | readable.pause() | 604 | readable.pause() |
602 | 605 | ||
606 | const byterangeStart = start + chunk.length - 1 | ||
607 | |||
603 | const headers = { | 608 | const headers = { |
604 | 'Authorization': 'Bearer ' + token, | 609 | 'Authorization': 'Bearer ' + token, |
605 | 'Content-Type': 'application/octet-stream', | 610 | 'Content-Type': 'application/octet-stream', |
606 | 'Content-Range': contentRangeBuilder | 611 | 'Content-Range': contentRangeBuilder |
607 | ? contentRangeBuilder(start, chunk) | 612 | ? contentRangeBuilder(start, chunk) |
608 | : `bytes ${start}-${start + chunk.length - 1}/${size}`, | 613 | : `bytes ${start}-${byterangeStart}/${size}`, |
609 | 'Content-Length': contentLength ? contentLength + '' : chunk.length + '' | 614 | 'Content-Length': contentLength ? contentLength + '' : chunk.length + '' |
610 | } | 615 | } |
611 | 616 | ||
@@ -625,13 +630,19 @@ export class VideosCommand extends AbstractCommand { | |||
625 | 630 | ||
626 | start += chunk.length | 631 | start += chunk.length |
627 | 632 | ||
628 | if (res.statusCode === expectedStatus) { | 633 | // Last request, check final status |
629 | return resolve(res) | 634 | if (byterangeStart + 1 === size) { |
630 | } | 635 | if (res.statusCode === expectedStatus) { |
636 | return resolve(res) | ||
637 | } | ||
638 | |||
639 | if (res.statusCode !== HttpStatusCode.PERMANENT_REDIRECT_308) { | ||
640 | readable.off('data', onData) | ||
631 | 641 | ||
632 | if (res.statusCode !== HttpStatusCode.PERMANENT_REDIRECT_308) { | 642 | // eslint-disable-next-line max-len |
633 | readable.off('data', onData) | 643 | const message = `Incorrect transient behaviour sending intermediary chunks. Status code is ${res.statusCode} instead of ${expectedStatus}` |
634 | return reject(new Error('Incorrect transient behaviour sending intermediary chunks')) | 644 | return reject(new Error(message)) |
645 | } | ||
635 | } | 646 | } |
636 | 647 | ||
637 | readable.resume() | 648 | readable.resume() |
@@ -694,6 +705,7 @@ export class VideosCommand extends AbstractCommand { | |||
694 | replaceSourceFile (options: OverrideCommandOptions & { | 705 | replaceSourceFile (options: OverrideCommandOptions & { |
695 | videoId: number | string | 706 | videoId: number | string |
696 | fixture: string | 707 | fixture: string |
708 | completedExpectedStatus?: HttpStatusCode | ||
697 | }) { | 709 | }) { |
698 | return this.buildResumeUpload({ | 710 | return this.buildResumeUpload({ |
699 | ...options, | 711 | ...options, |