Fix downloading private videos in admin

This commit is contained in:
Chocobozzz 2024-06-21 11:05:04 +02:00
parent 4302802840
commit 79d6e93b03
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
2 changed files with 35 additions and 7 deletions

View File

@ -8,7 +8,7 @@
[rowsPerPageOptions]="rowsPerPageOptions" [sortField]="sort.field" [sortOrder]="sort.order" dataKey="id" [resizableColumns]="true"
[(selection)]="selectedRows" [lazy]="true" (onLazyLoad)="loadLazy($event)" [lazyLoadOnInit]="false" [selectionPageOnly]="true"
[showCurrentPageReport]="true" [currentPageReportTemplate]="getPaginationTemplate()"
[expandedRowKeys]="expandedRows" [ngClass]="{ loading: loading }"
[expandedRowKeys]="expandedRows" [ngClass]="{ loading: loading }" (onRowExpand)="onVideoPanelOpened($event)"
>
<ng-template pTemplate="caption">
<div class="caption">
@ -49,7 +49,7 @@
<ng-template pTemplate="body" let-expanded="expanded" let-video>
<tr [pSelectableRow]="video">
<tr [pSelectableRow]="video" (onRowExpand)="onVideoPanelOpened(video)">
<td class="checkbox-cell">
<p-tableCheckbox [value]="video" ariaLabel="Select this row" i18n-ariaLabel></p-tableCheckbox>
</td>
@ -126,7 +126,7 @@
<ul>
<li>
{{ video.videoSource.inputFilename }}: {{ video.videoSource.size | bytes: 1 }}
<a title="Download this file" i18n-title [href]="getDownloadUrl(video, video.videoSource.fileDownloadUrl)">{{ video.videoSource.inputFilename }}</a>: {{ video.videoSource.size | bytes: 1 }}
<button
*ngIf="canRemoveOneFile(video)" class="border-0 p-0"
@ -144,7 +144,7 @@
<ul>
<li *ngFor="let file of video.files">
<a target="_blank" rel="noopener noreferrer" [href]="file.fileUrl">{{ file.resolution.label }}</a>: {{ file.size | bytes: 1 }}
<a title="Download this file" i18n-title [href]="getDownloadUrl(video, file.fileDownloadUrl)">{{ file.resolution.label }}</a>: {{ file.size | bytes: 1 }}
<button
*ngIf="canRemoveOneFile(video)" class="border-0 p-0"
@ -162,7 +162,7 @@
<ul>
<li *ngFor="let file of video.streamingPlaylists[0].files">
<a target="_blank" rel="noopener noreferrer" [href]="file.fileUrl">{{ file.resolution.label }}</a>: {{ file.size | bytes: 1 }}
<a title="Download this file" i18n-title [href]="getDownloadUrl(video, file.fileDownloadUrl)">{{ file.resolution.label }}</a>: {{ file.size | bytes: 1 }}
<button
*ngIf="canRemoveOneFile(video)" class="border-0 p-0"

View File

@ -3,6 +3,8 @@ import { Component, OnInit, ViewChild } from '@angular/core'
import { ActivatedRoute, Router, RouterLink } from '@angular/router'
import { AuthService, ConfirmService, Notifier, RestPagination, RestTable } from '@app/core'
import { formatICU, getAbsoluteAPIUrl } from '@app/helpers'
import { VideoDetails } from '@app/shared/shared-main/video/video-details.model'
import { VideoFileTokenService } from '@app/shared/shared-main/video/video-file-token.service'
import { Video } from '@app/shared/shared-main/video/video.model'
import { VideoService } from '@app/shared/shared-main/video/video.service'
import { VideoBlockComponent } from '@app/shared/shared-moderation/video-block.component'
@ -10,8 +12,9 @@ import { VideoBlockService } from '@app/shared/shared-moderation/video-block.ser
import { NgbTooltip } from '@ng-bootstrap/ng-bootstrap'
import { getAllFiles } from '@peertube/peertube-core-utils'
import { UserRight, VideoFile, VideoPrivacy, VideoState, VideoStreamingPlaylistType } from '@peertube/peertube-models'
import { videoRequiresFileToken } from '@root-helpers/video'
import { SharedModule, SortMeta } from 'primeng/api'
import { TableModule } from 'primeng/table'
import { TableModule, TableRowExpandEvent } from 'primeng/table'
import { finalize } from 'rxjs/operators'
import { AdvancedInputFilter, AdvancedInputFilterComponent } from '../../../shared/shared-forms/advanced-input-filter.component'
import { GlobalIconComponent } from '../../../shared/shared-icons/global-icon.component'
@ -86,6 +89,8 @@ export class VideoListComponent extends RestTable <Video> implements OnInit {
loading = true
private videoFileTokens: { [ videoId: number ]: string } = {}
constructor (
protected route: ActivatedRoute,
protected router: Router,
@ -94,7 +99,8 @@ export class VideoListComponent extends RestTable <Video> implements OnInit {
private notifier: Notifier,
private videoService: VideoService,
private videoAdminService: VideoAdminService,
private videoBlockService: VideoBlockService
private videoBlockService: VideoBlockService,
private videoFileTokenService: VideoFileTokenService
) {
super()
}
@ -265,6 +271,28 @@ export class VideoListComponent extends RestTable <Video> implements OnInit {
return str
}
// ---------------------------------------------------------------------------
onVideoPanelOpened (event: TableRowExpandEvent) {
const video = event.data as VideoDetails
if (!video.videoSource?.filename && !videoRequiresFileToken(video)) return
this.videoFileTokenService.getVideoFileToken({ videoUUID: video.uuid })
.subscribe(({ token }) => {
this.videoFileTokens[video.id] = token
})
}
getDownloadUrl (video: VideoDetails, downloadUrl: string) {
const token = this.videoFileTokens[video.id]
if (!token) return downloadUrl
return downloadUrl + `?videoFileToken=${token}`
}
// ---------------------------------------------------------------------------
protected reloadDataInternal () {
this.loading = true