aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils/videos/videos-command.ts
diff options
context:
space:
mode:
Diffstat (limited to 'shared/extra-utils/videos/videos-command.ts')
-rw-r--r--shared/extra-utils/videos/videos-command.ts36
1 files changed, 20 insertions, 16 deletions
diff --git a/shared/extra-utils/videos/videos-command.ts b/shared/extra-utils/videos/videos-command.ts
index feef5a771..f46d386f4 100644
--- a/shared/extra-utils/videos/videos-command.ts
+++ b/shared/extra-utils/videos/videos-command.ts
@@ -7,7 +7,7 @@ import { omit, pick } from 'lodash'
7import validator from 'validator' 7import validator from 'validator'
8import { buildUUID } from '@server/helpers/uuid' 8import { buildUUID } from '@server/helpers/uuid'
9import { loadLanguages } from '@server/initializers/constants' 9import { loadLanguages } from '@server/initializers/constants'
10import { HttpStatusCode } from '@shared/core-utils' 10import { HttpStatusCode } from '@shared/models'
11import { 11import {
12 ResultList, 12 ResultList,
13 UserVideoRateType, 13 UserVideoRateType,
@@ -234,10 +234,10 @@ export class VideosCommand extends AbstractCommand {
234 } 234 }
235 235
236 listByAccount (options: OverrideCommandOptions & VideosWithSearchCommonQuery & { 236 listByAccount (options: OverrideCommandOptions & VideosWithSearchCommonQuery & {
237 accountName: string 237 handle: string
238 }) { 238 }) {
239 const { accountName, search } = options 239 const { handle, search } = options
240 const path = '/api/v1/accounts/' + accountName + '/videos' 240 const path = '/api/v1/accounts/' + handle + '/videos'
241 241
242 return this.getRequestBody<ResultList<Video>>({ 242 return this.getRequestBody<ResultList<Video>>({
243 ...options, 243 ...options,
@@ -250,10 +250,10 @@ export class VideosCommand extends AbstractCommand {
250 } 250 }
251 251
252 listByChannel (options: OverrideCommandOptions & VideosWithSearchCommonQuery & { 252 listByChannel (options: OverrideCommandOptions & VideosWithSearchCommonQuery & {
253 videoChannelName: string 253 handle: string
254 }) { 254 }) {
255 const { videoChannelName } = options 255 const { handle } = options
256 const path = '/api/v1/video-channels/' + videoChannelName + '/videos' 256 const path = '/api/v1/video-channels/' + handle + '/videos'
257 257
258 return this.getRequestBody<ResultList<Video>>({ 258 return this.getRequestBody<ResultList<Video>>({
259 ...options, 259 ...options,
@@ -309,13 +309,13 @@ export class VideosCommand extends AbstractCommand {
309 }) { 309 }) {
310 const path = '/api/v1/videos/' + options.id 310 const path = '/api/v1/videos/' + options.id
311 311
312 return this.deleteRequest({ 312 return unwrapBody(this.deleteRequest({
313 ...options, 313 ...options,
314 314
315 path, 315 path,
316 implicitToken: true, 316 implicitToken: true,
317 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 317 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
318 }) 318 }))
319 } 319 }
320 320
321 async removeAll () { 321 async removeAll () {
@@ -396,7 +396,7 @@ export class VideosCommand extends AbstractCommand {
396 396
397 async buildResumeUpload (options: OverrideCommandOptions & { 397 async buildResumeUpload (options: OverrideCommandOptions & {
398 attributes: VideoEdit 398 attributes: VideoEdit
399 }) { 399 }): Promise<VideoCreateResult> {
400 const { attributes, expectedStatus } = options 400 const { attributes, expectedStatus } = options
401 401
402 let size = 0 402 let size = 0
@@ -414,7 +414,8 @@ export class VideosCommand extends AbstractCommand {
414 } 414 }
415 } 415 }
416 416
417 const initializeSessionRes = await this.prepareResumableUpload({ ...options, attributes, size, mimetype }) 417 // Do not check status automatically, we'll check it manually
418 const initializeSessionRes = await this.prepareResumableUpload({ ...options, expectedStatus: null, attributes, size, mimetype })
418 const initStatus = initializeSessionRes.status 419 const initStatus = initializeSessionRes.status
419 420
420 if (videoFilePath && initStatus === HttpStatusCode.CREATED_201) { 421 if (videoFilePath && initStatus === HttpStatusCode.CREATED_201) {
@@ -425,7 +426,7 @@ export class VideosCommand extends AbstractCommand {
425 426
426 const result = await this.sendResumableChunks({ ...options, pathUploadId, videoFilePath, size }) 427 const result = await this.sendResumableChunks({ ...options, pathUploadId, videoFilePath, size })
427 428
428 return result.body.video 429 return result.body?.video || result.body as any
429 } 430 }
430 431
431 const expectedInitStatus = expectedStatus === HttpStatusCode.OK_200 432 const expectedInitStatus = expectedStatus === HttpStatusCode.OK_200
@@ -434,7 +435,7 @@ export class VideosCommand extends AbstractCommand {
434 435
435 expect(initStatus).to.equal(expectedInitStatus) 436 expect(initStatus).to.equal(expectedInitStatus)
436 437
437 return initializeSessionRes.body.video as VideoCreateResult 438 return initializeSessionRes.body.video || initializeSessionRes.body
438 } 439 }
439 440
440 async prepareResumableUpload (options: OverrideCommandOptions & { 441 async prepareResumableUpload (options: OverrideCommandOptions & {
@@ -455,7 +456,10 @@ export class VideosCommand extends AbstractCommand {
455 'X-Upload-Content-Length': size.toString() 456 'X-Upload-Content-Length': size.toString()
456 }, 457 },
457 fields: { filename: attributes.fixture, ...this.buildUploadFields(options.attributes) }, 458 fields: { filename: attributes.fixture, ...this.buildUploadFields(options.attributes) },
459 // Fixture will be sent later
460 attaches: this.buildUploadAttaches(omit(options.attributes, 'fixture')),
458 implicitToken: true, 461 implicitToken: true,
462
459 defaultExpectedStatus: null 463 defaultExpectedStatus: null
460 }) 464 })
461 } 465 }
@@ -539,10 +543,10 @@ export class VideosCommand extends AbstractCommand {
539 543
540 const attributes = { name, additionalParams } 544 const attributes = { name, additionalParams }
541 545
542 if (wait) await waitJobs([ this.server ])
543
544 const result = await this.upload({ ...options, attributes }) 546 const result = await this.upload({ ...options, attributes })
545 547
548 if (wait) await waitJobs([ this.server ])
549
546 return { ...result, name } 550 return { ...result, name }
547 } 551 }
548 552
@@ -566,7 +570,7 @@ export class VideosCommand extends AbstractCommand {
566 } 570 }
567 571
568 private buildUploadFields (attributes: VideoEdit) { 572 private buildUploadFields (attributes: VideoEdit) {
569 return omit(attributes, [ 'thumbnailfile', 'previewfile' ]) 573 return omit(attributes, [ 'fixture', 'thumbnailfile', 'previewfile' ])
570 } 574 }
571 575
572 private buildUploadAttaches (attributes: VideoEdit) { 576 private buildUploadAttaches (attributes: VideoEdit) {