diff options
Diffstat (limited to 'shared')
-rw-r--r-- | shared/models/plugins/client/client-hook.model.ts | 5 | ||||
-rw-r--r-- | shared/models/plugins/server/server-hook.model.ts | 4 | ||||
-rw-r--r-- | shared/models/users/index.ts | 1 | ||||
-rw-r--r-- | shared/models/users/two-factor-enable-result.model.ts | 7 | ||||
-rw-r--r-- | shared/models/users/user.model.ts | 2 | ||||
-rw-r--r-- | shared/server-commands/requests/requests.ts | 7 | ||||
-rw-r--r-- | shared/server-commands/server/server.ts | 45 | ||||
-rw-r--r-- | shared/server-commands/users/index.ts | 1 | ||||
-rw-r--r-- | shared/server-commands/users/login-command.ts | 73 | ||||
-rw-r--r-- | shared/server-commands/users/two-factor-command.ts | 92 | ||||
-rw-r--r-- | shared/server-commands/users/users-command.ts | 8 | ||||
-rw-r--r-- | shared/server-commands/videos/live-command.ts | 71 | ||||
-rw-r--r-- | shared/server-commands/videos/streaming-playlists-command.ts | 38 |
13 files changed, 292 insertions, 62 deletions
diff --git a/shared/models/plugins/client/client-hook.model.ts b/shared/models/plugins/client/client-hook.model.ts index e6313b60e..20e019304 100644 --- a/shared/models/plugins/client/client-hook.model.ts +++ b/shared/models/plugins/client/client-hook.model.ts | |||
@@ -88,7 +88,10 @@ export const clientFilterHookObject = { | |||
88 | 'filter:share.video-playlist-url.build.result': true, | 88 | 'filter:share.video-playlist-url.build.result': true, |
89 | 89 | ||
90 | // Filter videojs options built for PeerTube player | 90 | // Filter videojs options built for PeerTube player |
91 | 'filter:internal.player.videojs.options.result': true | 91 | 'filter:internal.player.videojs.options.result': true, |
92 | |||
93 | // Filter p2p media loader options built for PeerTube player | ||
94 | 'filter:internal.player.p2p-media-loader.options.result': true | ||
92 | } | 95 | } |
93 | 96 | ||
94 | export type ClientFilterHookName = keyof typeof clientFilterHookObject | 97 | export type ClientFilterHookName = keyof typeof clientFilterHookObject |
diff --git a/shared/models/plugins/server/server-hook.model.ts b/shared/models/plugins/server/server-hook.model.ts index 5bf01c4b4..f11d2050b 100644 --- a/shared/models/plugins/server/server-hook.model.ts +++ b/shared/models/plugins/server/server-hook.model.ts | |||
@@ -103,7 +103,9 @@ export const serverFilterHookObject = { | |||
103 | 'filter:job-queue.process.result': true, | 103 | 'filter:job-queue.process.result': true, |
104 | 104 | ||
105 | 'filter:transcoding.manual.resolutions-to-transcode.result': true, | 105 | 'filter:transcoding.manual.resolutions-to-transcode.result': true, |
106 | 'filter:transcoding.auto.resolutions-to-transcode.result': true | 106 | 'filter:transcoding.auto.resolutions-to-transcode.result': true, |
107 | |||
108 | 'filter:activity-pub.remote-video-comment.create.accept.result': true | ||
107 | } | 109 | } |
108 | 110 | ||
109 | export type ServerFilterHookName = keyof typeof serverFilterHookObject | 111 | export type ServerFilterHookName = keyof typeof serverFilterHookObject |
diff --git a/shared/models/users/index.ts b/shared/models/users/index.ts index b25978587..32f7a441c 100644 --- a/shared/models/users/index.ts +++ b/shared/models/users/index.ts | |||
@@ -1,3 +1,4 @@ | |||
1 | export * from './two-factor-enable-result.model' | ||
1 | export * from './user-create-result.model' | 2 | export * from './user-create-result.model' |
2 | export * from './user-create.model' | 3 | export * from './user-create.model' |
3 | export * from './user-flag.model' | 4 | export * from './user-flag.model' |
diff --git a/shared/models/users/two-factor-enable-result.model.ts b/shared/models/users/two-factor-enable-result.model.ts new file mode 100644 index 000000000..1fc801f0a --- /dev/null +++ b/shared/models/users/two-factor-enable-result.model.ts | |||
@@ -0,0 +1,7 @@ | |||
1 | export interface TwoFactorEnableResult { | ||
2 | otpRequest: { | ||
3 | requestToken: string | ||
4 | secret: string | ||
5 | uri: string | ||
6 | } | ||
7 | } | ||
diff --git a/shared/models/users/user.model.ts b/shared/models/users/user.model.ts index 63c5c8a92..7b6494ff8 100644 --- a/shared/models/users/user.model.ts +++ b/shared/models/users/user.model.ts | |||
@@ -62,6 +62,8 @@ export interface User { | |||
62 | pluginAuth: string | null | 62 | pluginAuth: string | null |
63 | 63 | ||
64 | lastLoginDate: Date | null | 64 | lastLoginDate: Date | null |
65 | |||
66 | twoFactorEnabled: boolean | ||
65 | } | 67 | } |
66 | 68 | ||
67 | export interface MyUserSpecialPlaylist { | 69 | export interface MyUserSpecialPlaylist { |
diff --git a/shared/server-commands/requests/requests.ts b/shared/server-commands/requests/requests.ts index 85cbc9be9..8cc1245e0 100644 --- a/shared/server-commands/requests/requests.ts +++ b/shared/server-commands/requests/requests.ts | |||
@@ -134,7 +134,12 @@ function unwrapText (test: request.Test): Promise<string> { | |||
134 | function unwrapBodyOrDecodeToJSON <T> (test: request.Test): Promise<T> { | 134 | function unwrapBodyOrDecodeToJSON <T> (test: request.Test): Promise<T> { |
135 | return test.then(res => { | 135 | return test.then(res => { |
136 | if (res.body instanceof Buffer) { | 136 | if (res.body instanceof Buffer) { |
137 | return JSON.parse(new TextDecoder().decode(res.body)) | 137 | try { |
138 | return JSON.parse(new TextDecoder().decode(res.body)) | ||
139 | } catch (err) { | ||
140 | console.error('Cannot decode JSON.', res.body) | ||
141 | throw err | ||
142 | } | ||
138 | } | 143 | } |
139 | 144 | ||
140 | return res.body | 145 | return res.body |
diff --git a/shared/server-commands/server/server.ts b/shared/server-commands/server/server.ts index 2b4c9c9f8..7096faf21 100644 --- a/shared/server-commands/server/server.ts +++ b/shared/server-commands/server/server.ts | |||
@@ -13,7 +13,15 @@ import { AbusesCommand } from '../moderation' | |||
13 | import { OverviewsCommand } from '../overviews' | 13 | import { OverviewsCommand } from '../overviews' |
14 | import { SearchCommand } from '../search' | 14 | import { SearchCommand } from '../search' |
15 | import { SocketIOCommand } from '../socket' | 15 | import { SocketIOCommand } from '../socket' |
16 | import { AccountsCommand, BlocklistCommand, LoginCommand, NotificationsCommand, SubscriptionsCommand, UsersCommand } from '../users' | 16 | import { |
17 | AccountsCommand, | ||
18 | BlocklistCommand, | ||
19 | LoginCommand, | ||
20 | NotificationsCommand, | ||
21 | SubscriptionsCommand, | ||
22 | TwoFactorCommand, | ||
23 | UsersCommand | ||
24 | } from '../users' | ||
17 | import { | 25 | import { |
18 | BlacklistCommand, | 26 | BlacklistCommand, |
19 | CaptionsCommand, | 27 | CaptionsCommand, |
@@ -136,6 +144,7 @@ export class PeerTubeServer { | |||
136 | videos?: VideosCommand | 144 | videos?: VideosCommand |
137 | videoStats?: VideoStatsCommand | 145 | videoStats?: VideoStatsCommand |
138 | views?: ViewsCommand | 146 | views?: ViewsCommand |
147 | twoFactor?: TwoFactorCommand | ||
139 | 148 | ||
140 | constructor (options: { serverNumber: number } | { url: string }) { | 149 | constructor (options: { serverNumber: number } | { url: string }) { |
141 | if ((options as any).url) { | 150 | if ((options as any).url) { |
@@ -182,6 +191,12 @@ export class PeerTubeServer { | |||
182 | this.port = parseInt(parsed.port) | 191 | this.port = parseInt(parsed.port) |
183 | } | 192 | } |
184 | 193 | ||
194 | getDirectoryPath (directoryName: string) { | ||
195 | const testDirectory = 'test' + this.internalServerNumber | ||
196 | |||
197 | return join(root(), testDirectory, directoryName) | ||
198 | } | ||
199 | |||
185 | async flushAndRun (configOverride?: Object, options: RunServerOptions = {}) { | 200 | async flushAndRun (configOverride?: Object, options: RunServerOptions = {}) { |
186 | await ServersCommand.flushTests(this.internalServerNumber) | 201 | await ServersCommand.flushTests(this.internalServerNumber) |
187 | 202 | ||
@@ -341,19 +356,20 @@ export class PeerTubeServer { | |||
341 | suffix: '_test' + this.internalServerNumber | 356 | suffix: '_test' + this.internalServerNumber |
342 | }, | 357 | }, |
343 | storage: { | 358 | storage: { |
344 | tmp: `test${this.internalServerNumber}/tmp/`, | 359 | tmp: this.getDirectoryPath('tmp') + '/', |
345 | bin: `test${this.internalServerNumber}/bin/`, | 360 | bin: this.getDirectoryPath('bin') + '/', |
346 | avatars: `test${this.internalServerNumber}/avatars/`, | 361 | avatars: this.getDirectoryPath('avatars') + '/', |
347 | videos: `test${this.internalServerNumber}/videos/`, | 362 | videos: this.getDirectoryPath('videos') + '/', |
348 | streaming_playlists: `test${this.internalServerNumber}/streaming-playlists/`, | 363 | streaming_playlists: this.getDirectoryPath('streaming-playlists') + '/', |
349 | redundancy: `test${this.internalServerNumber}/redundancy/`, | 364 | redundancy: this.getDirectoryPath('redundancy') + '/', |
350 | logs: `test${this.internalServerNumber}/logs/`, | 365 | logs: this.getDirectoryPath('logs') + '/', |
351 | previews: `test${this.internalServerNumber}/previews/`, | 366 | previews: this.getDirectoryPath('previews') + '/', |
352 | thumbnails: `test${this.internalServerNumber}/thumbnails/`, | 367 | thumbnails: this.getDirectoryPath('thumbnails') + '/', |
353 | torrents: `test${this.internalServerNumber}/torrents/`, | 368 | torrents: this.getDirectoryPath('torrents') + '/', |
354 | captions: `test${this.internalServerNumber}/captions/`, | 369 | captions: this.getDirectoryPath('captions') + '/', |
355 | cache: `test${this.internalServerNumber}/cache/`, | 370 | cache: this.getDirectoryPath('cache') + '/', |
356 | plugins: `test${this.internalServerNumber}/plugins/` | 371 | plugins: this.getDirectoryPath('plugins') + '/', |
372 | well_known: this.getDirectoryPath('well-known') + '/' | ||
357 | }, | 373 | }, |
358 | admin: { | 374 | admin: { |
359 | email: `admin${this.internalServerNumber}@example.com` | 375 | email: `admin${this.internalServerNumber}@example.com` |
@@ -410,5 +426,6 @@ export class PeerTubeServer { | |||
410 | this.videoStudio = new VideoStudioCommand(this) | 426 | this.videoStudio = new VideoStudioCommand(this) |
411 | this.videoStats = new VideoStatsCommand(this) | 427 | this.videoStats = new VideoStatsCommand(this) |
412 | this.views = new ViewsCommand(this) | 428 | this.views = new ViewsCommand(this) |
429 | this.twoFactor = new TwoFactorCommand(this) | ||
413 | } | 430 | } |
414 | } | 431 | } |
diff --git a/shared/server-commands/users/index.ts b/shared/server-commands/users/index.ts index f6f93b4d2..1afc02dc1 100644 --- a/shared/server-commands/users/index.ts +++ b/shared/server-commands/users/index.ts | |||
@@ -5,4 +5,5 @@ export * from './login' | |||
5 | export * from './login-command' | 5 | export * from './login-command' |
6 | export * from './notifications-command' | 6 | export * from './notifications-command' |
7 | export * from './subscriptions-command' | 7 | export * from './subscriptions-command' |
8 | export * from './two-factor-command' | ||
8 | export * from './users-command' | 9 | export * from './users-command' |
diff --git a/shared/server-commands/users/login-command.ts b/shared/server-commands/users/login-command.ts index 54070e426..f2fc6d1c5 100644 --- a/shared/server-commands/users/login-command.ts +++ b/shared/server-commands/users/login-command.ts | |||
@@ -2,34 +2,27 @@ import { HttpStatusCode, PeerTubeProblemDocument } from '@shared/models' | |||
2 | import { unwrapBody } from '../requests' | 2 | import { unwrapBody } from '../requests' |
3 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | 3 | import { AbstractCommand, OverrideCommandOptions } from '../shared' |
4 | 4 | ||
5 | type LoginOptions = OverrideCommandOptions & { | ||
6 | client?: { id?: string, secret?: string } | ||
7 | user?: { username: string, password?: string } | ||
8 | otpToken?: string | ||
9 | } | ||
10 | |||
5 | export class LoginCommand extends AbstractCommand { | 11 | export class LoginCommand extends AbstractCommand { |
6 | 12 | ||
7 | login (options: OverrideCommandOptions & { | 13 | async login (options: LoginOptions = {}) { |
8 | client?: { id?: string, secret?: string } | 14 | const res = await this._login(options) |
9 | user?: { username: string, password?: string } | ||
10 | } = {}) { | ||
11 | const { client = this.server.store.client, user = this.server.store.user } = options | ||
12 | const path = '/api/v1/users/token' | ||
13 | 15 | ||
14 | const body = { | 16 | return this.unwrapLoginBody(res.body) |
15 | client_id: client.id, | 17 | } |
16 | client_secret: client.secret, | ||
17 | username: user.username, | ||
18 | password: user.password ?? 'password', | ||
19 | response_type: 'code', | ||
20 | grant_type: 'password', | ||
21 | scope: 'upload' | ||
22 | } | ||
23 | 18 | ||
24 | return unwrapBody<{ access_token: string, refresh_token: string } & PeerTubeProblemDocument>(this.postBodyRequest({ | 19 | async loginAndGetResponse (options: LoginOptions = {}) { |
25 | ...options, | 20 | const res = await this._login(options) |
26 | 21 | ||
27 | path, | 22 | return { |
28 | requestType: 'form', | 23 | res, |
29 | fields: body, | 24 | body: this.unwrapLoginBody(res.body) |
30 | implicitToken: false, | 25 | } |
31 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
32 | })) | ||
33 | } | 26 | } |
34 | 27 | ||
35 | getAccessToken (arg1?: { username: string, password?: string }): Promise<string> | 28 | getAccessToken (arg1?: { username: string, password?: string }): Promise<string> |
@@ -129,4 +122,38 @@ export class LoginCommand extends AbstractCommand { | |||
129 | defaultExpectedStatus: HttpStatusCode.OK_200 | 122 | defaultExpectedStatus: HttpStatusCode.OK_200 |
130 | }) | 123 | }) |
131 | } | 124 | } |
125 | |||
126 | private _login (options: LoginOptions) { | ||
127 | const { client = this.server.store.client, user = this.server.store.user, otpToken } = options | ||
128 | const path = '/api/v1/users/token' | ||
129 | |||
130 | const body = { | ||
131 | client_id: client.id, | ||
132 | client_secret: client.secret, | ||
133 | username: user.username, | ||
134 | password: user.password ?? 'password', | ||
135 | response_type: 'code', | ||
136 | grant_type: 'password', | ||
137 | scope: 'upload' | ||
138 | } | ||
139 | |||
140 | const headers = otpToken | ||
141 | ? { 'x-peertube-otp': otpToken } | ||
142 | : {} | ||
143 | |||
144 | return this.postBodyRequest({ | ||
145 | ...options, | ||
146 | |||
147 | path, | ||
148 | headers, | ||
149 | requestType: 'form', | ||
150 | fields: body, | ||
151 | implicitToken: false, | ||
152 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
153 | }) | ||
154 | } | ||
155 | |||
156 | private unwrapLoginBody (body: any) { | ||
157 | return body as { access_token: string, refresh_token: string } & PeerTubeProblemDocument | ||
158 | } | ||
132 | } | 159 | } |
diff --git a/shared/server-commands/users/two-factor-command.ts b/shared/server-commands/users/two-factor-command.ts new file mode 100644 index 000000000..5542acfda --- /dev/null +++ b/shared/server-commands/users/two-factor-command.ts | |||
@@ -0,0 +1,92 @@ | |||
1 | import { TOTP } from 'otpauth' | ||
2 | import { HttpStatusCode, TwoFactorEnableResult } from '@shared/models' | ||
3 | import { unwrapBody } from '../requests' | ||
4 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
5 | |||
6 | export class TwoFactorCommand extends AbstractCommand { | ||
7 | |||
8 | static buildOTP (options: { | ||
9 | secret: string | ||
10 | }) { | ||
11 | const { secret } = options | ||
12 | |||
13 | return new TOTP({ | ||
14 | issuer: 'PeerTube', | ||
15 | algorithm: 'SHA1', | ||
16 | digits: 6, | ||
17 | period: 30, | ||
18 | secret | ||
19 | }) | ||
20 | } | ||
21 | |||
22 | request (options: OverrideCommandOptions & { | ||
23 | userId: number | ||
24 | currentPassword?: string | ||
25 | }) { | ||
26 | const { currentPassword, userId } = options | ||
27 | |||
28 | const path = '/api/v1/users/' + userId + '/two-factor/request' | ||
29 | |||
30 | return unwrapBody<TwoFactorEnableResult>(this.postBodyRequest({ | ||
31 | ...options, | ||
32 | |||
33 | path, | ||
34 | fields: { currentPassword }, | ||
35 | implicitToken: true, | ||
36 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
37 | })) | ||
38 | } | ||
39 | |||
40 | confirmRequest (options: OverrideCommandOptions & { | ||
41 | userId: number | ||
42 | requestToken: string | ||
43 | otpToken: string | ||
44 | }) { | ||
45 | const { userId, requestToken, otpToken } = options | ||
46 | |||
47 | const path = '/api/v1/users/' + userId + '/two-factor/confirm-request' | ||
48 | |||
49 | return this.postBodyRequest({ | ||
50 | ...options, | ||
51 | |||
52 | path, | ||
53 | fields: { requestToken, otpToken }, | ||
54 | implicitToken: true, | ||
55 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
56 | }) | ||
57 | } | ||
58 | |||
59 | disable (options: OverrideCommandOptions & { | ||
60 | userId: number | ||
61 | currentPassword?: string | ||
62 | }) { | ||
63 | const { userId, currentPassword } = options | ||
64 | const path = '/api/v1/users/' + userId + '/two-factor/disable' | ||
65 | |||
66 | return this.postBodyRequest({ | ||
67 | ...options, | ||
68 | |||
69 | path, | ||
70 | fields: { currentPassword }, | ||
71 | implicitToken: true, | ||
72 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
73 | }) | ||
74 | } | ||
75 | |||
76 | async requestAndConfirm (options: OverrideCommandOptions & { | ||
77 | userId: number | ||
78 | currentPassword?: string | ||
79 | }) { | ||
80 | const { userId, currentPassword } = options | ||
81 | |||
82 | const { otpRequest } = await this.request({ userId, currentPassword }) | ||
83 | |||
84 | await this.confirmRequest({ | ||
85 | userId, | ||
86 | requestToken: otpRequest.requestToken, | ||
87 | otpToken: TwoFactorCommand.buildOTP({ secret: otpRequest.secret }).generate() | ||
88 | }) | ||
89 | |||
90 | return otpRequest | ||
91 | } | ||
92 | } | ||
diff --git a/shared/server-commands/users/users-command.ts b/shared/server-commands/users/users-command.ts index d8303848d..811b9685b 100644 --- a/shared/server-commands/users/users-command.ts +++ b/shared/server-commands/users/users-command.ts | |||
@@ -202,7 +202,8 @@ export class UsersCommand extends AbstractCommand { | |||
202 | token, | 202 | token, |
203 | userId: user.id, | 203 | userId: user.id, |
204 | userChannelId: me.videoChannels[0].id, | 204 | userChannelId: me.videoChannels[0].id, |
205 | userChannelName: me.videoChannels[0].name | 205 | userChannelName: me.videoChannels[0].name, |
206 | password | ||
206 | } | 207 | } |
207 | } | 208 | } |
208 | 209 | ||
@@ -217,12 +218,13 @@ export class UsersCommand extends AbstractCommand { | |||
217 | username: string | 218 | username: string |
218 | password?: string | 219 | password?: string |
219 | displayName?: string | 220 | displayName?: string |
221 | email?: string | ||
220 | channel?: { | 222 | channel?: { |
221 | name: string | 223 | name: string |
222 | displayName: string | 224 | displayName: string |
223 | } | 225 | } |
224 | }) { | 226 | }) { |
225 | const { username, password = 'password', displayName, channel } = options | 227 | const { username, password = 'password', displayName, channel, email = username + '@example.com' } = options |
226 | const path = '/api/v1/users/register' | 228 | const path = '/api/v1/users/register' |
227 | 229 | ||
228 | return this.postBodyRequest({ | 230 | return this.postBodyRequest({ |
@@ -232,7 +234,7 @@ export class UsersCommand extends AbstractCommand { | |||
232 | fields: { | 234 | fields: { |
233 | username, | 235 | username, |
234 | password, | 236 | password, |
235 | email: username + '@example.com', | 237 | email, |
236 | displayName, | 238 | displayName, |
237 | channel | 239 | channel |
238 | }, | 240 | }, |
diff --git a/shared/server-commands/videos/live-command.ts b/shared/server-commands/videos/live-command.ts index d804fd883..84d127db2 100644 --- a/shared/server-commands/videos/live-command.ts +++ b/shared/server-commands/videos/live-command.ts | |||
@@ -15,6 +15,7 @@ import { | |||
15 | VideoState | 15 | VideoState |
16 | } from '@shared/models' | 16 | } from '@shared/models' |
17 | import { unwrapBody } from '../requests' | 17 | import { unwrapBody } from '../requests' |
18 | import { ObjectStorageCommand } from '../server' | ||
18 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | 19 | import { AbstractCommand, OverrideCommandOptions } from '../shared' |
19 | import { sendRTMPStream, testFfmpegStreamError } from './live' | 20 | import { sendRTMPStream, testFfmpegStreamError } from './live' |
20 | 21 | ||
@@ -34,6 +35,8 @@ export class LiveCommand extends AbstractCommand { | |||
34 | }) | 35 | }) |
35 | } | 36 | } |
36 | 37 | ||
38 | // --------------------------------------------------------------------------- | ||
39 | |||
37 | listSessions (options: OverrideCommandOptions & { | 40 | listSessions (options: OverrideCommandOptions & { |
38 | videoId: number | string | 41 | videoId: number | string |
39 | }) { | 42 | }) { |
@@ -70,6 +73,8 @@ export class LiveCommand extends AbstractCommand { | |||
70 | }) | 73 | }) |
71 | } | 74 | } |
72 | 75 | ||
76 | // --------------------------------------------------------------------------- | ||
77 | |||
73 | update (options: OverrideCommandOptions & { | 78 | update (options: OverrideCommandOptions & { |
74 | videoId: number | string | 79 | videoId: number | string |
75 | fields: LiveVideoUpdate | 80 | fields: LiveVideoUpdate |
@@ -110,6 +115,8 @@ export class LiveCommand extends AbstractCommand { | |||
110 | return body.video | 115 | return body.video |
111 | } | 116 | } |
112 | 117 | ||
118 | // --------------------------------------------------------------------------- | ||
119 | |||
113 | async sendRTMPStreamInVideo (options: OverrideCommandOptions & { | 120 | async sendRTMPStreamInVideo (options: OverrideCommandOptions & { |
114 | videoId: number | string | 121 | videoId: number | string |
115 | fixtureName?: string | 122 | fixtureName?: string |
@@ -130,6 +137,8 @@ export class LiveCommand extends AbstractCommand { | |||
130 | return testFfmpegStreamError(command, options.shouldHaveError) | 137 | return testFfmpegStreamError(command, options.shouldHaveError) |
131 | } | 138 | } |
132 | 139 | ||
140 | // --------------------------------------------------------------------------- | ||
141 | |||
133 | waitUntilPublished (options: OverrideCommandOptions & { | 142 | waitUntilPublished (options: OverrideCommandOptions & { |
134 | videoId: number | string | 143 | videoId: number | string |
135 | }) { | 144 | }) { |
@@ -163,15 +172,45 @@ export class LiveCommand extends AbstractCommand { | |||
163 | return this.server.servers.waitUntilLog(`${videoUUID}/${segmentName}`, totalSessions * 2, false) | 172 | return this.server.servers.waitUntilLog(`${videoUUID}/${segmentName}`, totalSessions * 2, false) |
164 | } | 173 | } |
165 | 174 | ||
166 | getSegment (options: OverrideCommandOptions & { | 175 | waitUntilSegmentUpload (options: OverrideCommandOptions & { |
176 | playlistNumber: number | ||
177 | segment: number | ||
178 | totalSessions?: number | ||
179 | }) { | ||
180 | const { playlistNumber, segment, totalSessions = 1 } = options | ||
181 | const segmentName = `${playlistNumber}-00000${segment}.ts` | ||
182 | |||
183 | return this.server.servers.waitUntilLog(`${segmentName} in bucket `, totalSessions * 2, false) | ||
184 | } | ||
185 | |||
186 | async waitUntilReplacedByReplay (options: OverrideCommandOptions & { | ||
187 | videoId: number | string | ||
188 | }) { | ||
189 | let video: VideoDetails | ||
190 | |||
191 | do { | ||
192 | video = await this.server.videos.getWithToken({ token: options.token, id: options.videoId }) | ||
193 | |||
194 | await wait(500) | ||
195 | } while (video.isLive === true || video.state.id !== VideoState.PUBLISHED) | ||
196 | } | ||
197 | |||
198 | // --------------------------------------------------------------------------- | ||
199 | |||
200 | getSegmentFile (options: OverrideCommandOptions & { | ||
167 | videoUUID: string | 201 | videoUUID: string |
168 | playlistNumber: number | 202 | playlistNumber: number |
169 | segment: number | 203 | segment: number |
204 | objectStorage?: boolean // default false | ||
170 | }) { | 205 | }) { |
171 | const { playlistNumber, segment, videoUUID } = options | 206 | const { playlistNumber, segment, videoUUID, objectStorage = false } = options |
172 | 207 | ||
173 | const segmentName = `${playlistNumber}-00000${segment}.ts` | 208 | const segmentName = `${playlistNumber}-00000${segment}.ts` |
174 | const url = `${this.server.url}/static/streaming-playlists/hls/${videoUUID}/${segmentName}` | 209 | const baseUrl = objectStorage |
210 | ? ObjectStorageCommand.getPlaylistBaseUrl() | ||
211 | : `${this.server.url}/static/streaming-playlists/hls` | ||
212 | |||
213 | const url = `${baseUrl}/${videoUUID}/${segmentName}` | ||
175 | 214 | ||
176 | return this.getRawRequest({ | 215 | return this.getRawRequest({ |
177 | ...options, | 216 | ...options, |
@@ -182,18 +221,30 @@ export class LiveCommand extends AbstractCommand { | |||
182 | }) | 221 | }) |
183 | } | 222 | } |
184 | 223 | ||
185 | async waitUntilReplacedByReplay (options: OverrideCommandOptions & { | 224 | getPlaylistFile (options: OverrideCommandOptions & { |
186 | videoId: number | string | 225 | videoUUID: string |
226 | playlistName: string | ||
227 | objectStorage?: boolean // default false | ||
187 | }) { | 228 | }) { |
188 | let video: VideoDetails | 229 | const { playlistName, videoUUID, objectStorage = false } = options |
189 | 230 | ||
190 | do { | 231 | const baseUrl = objectStorage |
191 | video = await this.server.videos.getWithToken({ token: options.token, id: options.videoId }) | 232 | ? ObjectStorageCommand.getPlaylistBaseUrl() |
233 | : `${this.server.url}/static/streaming-playlists/hls` | ||
192 | 234 | ||
193 | await wait(500) | 235 | const url = `${baseUrl}/${videoUUID}/${playlistName}` |
194 | } while (video.isLive === true || video.state.id !== VideoState.PUBLISHED) | 236 | |
237 | return this.getRawRequest({ | ||
238 | ...options, | ||
239 | |||
240 | url, | ||
241 | implicitToken: false, | ||
242 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
243 | }) | ||
195 | } | 244 | } |
196 | 245 | ||
246 | // --------------------------------------------------------------------------- | ||
247 | |||
197 | async countPlaylists (options: OverrideCommandOptions & { | 248 | async countPlaylists (options: OverrideCommandOptions & { |
198 | videoUUID: string | 249 | videoUUID: string |
199 | }) { | 250 | }) { |
diff --git a/shared/server-commands/videos/streaming-playlists-command.ts b/shared/server-commands/videos/streaming-playlists-command.ts index 5d40d35cb..25e446e72 100644 --- a/shared/server-commands/videos/streaming-playlists-command.ts +++ b/shared/server-commands/videos/streaming-playlists-command.ts | |||
@@ -1,22 +1,42 @@ | |||
1 | import { wait } from '@shared/core-utils' | ||
1 | import { HttpStatusCode } from '@shared/models' | 2 | import { HttpStatusCode } from '@shared/models' |
2 | import { unwrapBody, unwrapTextOrDecode, unwrapBodyOrDecodeToJSON } from '../requests' | 3 | import { unwrapBody, unwrapBodyOrDecodeToJSON, unwrapTextOrDecode } from '../requests' |
3 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | 4 | import { AbstractCommand, OverrideCommandOptions } from '../shared' |
4 | 5 | ||
5 | export class StreamingPlaylistsCommand extends AbstractCommand { | 6 | export class StreamingPlaylistsCommand extends AbstractCommand { |
6 | 7 | ||
7 | get (options: OverrideCommandOptions & { | 8 | async get (options: OverrideCommandOptions & { |
8 | url: string | 9 | url: string |
10 | withRetry?: boolean // default false | ||
11 | currentRetry?: number | ||
9 | }) { | 12 | }) { |
10 | return unwrapTextOrDecode(this.getRawRequest({ | 13 | const { withRetry, currentRetry = 1 } = options |
11 | ...options, | ||
12 | 14 | ||
13 | url: options.url, | 15 | try { |
14 | implicitToken: false, | 16 | const result = await unwrapTextOrDecode(this.getRawRequest({ |
15 | defaultExpectedStatus: HttpStatusCode.OK_200 | 17 | ...options, |
16 | })) | 18 | |
19 | url: options.url, | ||
20 | implicitToken: false, | ||
21 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
22 | })) | ||
23 | |||
24 | return result | ||
25 | } catch (err) { | ||
26 | if (!withRetry || currentRetry > 5) throw err | ||
27 | |||
28 | await wait(100) | ||
29 | |||
30 | return this.get({ | ||
31 | ...options, | ||
32 | |||
33 | withRetry, | ||
34 | currentRetry: currentRetry + 1 | ||
35 | }) | ||
36 | } | ||
17 | } | 37 | } |
18 | 38 | ||
19 | getSegment (options: OverrideCommandOptions & { | 39 | getFragmentedSegment (options: OverrideCommandOptions & { |
20 | url: string | 40 | url: string |
21 | range?: string | 41 | range?: string |
22 | }) { | 42 | }) { |