X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=sidebyside;f=shared%2Fextra-utils%2Fvideos%2Fvideos-command.ts;h=7ec9c3647cbc67a419d67c5e2454014de5887771;hb=ad5db1044c8599eaaaa2a578b350777ae996b068;hp=98465e8f69f9d7741709ab16c5c7f04938ff2bdb;hpb=ac27887774e63d99f4e227fbe18846f143cc4b3c;p=github%2FChocobozzz%2FPeerTube.git diff --git a/shared/extra-utils/videos/videos-command.ts b/shared/extra-utils/videos/videos-command.ts index 98465e8f6..7ec9c3647 100644 --- a/shared/extra-utils/videos/videos-command.ts +++ b/shared/extra-utils/videos/videos-command.ts @@ -3,10 +3,11 @@ import { expect } from 'chai' import { createReadStream, stat } from 'fs-extra' import got, { Response as GotResponse } from 'got' -import { omit, pick } from 'lodash' +import { omit } from 'lodash' import validator from 'validator' import { buildUUID } from '@server/helpers/uuid' import { loadLanguages } from '@server/initializers/constants' +import { pick } from '@shared/core-utils' import { HttpStatusCode, ResultList, @@ -18,7 +19,7 @@ import { VideoFileMetadata, VideoPrivacy, VideosCommonQuery, - VideosWithSearchCommonQuery + VideoTranscodingCreate } from '@shared/models' import { buildAbsoluteFixturePath, wait } from '../miscs' import { unwrapBody } from '../requests' @@ -187,6 +188,17 @@ export class VideosCommand extends AbstractCommand { return id } + async listFiles (options: OverrideCommandOptions & { + id: number | string + }) { + const video = await this.get(options) + + const files = video.files || [] + const hlsFiles = video.streamingPlaylists[0]?.files || [] + + return files.concat(hlsFiles) + } + // --------------------------------------------------------------------------- listMyVideos (options: OverrideCommandOptions & { @@ -195,6 +207,7 @@ export class VideosCommand extends AbstractCommand { sort?: string search?: string isLive?: boolean + channelId?: number } = {}) { const path = '/api/v1/users/me/videos' @@ -202,7 +215,7 @@ export class VideosCommand extends AbstractCommand { ...options, path, - query: pick(options, [ 'start', 'count', 'sort', 'search', 'isLive' ]), + query: pick(options, [ 'start', 'count', 'sort', 'search', 'isLive', 'channelId' ]), implicitToken: true, defaultExpectedStatus: HttpStatusCode.OK_200 }) @@ -233,7 +246,7 @@ export class VideosCommand extends AbstractCommand { }) } - listByAccount (options: OverrideCommandOptions & VideosWithSearchCommonQuery & { + listByAccount (options: OverrideCommandOptions & VideosCommonQuery & { handle: string }) { const { handle, search } = options @@ -249,7 +262,7 @@ export class VideosCommand extends AbstractCommand { }) } - listByChannel (options: OverrideCommandOptions & VideosWithSearchCommonQuery & { + listByChannel (options: OverrideCommandOptions & VideosCommonQuery & { handle: string }) { const { handle } = options @@ -437,6 +450,10 @@ export class VideosCommand extends AbstractCommand { const result = await this.sendResumableChunks({ ...options, pathUploadId, videoFilePath, size }) + if (result.statusCode === HttpStatusCode.OK_200) { + await this.endResumableUpload({ ...options, expectedStatus: HttpStatusCode.NO_CONTENT_204, pathUploadId }) + } + return result.body?.video || result.body as any } @@ -453,8 +470,11 @@ export class VideosCommand extends AbstractCommand { attributes: VideoEdit size: number mimetype: string + + originalName?: string + lastModified?: number }) { - const { attributes, size, mimetype } = options + const { attributes, originalName, lastModified, size, mimetype } = options const path = '/api/v1/videos/upload-resumable' @@ -466,7 +486,14 @@ export class VideosCommand extends AbstractCommand { 'X-Upload-Content-Type': mimetype, 'X-Upload-Content-Length': size.toString() }, - fields: { filename: attributes.fixture, ...this.buildUploadFields(options.attributes) }, + fields: { + filename: attributes.fixture, + originalName, + lastModified, + + ...this.buildUploadFields(options.attributes) + }, + // Fixture will be sent later attaches: this.buildUploadAttaches(omit(options.attributes, 'fixture')), implicitToken: true, @@ -530,6 +557,19 @@ export class VideosCommand extends AbstractCommand { }) } + endResumableUpload (options: OverrideCommandOptions & { + pathUploadId: string + }) { + return this.deleteRequest({ + ...options, + + path: '/api/v1/videos/upload-resumable', + rawQuery: options.pathUploadId, + implicitToken: true, + defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 + }) + } + quickUpload (options: OverrideCommandOptions & { name: string nsfw?: boolean @@ -563,6 +603,54 @@ export class VideosCommand extends AbstractCommand { // --------------------------------------------------------------------------- + removeHLSFiles (options: OverrideCommandOptions & { + videoId: number | string + }) { + const path = '/api/v1/videos/' + options.videoId + '/hls' + + return this.deleteRequest({ + ...options, + + path, + implicitToken: true, + defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 + }) + } + + removeWebTorrentFiles (options: OverrideCommandOptions & { + videoId: number | string + }) { + const path = '/api/v1/videos/' + options.videoId + '/webtorrent' + + return this.deleteRequest({ + ...options, + + path, + implicitToken: true, + defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 + }) + } + + runTranscoding (options: OverrideCommandOptions & { + videoId: number | string + transcodingType: 'hls' | 'webtorrent' + }) { + const path = '/api/v1/videos/' + options.videoId + '/transcoding' + + const fields: VideoTranscodingCreate = pick(options, [ 'transcodingType' ]) + + return this.postBodyRequest({ + ...options, + + path, + fields, + implicitToken: true, + defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 + }) + } + + // --------------------------------------------------------------------------- + private buildListQuery (options: VideosCommonQuery) { return pick(options, [ 'start', @@ -575,7 +663,8 @@ export class VideosCommand extends AbstractCommand { 'languageOneOf', 'tagsOneOf', 'tagsAllOf', - 'filter', + 'isLocal', + 'include', 'skipCount' ]) }