X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=shared%2Fserver-commands%2Fvideos%2Fvideos-command.ts;h=b5df9c32534a05a00849d691c0a7e71938962505;hb=5170f492b95dc81b75230312411c5fdb0019eed2;hp=e952c9777d0187f502864cd1ace1dfc249578c23;hpb=64324ac646b0938e35cd88771492623b640bd0d8;p=github%2FChocobozzz%2FPeerTube.git diff --git a/shared/server-commands/videos/videos-command.ts b/shared/server-commands/videos/videos-command.ts index e952c9777..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,14 +15,15 @@ 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' -import { VideoSource } from '@shared/models/videos/video-source' export type VideoEdit = Partial> & { fixture?: string @@ -210,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 = {}) { @@ -235,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 }) { @@ -343,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 { @@ -378,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 { @@ -484,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 @@ -605,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' @@ -619,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' @@ -633,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' @@ -663,6 +724,7 @@ export class VideosCommand extends AbstractCommand { 'categoryOneOf', 'licenceOneOf', 'languageOneOf', + 'privacyOneOf', 'tagsOneOf', 'tagsAllOf', 'isLocal',