diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-16 10:42:24 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-20 15:27:18 +0200 |
commit | c0e8b12e7fd554ba4d2ceb0c4900804c6a4c63ea (patch) | |
tree | baf29753ac5d4598643e3bee719f8df0cc36c59d /shared/extra-utils/videos | |
parent | 08642a765ea514a00f159db898edf14c376fbe6c (diff) | |
download | PeerTube-c0e8b12e7fd554ba4d2ceb0c4900804c6a4c63ea.tar.gz PeerTube-c0e8b12e7fd554ba4d2ceb0c4900804c6a4c63ea.tar.zst PeerTube-c0e8b12e7fd554ba4d2ceb0c4900804c6a4c63ea.zip |
Refactor requests
Diffstat (limited to 'shared/extra-utils/videos')
-rw-r--r-- | shared/extra-utils/videos/blacklist-command.ts | 2 | ||||
-rw-r--r-- | shared/extra-utils/videos/captions-command.ts | 2 | ||||
-rw-r--r-- | shared/extra-utils/videos/captions.ts | 2 | ||||
-rw-r--r-- | shared/extra-utils/videos/change-ownership-command.ts | 2 | ||||
-rw-r--r-- | shared/extra-utils/videos/channels-command.ts | 2 | ||||
-rw-r--r-- | shared/extra-utils/videos/comments-command.ts | 2 | ||||
-rw-r--r-- | shared/extra-utils/videos/history-command.ts | 2 | ||||
-rw-r--r-- | shared/extra-utils/videos/imports-command.ts | 2 | ||||
-rw-r--r-- | shared/extra-utils/videos/live-command.ts | 2 | ||||
-rw-r--r-- | shared/extra-utils/videos/playlists-command.ts | 2 | ||||
-rw-r--r-- | shared/extra-utils/videos/services-command.ts | 2 | ||||
-rw-r--r-- | shared/extra-utils/videos/streaming-playlists-command.ts | 3 | ||||
-rw-r--r-- | shared/extra-utils/videos/streaming-playlists.ts | 2 | ||||
-rw-r--r-- | shared/extra-utils/videos/videos-command.ts | 36 | ||||
-rw-r--r-- | shared/extra-utils/videos/videos.ts | 2 |
15 files changed, 34 insertions, 31 deletions
diff --git a/shared/extra-utils/videos/blacklist-command.ts b/shared/extra-utils/videos/blacklist-command.ts index fdae6b469..9404d4c08 100644 --- a/shared/extra-utils/videos/blacklist-command.ts +++ b/shared/extra-utils/videos/blacklist-command.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | 1 | ||
2 | import { ResultList } from '@shared/models' | 2 | import { ResultList } from '@shared/models' |
3 | import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' | 3 | import { HttpStatusCode } from '@shared/models' |
4 | import { VideoBlacklist, VideoBlacklistType } from '../../models/videos' | 4 | import { VideoBlacklist, VideoBlacklistType } from '../../models/videos' |
5 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | 5 | import { AbstractCommand, OverrideCommandOptions } from '../shared' |
6 | 6 | ||
diff --git a/shared/extra-utils/videos/captions-command.ts b/shared/extra-utils/videos/captions-command.ts index ac3bde7a9..04dd32f84 100644 --- a/shared/extra-utils/videos/captions-command.ts +++ b/shared/extra-utils/videos/captions-command.ts | |||
@@ -1,4 +1,4 @@ | |||
1 | import { HttpStatusCode } from '@shared/core-utils' | 1 | import { HttpStatusCode } from '@shared/models' |
2 | import { ResultList, VideoCaption } from '@shared/models' | 2 | import { ResultList, VideoCaption } from '@shared/models' |
3 | import { buildAbsoluteFixturePath } from '../miscs' | 3 | import { buildAbsoluteFixturePath } from '../miscs' |
4 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | 4 | import { AbstractCommand, OverrideCommandOptions } from '../shared' |
diff --git a/shared/extra-utils/videos/captions.ts b/shared/extra-utils/videos/captions.ts index 2246bd133..ff8a43366 100644 --- a/shared/extra-utils/videos/captions.ts +++ b/shared/extra-utils/videos/captions.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import { expect } from 'chai' | 1 | import { expect } from 'chai' |
2 | import * as request from 'supertest' | 2 | import * as request from 'supertest' |
3 | import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' | 3 | import { HttpStatusCode } from '@shared/models' |
4 | 4 | ||
5 | async function testCaptionFile (url: string, captionPath: string, containsString: string) { | 5 | async function testCaptionFile (url: string, captionPath: string, containsString: string) { |
6 | const res = await request(url) | 6 | const res = await request(url) |
diff --git a/shared/extra-utils/videos/change-ownership-command.ts b/shared/extra-utils/videos/change-ownership-command.ts index 03f77a95f..ef6f07536 100644 --- a/shared/extra-utils/videos/change-ownership-command.ts +++ b/shared/extra-utils/videos/change-ownership-command.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | 1 | ||
2 | import { ResultList, VideoChangeOwnership } from '@shared/models' | 2 | import { ResultList, VideoChangeOwnership } from '@shared/models' |
3 | import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' | 3 | import { HttpStatusCode } from '@shared/models' |
4 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | 4 | import { AbstractCommand, OverrideCommandOptions } from '../shared' |
5 | 5 | ||
6 | export class ChangeOwnershipCommand extends AbstractCommand { | 6 | export class ChangeOwnershipCommand extends AbstractCommand { |
diff --git a/shared/extra-utils/videos/channels-command.ts b/shared/extra-utils/videos/channels-command.ts index a98c5cc93..e5393ff56 100644 --- a/shared/extra-utils/videos/channels-command.ts +++ b/shared/extra-utils/videos/channels-command.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import { pick } from 'lodash' | 1 | import { pick } from 'lodash' |
2 | import { ResultList, VideoChannel, VideoChannelCreateResult } from '@shared/models' | 2 | import { ResultList, VideoChannel, VideoChannelCreateResult } from '@shared/models' |
3 | import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' | 3 | import { HttpStatusCode } from '@shared/models' |
4 | import { VideoChannelCreate } from '../../models/videos/channel/video-channel-create.model' | 4 | import { VideoChannelCreate } from '../../models/videos/channel/video-channel-create.model' |
5 | import { VideoChannelUpdate } from '../../models/videos/channel/video-channel-update.model' | 5 | import { VideoChannelUpdate } from '../../models/videos/channel/video-channel-update.model' |
6 | import { unwrapBody } from '../requests' | 6 | import { unwrapBody } from '../requests' |
diff --git a/shared/extra-utils/videos/comments-command.ts b/shared/extra-utils/videos/comments-command.ts index b31f3e2dd..7368f3ea2 100644 --- a/shared/extra-utils/videos/comments-command.ts +++ b/shared/extra-utils/videos/comments-command.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import { pick } from 'lodash' | 1 | import { pick } from 'lodash' |
2 | import { HttpStatusCode } from '@shared/models' | ||
2 | import { ResultList, VideoComment, VideoCommentThreads, VideoCommentThreadTree } from '@shared/models' | 3 | import { ResultList, VideoComment, VideoCommentThreads, VideoCommentThreadTree } from '@shared/models' |
3 | import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' | ||
4 | import { unwrapBody } from '../requests' | 4 | import { unwrapBody } from '../requests' |
5 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | 5 | import { AbstractCommand, OverrideCommandOptions } from '../shared' |
6 | 6 | ||
diff --git a/shared/extra-utils/videos/history-command.ts b/shared/extra-utils/videos/history-command.ts index 8a144a312..41afc6bc6 100644 --- a/shared/extra-utils/videos/history-command.ts +++ b/shared/extra-utils/videos/history-command.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import { HttpStatusCode } from '@shared/models' | ||
1 | import { ResultList, Video } from '@shared/models' | 2 | import { ResultList, Video } from '@shared/models' |
2 | import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' | ||
3 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | 3 | import { AbstractCommand, OverrideCommandOptions } from '../shared' |
4 | 4 | ||
5 | export class HistoryCommand extends AbstractCommand { | 5 | export class HistoryCommand extends AbstractCommand { |
diff --git a/shared/extra-utils/videos/imports-command.ts b/shared/extra-utils/videos/imports-command.ts index de8b65829..d30f9745b 100644 --- a/shared/extra-utils/videos/imports-command.ts +++ b/shared/extra-utils/videos/imports-command.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | 1 | ||
2 | import { HttpStatusCode } from '@shared/models' | ||
2 | import { ResultList } from '@shared/models' | 3 | import { ResultList } from '@shared/models' |
3 | import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' | ||
4 | import { VideoImport, VideoImportCreate } from '../../models/videos' | 4 | import { VideoImport, VideoImportCreate } from '../../models/videos' |
5 | import { unwrapBody } from '../requests' | 5 | import { unwrapBody } from '../requests' |
6 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | 6 | import { AbstractCommand, OverrideCommandOptions } from '../shared' |
diff --git a/shared/extra-utils/videos/live-command.ts b/shared/extra-utils/videos/live-command.ts index fd66c9924..9dfe3087e 100644 --- a/shared/extra-utils/videos/live-command.ts +++ b/shared/extra-utils/videos/live-command.ts | |||
@@ -3,8 +3,8 @@ | |||
3 | import { readdir } from 'fs-extra' | 3 | import { readdir } from 'fs-extra' |
4 | import { omit } from 'lodash' | 4 | import { omit } from 'lodash' |
5 | import { join } from 'path' | 5 | import { join } from 'path' |
6 | import { HttpStatusCode } from '@shared/models' | ||
6 | import { LiveVideo, LiveVideoCreate, LiveVideoUpdate, VideoCreateResult, VideoDetails, VideoState } from '@shared/models' | 7 | import { LiveVideo, LiveVideoCreate, LiveVideoUpdate, VideoCreateResult, VideoDetails, VideoState } from '@shared/models' |
7 | import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' | ||
8 | import { wait } from '../miscs' | 8 | import { wait } from '../miscs' |
9 | import { unwrapBody } from '../requests' | 9 | import { unwrapBody } from '../requests' |
10 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | 10 | import { AbstractCommand, OverrideCommandOptions } from '../shared' |
diff --git a/shared/extra-utils/videos/playlists-command.ts b/shared/extra-utils/videos/playlists-command.ts index cbfc7e10f..40162c30d 100644 --- a/shared/extra-utils/videos/playlists-command.ts +++ b/shared/extra-utils/videos/playlists-command.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import { omit, pick } from 'lodash' | 1 | import { omit, pick } from 'lodash' |
2 | import { HttpStatusCode } from '@shared/core-utils' | 2 | import { HttpStatusCode } from '@shared/models' |
3 | import { | 3 | import { |
4 | BooleanBothQuery, | 4 | BooleanBothQuery, |
5 | ResultList, | 5 | ResultList, |
diff --git a/shared/extra-utils/videos/services-command.ts b/shared/extra-utils/videos/services-command.ts index 313b7878c..06760df42 100644 --- a/shared/extra-utils/videos/services-command.ts +++ b/shared/extra-utils/videos/services-command.ts | |||
@@ -1,4 +1,4 @@ | |||
1 | import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' | 1 | import { HttpStatusCode } from '@shared/models' |
2 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | 2 | import { AbstractCommand, OverrideCommandOptions } from '../shared' |
3 | 3 | ||
4 | export class ServicesCommand extends AbstractCommand { | 4 | export class ServicesCommand extends AbstractCommand { |
diff --git a/shared/extra-utils/videos/streaming-playlists-command.ts b/shared/extra-utils/videos/streaming-playlists-command.ts index fab3eb556..9662685da 100644 --- a/shared/extra-utils/videos/streaming-playlists-command.ts +++ b/shared/extra-utils/videos/streaming-playlists-command.ts | |||
@@ -1,5 +1,4 @@ | |||
1 | 1 | import { HttpStatusCode } from '@shared/models' | |
2 | import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' | ||
3 | import { unwrapBody, unwrapText } from '../requests' | 2 | import { unwrapBody, unwrapText } from '../requests' |
4 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | 3 | import { AbstractCommand, OverrideCommandOptions } from '../shared' |
5 | 4 | ||
diff --git a/shared/extra-utils/videos/streaming-playlists.ts b/shared/extra-utils/videos/streaming-playlists.ts index 002ae08b2..007d3d98d 100644 --- a/shared/extra-utils/videos/streaming-playlists.ts +++ b/shared/extra-utils/videos/streaming-playlists.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import { expect } from 'chai' | 1 | import { expect } from 'chai' |
2 | import { sha256 } from '@server/helpers/core-utils' | 2 | import { sha256 } from '@server/helpers/core-utils' |
3 | import { HttpStatusCode } from '@shared/core-utils' | 3 | import { HttpStatusCode } from '@shared/models' |
4 | import { VideoStreamingPlaylist } from '@shared/models' | 4 | import { VideoStreamingPlaylist } from '@shared/models' |
5 | import { PeerTubeServer } from '../server' | 5 | import { PeerTubeServer } from '../server' |
6 | 6 | ||
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' | |||
7 | import validator from 'validator' | 7 | import validator from 'validator' |
8 | import { buildUUID } from '@server/helpers/uuid' | 8 | import { buildUUID } from '@server/helpers/uuid' |
9 | import { loadLanguages } from '@server/initializers/constants' | 9 | import { loadLanguages } from '@server/initializers/constants' |
10 | import { HttpStatusCode } from '@shared/core-utils' | 10 | import { HttpStatusCode } from '@shared/models' |
11 | import { | 11 | import { |
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) { |
diff --git a/shared/extra-utils/videos/videos.ts b/shared/extra-utils/videos/videos.ts index b41533808..a96073c56 100644 --- a/shared/extra-utils/videos/videos.ts +++ b/shared/extra-utils/videos/videos.ts | |||
@@ -4,7 +4,7 @@ import { expect } from 'chai' | |||
4 | import { pathExists, readdir } from 'fs-extra' | 4 | import { pathExists, readdir } from 'fs-extra' |
5 | import { join } from 'path' | 5 | import { join } from 'path' |
6 | import { getLowercaseExtension } from '@server/helpers/core-utils' | 6 | import { getLowercaseExtension } from '@server/helpers/core-utils' |
7 | import { HttpStatusCode } from '@shared/core-utils' | 7 | import { HttpStatusCode } from '@shared/models' |
8 | import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../server/initializers/constants' | 8 | import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../server/initializers/constants' |
9 | import { dateIsValid, testImage, webtorrentAdd } from '../miscs' | 9 | import { dateIsValid, testImage, webtorrentAdd } from '../miscs' |
10 | import { makeRawRequest } from '../requests/requests' | 10 | import { makeRawRequest } from '../requests/requests' |