aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/server-commands
diff options
context:
space:
mode:
Diffstat (limited to 'shared/server-commands')
-rw-r--r--shared/server-commands/requests/requests.ts19
-rw-r--r--shared/server-commands/server/server.ts3
-rw-r--r--shared/server-commands/videos/index.ts1
-rw-r--r--shared/server-commands/videos/live-command.ts26
-rw-r--r--shared/server-commands/videos/live.ts7
-rw-r--r--shared/server-commands/videos/video-token-command.ts31
-rw-r--r--shared/server-commands/videos/videos-command.ts6
7 files changed, 85 insertions, 8 deletions
diff --git a/shared/server-commands/requests/requests.ts b/shared/server-commands/requests/requests.ts
index 8cc1245e0..b247017fd 100644
--- a/shared/server-commands/requests/requests.ts
+++ b/shared/server-commands/requests/requests.ts
@@ -3,7 +3,7 @@
3import { decode } from 'querystring' 3import { decode } from 'querystring'
4import request from 'supertest' 4import request from 'supertest'
5import { URL } from 'url' 5import { URL } from 'url'
6import { buildAbsoluteFixturePath } from '@shared/core-utils' 6import { buildAbsoluteFixturePath, pick } from '@shared/core-utils'
7import { HttpStatusCode } from '@shared/models' 7import { HttpStatusCode } from '@shared/models'
8 8
9export type CommonRequestParams = { 9export type CommonRequestParams = {
@@ -21,10 +21,21 @@ export type CommonRequestParams = {
21 expectedStatus?: HttpStatusCode 21 expectedStatus?: HttpStatusCode
22} 22}
23 23
24function makeRawRequest (url: string, expectedStatus?: HttpStatusCode, range?: string) { 24function makeRawRequest (options: {
25 const { host, protocol, pathname } = new URL(url) 25 url: string
26 token?: string
27 expectedStatus?: HttpStatusCode
28 range?: string
29 query?: { [ id: string ]: string }
30}) {
31 const { host, protocol, pathname } = new URL(options.url)
32
33 return makeGetRequest({
34 url: `${protocol}//${host}`,
35 path: pathname,
26 36
27 return makeGetRequest({ url: `${protocol}//${host}`, path: pathname, expectedStatus, range }) 37 ...pick(options, [ 'expectedStatus', 'range', 'token', 'query' ])
38 })
28} 39}
29 40
30function makeGetRequest (options: CommonRequestParams & { 41function makeGetRequest (options: CommonRequestParams & {
diff --git a/shared/server-commands/server/server.ts b/shared/server-commands/server/server.ts
index 7096faf21..c062e6986 100644
--- a/shared/server-commands/server/server.ts
+++ b/shared/server-commands/server/server.ts
@@ -36,6 +36,7 @@ import {
36 StreamingPlaylistsCommand, 36 StreamingPlaylistsCommand,
37 VideosCommand, 37 VideosCommand,
38 VideoStudioCommand, 38 VideoStudioCommand,
39 VideoTokenCommand,
39 ViewsCommand 40 ViewsCommand
40} from '../videos' 41} from '../videos'
41import { CommentsCommand } from '../videos/comments-command' 42import { CommentsCommand } from '../videos/comments-command'
@@ -145,6 +146,7 @@ export class PeerTubeServer {
145 videoStats?: VideoStatsCommand 146 videoStats?: VideoStatsCommand
146 views?: ViewsCommand 147 views?: ViewsCommand
147 twoFactor?: TwoFactorCommand 148 twoFactor?: TwoFactorCommand
149 videoToken?: VideoTokenCommand
148 150
149 constructor (options: { serverNumber: number } | { url: string }) { 151 constructor (options: { serverNumber: number } | { url: string }) {
150 if ((options as any).url) { 152 if ((options as any).url) {
@@ -427,5 +429,6 @@ export class PeerTubeServer {
427 this.videoStats = new VideoStatsCommand(this) 429 this.videoStats = new VideoStatsCommand(this)
428 this.views = new ViewsCommand(this) 430 this.views = new ViewsCommand(this)
429 this.twoFactor = new TwoFactorCommand(this) 431 this.twoFactor = new TwoFactorCommand(this)
432 this.videoToken = new VideoTokenCommand(this)
430 } 433 }
431} 434}
diff --git a/shared/server-commands/videos/index.ts b/shared/server-commands/videos/index.ts
index b4d6fa37b..c17f6ef20 100644
--- a/shared/server-commands/videos/index.ts
+++ b/shared/server-commands/videos/index.ts
@@ -14,5 +14,6 @@ export * from './services-command'
14export * from './streaming-playlists-command' 14export * from './streaming-playlists-command'
15export * from './comments-command' 15export * from './comments-command'
16export * from './video-studio-command' 16export * from './video-studio-command'
17export * from './video-token-command'
17export * from './views-command' 18export * from './views-command'
18export * from './videos-command' 19export * from './videos-command'
diff --git a/shared/server-commands/videos/live-command.ts b/shared/server-commands/videos/live-command.ts
index b163f7189..de193fa49 100644
--- a/shared/server-commands/videos/live-command.ts
+++ b/shared/server-commands/videos/live-command.ts
@@ -12,6 +12,7 @@ import {
12 ResultList, 12 ResultList,
13 VideoCreateResult, 13 VideoCreateResult,
14 VideoDetails, 14 VideoDetails,
15 VideoPrivacy,
15 VideoState 16 VideoState
16} from '@shared/models' 17} from '@shared/models'
17import { unwrapBody } from '../requests' 18import { unwrapBody } from '../requests'
@@ -115,6 +116,31 @@ export class LiveCommand extends AbstractCommand {
115 return body.video 116 return body.video
116 } 117 }
117 118
119 async quickCreate (options: OverrideCommandOptions & {
120 saveReplay: boolean
121 permanentLive: boolean
122 privacy?: VideoPrivacy
123 }) {
124 const { saveReplay, permanentLive, privacy } = options
125
126 const { uuid } = await this.create({
127 ...options,
128
129 fields: {
130 name: 'live',
131 permanentLive,
132 saveReplay,
133 channelId: this.server.store.channel.id,
134 privacy
135 }
136 })
137
138 const video = await this.server.videos.getWithToken({ id: uuid })
139 const live = await this.get({ videoId: uuid })
140
141 return { video, live }
142 }
143
118 // --------------------------------------------------------------------------- 144 // ---------------------------------------------------------------------------
119 145
120 async sendRTMPStreamInVideo (options: OverrideCommandOptions & { 146 async sendRTMPStreamInVideo (options: OverrideCommandOptions & {
diff --git a/shared/server-commands/videos/live.ts b/shared/server-commands/videos/live.ts
index 0d9c32aab..ee7444b64 100644
--- a/shared/server-commands/videos/live.ts
+++ b/shared/server-commands/videos/live.ts
@@ -1,6 +1,6 @@
1import ffmpeg, { FfmpegCommand } from 'fluent-ffmpeg' 1import ffmpeg, { FfmpegCommand } from 'fluent-ffmpeg'
2import { buildAbsoluteFixturePath, wait } from '@shared/core-utils' 2import { buildAbsoluteFixturePath, wait } from '@shared/core-utils'
3import { VideoDetails, VideoInclude } from '@shared/models' 3import { VideoDetails, VideoInclude, VideoPrivacy } from '@shared/models'
4import { PeerTubeServer } from '../server/server' 4import { PeerTubeServer } from '../server/server'
5 5
6function sendRTMPStream (options: { 6function sendRTMPStream (options: {
@@ -98,7 +98,10 @@ async function waitUntilLiveReplacedByReplayOnAllServers (servers: PeerTubeServe
98} 98}
99 99
100async function findExternalSavedVideo (server: PeerTubeServer, liveDetails: VideoDetails) { 100async function findExternalSavedVideo (server: PeerTubeServer, liveDetails: VideoDetails) {
101 const { data } = await server.videos.list({ token: server.accessToken, sort: '-publishedAt', include: VideoInclude.BLACKLISTED }) 101 const include = VideoInclude.BLACKLISTED
102 const privacyOneOf = [ VideoPrivacy.INTERNAL, VideoPrivacy.PRIVATE, VideoPrivacy.PUBLIC, VideoPrivacy.UNLISTED ]
103
104 const { data } = await server.videos.list({ token: server.accessToken, sort: '-publishedAt', include, privacyOneOf })
102 105
103 return data.find(v => v.name === liveDetails.name + ' - ' + new Date(liveDetails.publishedAt).toLocaleString()) 106 return data.find(v => v.name === liveDetails.name + ' - ' + new Date(liveDetails.publishedAt).toLocaleString())
104} 107}
diff --git a/shared/server-commands/videos/video-token-command.ts b/shared/server-commands/videos/video-token-command.ts
new file mode 100644
index 000000000..0531bee65
--- /dev/null
+++ b/shared/server-commands/videos/video-token-command.ts
@@ -0,0 +1,31 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/no-floating-promises */
2
3import { HttpStatusCode, VideoToken } from '@shared/models'
4import { unwrapBody } from '../requests'
5import { AbstractCommand, OverrideCommandOptions } from '../shared'
6
7export class VideoTokenCommand extends AbstractCommand {
8
9 create (options: OverrideCommandOptions & {
10 videoId: number | string
11 }) {
12 const { videoId } = options
13 const path = '/api/v1/videos/' + videoId + '/token'
14
15 return unwrapBody<VideoToken>(this.postBodyRequest({
16 ...options,
17
18 path,
19 implicitToken: true,
20 defaultExpectedStatus: HttpStatusCode.OK_200
21 }))
22 }
23
24 async getVideoFileToken (options: OverrideCommandOptions & {
25 videoId: number | string
26 }) {
27 const { files } = await this.create(options)
28
29 return files.token
30 }
31}
diff --git a/shared/server-commands/videos/videos-command.ts b/shared/server-commands/videos/videos-command.ts
index 168391523..5ec3b6ba8 100644
--- a/shared/server-commands/videos/videos-command.ts
+++ b/shared/server-commands/videos/videos-command.ts
@@ -342,8 +342,9 @@ export class VideosCommand extends AbstractCommand {
342 async upload (options: OverrideCommandOptions & { 342 async upload (options: OverrideCommandOptions & {
343 attributes?: VideoEdit 343 attributes?: VideoEdit
344 mode?: 'legacy' | 'resumable' // default legacy 344 mode?: 'legacy' | 'resumable' // default legacy
345 waitTorrentGeneration?: boolean // default true
345 } = {}) { 346 } = {}) {
346 const { mode = 'legacy' } = options 347 const { mode = 'legacy', waitTorrentGeneration } = options
347 let defaultChannelId = 1 348 let defaultChannelId = 1
348 349
349 try { 350 try {
@@ -377,7 +378,7 @@ export class VideosCommand extends AbstractCommand {
377 378
378 // Wait torrent generation 379 // Wait torrent generation
379 const expectedStatus = this.buildExpectedStatus({ ...options, defaultExpectedStatus: HttpStatusCode.OK_200 }) 380 const expectedStatus = this.buildExpectedStatus({ ...options, defaultExpectedStatus: HttpStatusCode.OK_200 })
380 if (expectedStatus === HttpStatusCode.OK_200) { 381 if (expectedStatus === HttpStatusCode.OK_200 && waitTorrentGeneration) {
381 let video: VideoDetails 382 let video: VideoDetails
382 383
383 do { 384 do {
@@ -692,6 +693,7 @@ export class VideosCommand extends AbstractCommand {
692 'categoryOneOf', 693 'categoryOneOf',
693 'licenceOneOf', 694 'licenceOneOf',
694 'languageOneOf', 695 'languageOneOf',
696 'privacyOneOf',
695 'tagsOneOf', 697 'tagsOneOf',
696 'tagsAllOf', 698 'tagsAllOf',
697 'isLocal', 699 'isLocal',