aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/shared-main
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/shared/shared-main')
-rw-r--r--client/src/app/shared/shared-main/video/video.model.ts7
-rw-r--r--client/src/app/shared/shared-main/video/video.service.ts52
2 files changed, 50 insertions, 9 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 a5bf1db8b..392dcadd0 100644
--- a/client/src/app/shared/shared-main/video/video.model.ts
+++ b/client/src/app/shared/shared-main/video/video.model.ts
@@ -257,9 +257,12 @@ export class Video implements VideoServerModel {
257 } 257 }
258 258
259 canRunTranscoding (user: AuthUser) { 259 canRunTranscoding (user: AuthUser) {
260 return this.canRunForcedTranscoding(user) && this.state.id !== VideoState.TO_TRANSCODE
261 }
262
263 canRunForcedTranscoding (user: AuthUser) {
260 return this.isLocal && 264 return this.isLocal &&
261 user && user.hasRight(UserRight.RUN_VIDEO_TRANSCODING) && 265 user && user.hasRight(UserRight.RUN_VIDEO_TRANSCODING)
262 this.state.id !== VideoState.TO_TRANSCODE
263 } 266 }
264 267
265 hasHLS () { 268 hasHLS () {
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 20145b9c5..cd0a300e2 100644
--- a/client/src/app/shared/shared-main/video/video.service.ts
+++ b/client/src/app/shared/shared-main/video/video.service.ts
@@ -1,9 +1,9 @@
1import { SortMeta } from 'primeng/api' 1import { SortMeta } from 'primeng/api'
2import { from, Observable, of } from 'rxjs' 2import { from, Observable, of, throwError } from 'rxjs'
3import { catchError, concatMap, map, switchMap, toArray } from 'rxjs/operators' 3import { catchError, concatMap, map, switchMap, toArray } from 'rxjs/operators'
4import { HttpClient, HttpParams, HttpRequest } from '@angular/common/http' 4import { HttpClient, HttpParams, HttpRequest } from '@angular/common/http'
5import { Injectable } from '@angular/core' 5import { Injectable } from '@angular/core'
6import { AuthService, ComponentPaginationLight, RestExtractor, RestService, ServerService, UserService } from '@app/core' 6import { AuthService, ComponentPaginationLight, ConfirmService, RestExtractor, RestService, ServerService, UserService } from '@app/core'
7import { objectToFormData } from '@app/helpers' 7import { objectToFormData } from '@app/helpers'
8import { arrayify } from '@shared/core-utils' 8import { arrayify } from '@shared/core-utils'
9import { 9import {
@@ -11,6 +11,7 @@ import {
11 FeedFormat, 11 FeedFormat,
12 NSFWPolicyType, 12 NSFWPolicyType,
13 ResultList, 13 ResultList,
14 ServerErrorCode,
14 Storyboard, 15 Storyboard,
15 UserVideoRate, 16 UserVideoRate,
16 UserVideoRateType, 17 UserVideoRateType,
@@ -33,8 +34,8 @@ import { AccountService } from '../account/account.service'
33import { VideoChannel, VideoChannelService } from '../video-channel' 34import { VideoChannel, VideoChannelService } from '../video-channel'
34import { VideoDetails } from './video-details.model' 35import { VideoDetails } from './video-details.model'
35import { VideoEdit } from './video-edit.model' 36import { VideoEdit } from './video-edit.model'
36import { Video } from './video.model'
37import { VideoPasswordService } from './video-password.service' 37import { VideoPasswordService } from './video-password.service'
38import { Video } from './video.model'
38 39
39export type CommonVideoParams = { 40export type CommonVideoParams = {
40 videoPagination?: ComponentPaginationLight 41 videoPagination?: ComponentPaginationLight
@@ -64,7 +65,8 @@ export class VideoService {
64 private authHttp: HttpClient, 65 private authHttp: HttpClient,
65 private restExtractor: RestExtractor, 66 private restExtractor: RestExtractor,
66 private restService: RestService, 67 private restService: RestService,
67 private serverService: ServerService 68 private serverService: ServerService,
69 private confirmService: ConfirmService
68 ) {} 70 ) {}
69 71
70 getVideoViewUrl (uuid: string) { 72 getVideoViewUrl (uuid: string) {
@@ -325,17 +327,53 @@ export class VideoService {
325 .pipe(catchError(err => this.restExtractor.handleError(err))) 327 .pipe(catchError(err => this.restExtractor.handleError(err)))
326 } 328 }
327 329
328 runTranscoding (videoIds: (number | string)[], type: 'hls' | 'web-video') { 330 runTranscoding (options: {
329 const body: VideoTranscodingCreate = { transcodingType: type } 331 videoIds: (number | string)[]
332 type: 'hls' | 'web-video'
333 askForForceTranscodingIfNeeded: boolean
334 forceTranscoding?: boolean
335 }): Observable<any> {
336 const { videoIds, type, askForForceTranscodingIfNeeded, forceTranscoding } = options
337
338 if (askForForceTranscodingIfNeeded && videoIds.length !== 1) {
339 throw new Error('Cannot ask to force transcoding on multiple videos')
340 }
341
342 const body: VideoTranscodingCreate = { transcodingType: type, forceTranscoding }
330 343
331 return from(videoIds) 344 return from(videoIds)
332 .pipe( 345 .pipe(
333 concatMap(id => this.authHttp.post(VideoService.BASE_VIDEO_URL + '/' + id + '/transcoding', body)), 346 concatMap(id => {
347 return this.authHttp.post(VideoService.BASE_VIDEO_URL + '/' + id + '/transcoding', body)
348 .pipe(
349 catchError(err => {
350 if (askForForceTranscodingIfNeeded && err.error?.code === ServerErrorCode.VIDEO_ALREADY_BEING_TRANSCODED) {
351 const message = $localize`PeerTube considers this video is already being transcoded.` +
352 // eslint-disable-next-line max-len
353 $localize` If you think PeerTube is wrong (video in broken state after a crash etc.), you can force transcoding on this video.` +
354 ` Do you still want to run transcoding?`
355
356 return from(this.confirmService.confirm(message, $localize`Force transcoding`))
357 .pipe(
358 switchMap(res => {
359 if (res === false) return throwError(() => err)
360
361 return this.runTranscoding({ videoIds, type, askForForceTranscodingIfNeeded: false, forceTranscoding: true })
362 })
363 )
364 }
365
366 return throwError(() => err)
367 })
368 )
369 }),
334 toArray(), 370 toArray(),
335 catchError(err => this.restExtractor.handleError(err)) 371 catchError(err => this.restExtractor.handleError(err))
336 ) 372 )
337 } 373 }
338 374
375 // ---------------------------------------------------------------------------
376
339 loadCompleteDescription (descriptionPath: string) { 377 loadCompleteDescription (descriptionPath: string) {
340 return this.authHttp 378 return this.authHttp
341 .get<{ description: string }>(environment.apiUrl + descriptionPath) 379 .get<{ description: string }>(environment.apiUrl + descriptionPath)