]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - shared/server-commands/videos/videos-command.ts
Merge branch 'release/4.2.0' into develop
[github/Chocobozzz/PeerTube.git] / shared / server-commands / videos / videos-command.ts
index ead57b9aa6a9d87a4105c6627b68703a29e13d39..e952c9777d0187f502864cd1ace1dfc249578c23 100644 (file)
@@ -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<Omit<VideoCreate, 'thumbnailfile' | 'previewfile'>> & {
   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<VideoSource>({
+      ...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',