import { firstValueFrom } from 'rxjs'
import { tap } from 'rxjs/operators'
import { Component, ElementRef, Inject, LOCALE_ID, ViewChild } from '@angular/core'
-import { AuthService, HooksService, Notifier } from '@app/core'
+import { HooksService } from '@app/core'
import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'
+import { logger } from '@root-helpers/logger'
+import { videoRequiresAuth } from '@root-helpers/video'
import { VideoCaption, VideoFile, VideoPrivacy } from '@shared/models'
-import { BytesPipe, NumberFormatterPipe, VideoDetails, VideoService } from '../shared-main'
+import { BytesPipe, NumberFormatterPipe, VideoDetails, VideoFileTokenService, VideoService } from '../shared-main'
type DownloadType = 'video' | 'subtitles'
-type FileMetadata = { [key: string]: { label: string, value: string }}
+type FileMetadata = { [key: string]: { label: string, value: string } }
@Component({
selector: 'my-video-download',
type: DownloadType = 'video'
+ videoFileToken: string
+
private activeModal: NgbModalRef
private bytesPipe: BytesPipe
constructor (
@Inject(LOCALE_ID) private localeId: string,
- private notifier: Notifier,
private modalService: NgbModal,
private videoService: VideoService,
- private auth: AuthService,
+ private videoFileTokenService: VideoFileTokenService,
private hooks: HooksService
) {
this.bytesPipe = new BytesPipe()
}
show (video: VideoDetails, videoCaptions?: VideoCaption[]) {
+ this.videoFileToken = undefined
+
this.video = video
this.videoCaptions = videoCaptions
this.subtitleLanguageId = this.videoCaptions[0].language.id
}
+ if (videoRequiresAuth(this.video)) {
+ this.videoFileTokenService.getVideoFileToken(this.video.uuid)
+ .subscribe(({ token }) => this.videoFileToken = token)
+ }
+
this.activeModal.shown.subscribe(() => {
this.hooks.runAction('action:modal.video-download.shown', 'common')
})
.find(f => f.resolution.id === this.resolutionId)
if (!file) {
- console.error('Could not find file with resolution %d.', this.resolutionId)
+ logger.error(`Could not find file with resolution ${this.resolutionId}`)
return undefined
}
if (!file) return ''
const suffix = this.isConfidentialVideo()
- ? '?access_token=' + this.auth.getAccessToken()
+ ? '?videoFileToken=' + this.videoFileToken
: ''
switch (this.downloadType) {
.find(c => c.language.id === this.subtitleLanguageId)
if (!caption) {
- console.error('Cannot find caption %s.', this.subtitleLanguageId)
+ logger.error(`Cannot find caption ${this.subtitleLanguageId}`)
return undefined
}