diff options
author | Chocobozzz <me@florianbigard.com> | 2021-11-18 14:35:08 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-11-18 15:20:57 +0100 |
commit | ad5db1044c8599eaaaa2a578b350777ae996b068 (patch) | |
tree | 3e003cccf021152405d49b21c6c91b703c8ae96c /client/src/app/shared | |
parent | b46cf4b920984492df598c1b61179acfc7f6f22e (diff) | |
download | PeerTube-ad5db1044c8599eaaaa2a578b350777ae996b068.tar.gz PeerTube-ad5db1044c8599eaaaa2a578b350777ae996b068.tar.zst PeerTube-ad5db1044c8599eaaaa2a578b350777ae996b068.zip |
Add ability to run transcoding jobs
Diffstat (limited to 'client/src/app/shared')
3 files changed, 59 insertions, 3 deletions
diff --git a/client/src/app/shared/shared-main/video/video.model.ts b/client/src/app/shared/shared-main/video/video.model.ts index 4203ff1c0..eefa90489 100644 --- a/client/src/app/shared/shared-main/video/video.model.ts +++ b/client/src/app/shared/shared-main/video/video.model.ts | |||
@@ -220,6 +220,18 @@ export class Video implements VideoServerModel { | |||
220 | return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.UPDATE_ANY_VIDEO)) | 220 | return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.UPDATE_ANY_VIDEO)) |
221 | } | 221 | } |
222 | 222 | ||
223 | canRemoveFiles (user: AuthUser) { | ||
224 | return user.hasRight(UserRight.MANAGE_VIDEO_FILES) && | ||
225 | this.state.id !== VideoState.TO_TRANSCODE && | ||
226 | this.hasHLS() && | ||
227 | this.hasWebTorrent() | ||
228 | } | ||
229 | |||
230 | canRunTranscoding (user: AuthUser) { | ||
231 | return user.hasRight(UserRight.RUN_VIDEO_TRANSCODING) && | ||
232 | this.state.id !== VideoState.TO_TRANSCODE | ||
233 | } | ||
234 | |||
223 | hasHLS () { | 235 | hasHLS () { |
224 | return this.streamingPlaylists?.some(p => p.type === VideoStreamingPlaylistType.HLS) | 236 | return this.streamingPlaylists?.some(p => p.type === VideoStreamingPlaylistType.HLS) |
225 | } | 237 | } |
diff --git a/client/src/app/shared/shared-main/video/video.service.ts b/client/src/app/shared/shared-main/video/video.service.ts index d135a27dc..9bfa397f8 100644 --- a/client/src/app/shared/shared-main/video/video.service.ts +++ b/client/src/app/shared/shared-main/video/video.service.ts | |||
@@ -21,6 +21,7 @@ import { | |||
21 | VideoInclude, | 21 | VideoInclude, |
22 | VideoPrivacy, | 22 | VideoPrivacy, |
23 | VideoSortField, | 23 | VideoSortField, |
24 | VideoTranscodingCreate, | ||
24 | VideoUpdate | 25 | VideoUpdate |
25 | } from '@shared/models' | 26 | } from '@shared/models' |
26 | import { environment } from '../../../../environments/environment' | 27 | import { environment } from '../../../../environments/environment' |
@@ -308,6 +309,17 @@ export class VideoService { | |||
308 | ) | 309 | ) |
309 | } | 310 | } |
310 | 311 | ||
312 | runTranscoding (videoIds: (number | string)[], type: 'hls' | 'webtorrent') { | ||
313 | const body: VideoTranscodingCreate = { transcodingType: type } | ||
314 | |||
315 | return from(videoIds) | ||
316 | .pipe( | ||
317 | concatMap(id => this.authHttp.post(VideoService.BASE_VIDEO_URL + '/' + id + '/transcoding', body)), | ||
318 | toArray(), | ||
319 | catchError(err => this.restExtractor.handleError(err)) | ||
320 | ) | ||
321 | } | ||
322 | |||
311 | loadCompleteDescription (descriptionPath: string) { | 323 | loadCompleteDescription (descriptionPath: string) { |
312 | return this.authHttp | 324 | return this.authHttp |
313 | .get<{ description: string }>(environment.apiUrl + descriptionPath) | 325 | .get<{ description: string }>(environment.apiUrl + descriptionPath) |
diff --git a/client/src/app/shared/shared-video-miniature/video-actions-dropdown.component.ts b/client/src/app/shared/shared-video-miniature/video-actions-dropdown.component.ts index 82c084791..2ab9f4739 100644 --- a/client/src/app/shared/shared-video-miniature/video-actions-dropdown.component.ts +++ b/client/src/app/shared/shared-video-miniature/video-actions-dropdown.component.ts | |||
@@ -2,7 +2,7 @@ import { Component, EventEmitter, Input, OnChanges, Output, ViewChild } from '@a | |||
2 | import { AuthService, ConfirmService, Notifier, ScreenService } from '@app/core' | 2 | import { AuthService, ConfirmService, Notifier, ScreenService } from '@app/core' |
3 | import { BlocklistService, VideoBlockComponent, VideoBlockService, VideoReportComponent } from '@app/shared/shared-moderation' | 3 | import { BlocklistService, VideoBlockComponent, VideoBlockService, VideoReportComponent } from '@app/shared/shared-moderation' |
4 | import { NgbDropdown } from '@ng-bootstrap/ng-bootstrap' | 4 | import { NgbDropdown } from '@ng-bootstrap/ng-bootstrap' |
5 | import { UserRight, VideoCaption } from '@shared/models' | 5 | import { UserRight, VideoCaption, VideoState } from '@shared/models' |
6 | import { | 6 | import { |
7 | Actor, | 7 | Actor, |
8 | DropdownAction, | 8 | DropdownAction, |
@@ -28,6 +28,7 @@ export type VideoActionsDisplayType = { | |||
28 | mute?: boolean | 28 | mute?: boolean |
29 | liveInfo?: boolean | 29 | liveInfo?: boolean |
30 | removeFiles?: boolean | 30 | removeFiles?: boolean |
31 | transcoding?: boolean | ||
31 | } | 32 | } |
32 | 33 | ||
33 | @Component({ | 34 | @Component({ |
@@ -56,7 +57,9 @@ export class VideoActionsDropdownComponent implements OnChanges { | |||
56 | report: true, | 57 | report: true, |
57 | duplicate: true, | 58 | duplicate: true, |
58 | mute: true, | 59 | mute: true, |
59 | liveInfo: false | 60 | liveInfo: false, |
61 | removeFiles: false, | ||
62 | transcoding: false | ||
60 | } | 63 | } |
61 | @Input() placement = 'left' | 64 | @Input() placement = 'left' |
62 | 65 | ||
@@ -71,6 +74,7 @@ export class VideoActionsDropdownComponent implements OnChanges { | |||
71 | @Output() videoUnblocked = new EventEmitter() | 74 | @Output() videoUnblocked = new EventEmitter() |
72 | @Output() videoBlocked = new EventEmitter() | 75 | @Output() videoBlocked = new EventEmitter() |
73 | @Output() videoAccountMuted = new EventEmitter() | 76 | @Output() videoAccountMuted = new EventEmitter() |
77 | @Output() transcodingCreated = new EventEmitter() | ||
74 | @Output() modalOpened = new EventEmitter() | 78 | @Output() modalOpened = new EventEmitter() |
75 | 79 | ||
76 | videoActions: DropdownAction<{ video: Video }>[][] = [] | 80 | videoActions: DropdownAction<{ video: Video }>[][] = [] |
@@ -177,7 +181,11 @@ export class VideoActionsDropdownComponent implements OnChanges { | |||
177 | } | 181 | } |
178 | 182 | ||
179 | canRemoveVideoFiles () { | 183 | canRemoveVideoFiles () { |
180 | return this.user.hasRight(UserRight.MANAGE_VIDEO_FILES) && this.video.hasHLS() && this.video.hasWebTorrent() | 184 | return this.video.canRemoveFiles(this.user) |
185 | } | ||
186 | |||
187 | canRunTranscoding () { | ||
188 | return this.video.canRunTranscoding(this.user) | ||
181 | } | 189 | } |
182 | 190 | ||
183 | /* Action handlers */ | 191 | /* Action handlers */ |
@@ -268,6 +276,18 @@ export class VideoActionsDropdownComponent implements OnChanges { | |||
268 | }) | 276 | }) |
269 | } | 277 | } |
270 | 278 | ||
279 | runTranscoding (video: Video, type: 'hls' | 'webtorrent') { | ||
280 | this.videoService.runTranscoding([ video.id ], type) | ||
281 | .subscribe({ | ||
282 | next: () => { | ||
283 | this.notifier.success($localize`Transcoding jobs created for ${video.name}.`) | ||
284 | this.transcodingCreated.emit() | ||
285 | }, | ||
286 | |||
287 | error: err => this.notifier.error(err.message) | ||
288 | }) | ||
289 | } | ||
290 | |||
271 | onVideoBlocked () { | 291 | onVideoBlocked () { |
272 | this.videoBlocked.emit() | 292 | this.videoBlocked.emit() |
273 | } | 293 | } |
@@ -342,6 +362,18 @@ export class VideoActionsDropdownComponent implements OnChanges { | |||
342 | ], | 362 | ], |
343 | [ | 363 | [ |
344 | { | 364 | { |
365 | label: $localize`Run HLS transcoding`, | ||
366 | handler: ({ video }) => this.runTranscoding(video, 'hls'), | ||
367 | isDisplayed: () => this.displayOptions.transcoding && this.canRunTranscoding(), | ||
368 | iconName: 'cog' | ||
369 | }, | ||
370 | { | ||
371 | label: $localize`Run WebTorrent transcoding`, | ||
372 | handler: ({ video }) => this.runTranscoding(video, 'webtorrent'), | ||
373 | isDisplayed: () => this.displayOptions.transcoding && this.canRunTranscoding(), | ||
374 | iconName: 'cog' | ||
375 | }, | ||
376 | { | ||
345 | label: $localize`Delete HLS files`, | 377 | label: $localize`Delete HLS files`, |
346 | handler: ({ video }) => this.removeVideoFiles(video, 'hls'), | 378 | handler: ({ video }) => this.removeVideoFiles(video, 'hls'), |
347 | isDisplayed: () => this.displayOptions.removeFiles && this.canRemoveVideoFiles(), | 379 | isDisplayed: () => this.displayOptions.removeFiles && this.canRemoveVideoFiles(), |