X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=shared%2Fserver-commands%2Fvideos%2Fvideos-command.ts;h=b5df9c32534a05a00849d691c0a7e71938962505;hb=5170f492b95dc81b75230312411c5fdb0019eed2;hp=1cceb58dbd3b259d6ceb264ccbbbc14afb4b5186;hpb=33ac85bf610d74d353ee456a286159872cdd83cc;p=github%2FChocobozzz%2FPeerTube.git diff --git a/shared/server-commands/videos/videos-command.ts b/shared/server-commands/videos/videos-command.ts index 1cceb58db..b5df9c325 100644 --- a/shared/server-commands/videos/videos-command.ts +++ b/shared/server-commands/videos/videos-command.ts @@ -3,9 +3,8 @@ import { expect } from 'chai' import { createReadStream, stat } from 'fs-extra' import got, { Response as GotResponse } from 'got' -import { omit } from 'lodash' import validator from 'validator' -import { buildAbsoluteFixturePath, pick, wait } from '@shared/core-utils' +import { buildAbsoluteFixturePath, getAllPrivacies, omit, pick, wait } from '@shared/core-utils' import { buildUUID } from '@shared/extra-utils' import { HttpStatusCode, @@ -16,10 +15,12 @@ import { VideoCreateResult, VideoDetails, VideoFileMetadata, + VideoInclude, VideoPrivacy, VideosCommonQuery, VideoTranscodingCreate } from '@shared/models' +import { VideoSource } from '@shared/models/videos/video-source' import { unwrapBody } from '../requests' import { waitJobs } from '../server' import { AbstractCommand, OverrideCommandOptions } from '../shared' @@ -150,6 +151,20 @@ export class VideosCommand extends AbstractCommand { }) } + getSource (options: OverrideCommandOptions & { + id: number | string + }) { + const path = '/api/v1/videos/' + options.id + '/source' + + return this.getRequestBody({ + ...options, + + path, + implicitToken: true, + defaultExpectedStatus: HttpStatusCode.OK_200 + }) + } + async getId (options: OverrideCommandOptions & { uuid: number | string }) { @@ -195,6 +210,20 @@ export class VideosCommand extends AbstractCommand { }) } + listMySubscriptionVideos (options: OverrideCommandOptions & VideosCommonQuery = {}) { + const { sort = '-createdAt' } = options + const path = '/api/v1/users/me/subscriptions/videos' + + return this.getRequestBody>({ + ...options, + + path, + query: { sort, ...this.buildListQuery(options) }, + implicitToken: true, + defaultExpectedStatus: HttpStatusCode.OK_200 + }) + } + // --------------------------------------------------------------------------- list (options: OverrideCommandOptions & VideosCommonQuery = {}) { @@ -220,6 +249,22 @@ export class VideosCommand extends AbstractCommand { }) } + listAllForAdmin (options: OverrideCommandOptions & VideosCommonQuery = {}) { + const include = VideoInclude.NOT_PUBLISHED_STATE | VideoInclude.BLACKLISTED | VideoInclude.BLOCKED_OWNER + const nsfw = 'both' + const privacyOneOf = getAllPrivacies() + + return this.list({ + ...options, + + include, + nsfw, + privacyOneOf, + + token: this.buildCommonRequestToken({ ...options, implicitToken: true }) + }) + } + listByAccount (options: OverrideCommandOptions & VideosCommonQuery & { handle: string }) { @@ -328,8 +373,9 @@ export class VideosCommand extends AbstractCommand { async upload (options: OverrideCommandOptions & { attributes?: VideoEdit mode?: 'legacy' | 'resumable' // default legacy + waitTorrentGeneration?: boolean // default true } = {}) { - const { mode = 'legacy' } = options + const { mode = 'legacy', waitTorrentGeneration = true } = options let defaultChannelId = 1 try { @@ -363,7 +409,7 @@ export class VideosCommand extends AbstractCommand { // Wait torrent generation const expectedStatus = this.buildExpectedStatus({ ...options, defaultExpectedStatus: HttpStatusCode.OK_200 }) - if (expectedStatus === HttpStatusCode.OK_200) { + if (expectedStatus === HttpStatusCode.OK_200 && waitTorrentGeneration) { let video: VideoDetails do { @@ -469,7 +515,7 @@ export class VideosCommand extends AbstractCommand { }, // Fixture will be sent later - attaches: this.buildUploadAttaches(omit(options.attributes, 'fixture')), + attaches: this.buildUploadAttaches(omit(options.attributes, [ 'fixture' ])), implicitToken: true, defaultExpectedStatus: null @@ -590,7 +636,7 @@ export class VideosCommand extends AbstractCommand { // --------------------------------------------------------------------------- - removeHLSFiles (options: OverrideCommandOptions & { + removeHLSPlaylist (options: OverrideCommandOptions & { videoId: number | string }) { const path = '/api/v1/videos/' + options.videoId + '/hls' @@ -604,7 +650,22 @@ export class VideosCommand extends AbstractCommand { }) } - removeWebTorrentFiles (options: OverrideCommandOptions & { + removeHLSFile (options: OverrideCommandOptions & { + videoId: number | string + fileId: number + }) { + const path = '/api/v1/videos/' + options.videoId + '/hls/' + options.fileId + + return this.deleteRequest({ + ...options, + + path, + implicitToken: true, + defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 + }) + } + + removeAllWebTorrentFiles (options: OverrideCommandOptions & { videoId: number | string }) { const path = '/api/v1/videos/' + options.videoId + '/webtorrent' @@ -618,6 +679,21 @@ export class VideosCommand extends AbstractCommand { }) } + removeWebTorrentFile (options: OverrideCommandOptions & { + videoId: number | string + fileId: number + }) { + const path = '/api/v1/videos/' + options.videoId + '/webtorrent/' + options.fileId + + return this.deleteRequest({ + ...options, + + path, + implicitToken: true, + defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 + }) + } + runTranscoding (options: OverrideCommandOptions & { videoId: number | string transcodingType: 'hls' | 'webtorrent' @@ -648,6 +724,7 @@ export class VideosCommand extends AbstractCommand { 'categoryOneOf', 'licenceOneOf', 'languageOneOf', + 'privacyOneOf', 'tagsOneOf', 'tagsAllOf', 'isLocal',