X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=shared%2Fserver-commands%2Fvideos%2Fvideos-command.ts;h=e952c9777d0187f502864cd1ace1dfc249578c23;hb=e722fb5923ddf11d72e48cec9788abc64327c22f;hp=ead57b9aa6a9d87a4105c6627b68703a29e13d39;hpb=c55e3d7227fe1453869e309025996b9d75256d5d;p=github%2FChocobozzz%2FPeerTube.git diff --git a/shared/server-commands/videos/videos-command.ts b/shared/server-commands/videos/videos-command.ts index ead57b9aa..e952c9777 100644 --- a/shared/server-commands/videos/videos-command.ts +++ b/shared/server-commands/videos/videos-command.ts @@ -5,7 +5,8 @@ import { createReadStream, stat } from 'fs-extra' import got, { Response as GotResponse } from 'got' import { omit } from 'lodash' import validator from 'validator' -import { buildAbsoluteFixturePath, buildUUID, pick, wait } from '@shared/core-utils' +import { buildAbsoluteFixturePath, pick, wait } from '@shared/core-utils' +import { buildUUID } from '@shared/extra-utils' import { HttpStatusCode, ResultList, @@ -22,6 +23,7 @@ import { 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 @@ -106,23 +108,6 @@ export class VideosCommand extends AbstractCommand { // --------------------------------------------------------------------------- - view (options: OverrideCommandOptions & { - id: number | string - xForwardedFor?: string - }) { - const { id, xForwardedFor } = options - const path = '/api/v1/videos/' + id + '/views' - - return this.postBodyRequest({ - ...options, - - path, - xForwardedFor, - implicitToken: false, - defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 - }) - } - rate (options: OverrideCommandOptions & { id: number | string rating: UserVideoRateType @@ -166,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 }) { @@ -498,8 +497,17 @@ export class VideosCommand extends AbstractCommand { size: number contentLength?: number contentRangeBuilder?: (start: number, chunk: any) => string + digestBuilder?: (chunk: any) => string }) { - const { pathUploadId, videoFilePath, size, contentLength, contentRangeBuilder, expectedStatus = HttpStatusCode.OK_200 } = options + const { + pathUploadId, + videoFilePath, + size, + contentLength, + contentRangeBuilder, + digestBuilder, + expectedStatus = HttpStatusCode.OK_200 + } = options const path = '/api/v1/videos/upload-resumable' let start = 0 @@ -521,6 +529,10 @@ export class VideosCommand extends AbstractCommand { 'Content-Length': contentLength ? contentLength + '' : chunk.length + '' } + if (digestBuilder) { + Object.assign(headers, { digest: digestBuilder(chunk) }) + } + const res = await got<{ video: VideoCreateResult }>({ url, method: 'put',