Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Fix downloading a video for admins

Chocobozzz34635015bf80
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 ef6d9dc6f4..c49da49118 100644
--- a/client/src/app/shared/shared-main/video/video.model.ts
+++ b/client/src/app/shared/shared-main/video/video.model.ts
@@ -282,6 +282,23 @@ export class Video implements VideoServerModel {
)
}
+ canBypassDisabledDownload (user: AuthUser) {
+ return user && this.isLocal === true && (
+ user.isOwnerOfChannel(this.channel) ||
+ user.isEditorOfChannel(this.channel) ||
+ user.hasRight(UserRight.SEE_ALL_VIDEOS)
+ )
+ }
+
+ // The source metadata endpoint requires UPDATE_ANY_VIDEO and the source file endpoint SEE_ALL_VIDEOS
+ canGetOriginalFile (user: AuthUser) {
+ return user && this.isLocal === true && (
+ user.isOwnerOfChannel(this.channel) ||
+ user.isEditorOfChannel(this.channel) ||
+ (user.hasRight(UserRight.UPDATE_ANY_VIDEO) && user.hasRight(UserRight.SEE_ALL_VIDEOS))
+ )
+ }
+
canBypassPassword (user: AuthUser) {
return this.privacy.id === VideoPrivacy.PASSWORD_PROTECTED &&
user &&
diff --git a/client/src/app/shared/shared-video-miniature/download/video-download.component.ts b/client/src/app/shared/shared-video-miniature/download/video-download.component.ts
index be309f5fc8..7ee2b80129 100644
--- a/client/src/app/shared/shared-video-miniature/download/video-download.component.ts
+++ b/client/src/app/shared/shared-video-miniature/download/video-download.component.ts
@@ -6,7 +6,7 @@ import { GlobalIconComponent } from '@app/shared/shared-icons/global-icon.compon
import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'
import { VideoCaption, VideoSource } from '@peertube/peertube-models'
import { logger } from '@root-helpers/logger'
-import { videoRequiresFileToken } from '@root-helpers/video'
+import { videoDownloadRequiresFileToken } from '@root-helpers/video'
import { of } from 'rxjs'
import { catchError } from 'rxjs/operators'
import { VideoDetails } from '../../shared-main/video/video-details.model'
@@ -80,7 +80,7 @@ export class VideoDownloadComponent {
this.originalVideoFile = source
}
- if (this.originalVideoFile || videoRequiresFileToken(this.video)) {
+ if (this.originalVideoFile || videoDownloadRequiresFileToken(this.video)) {
this.videoFileTokenService.getVideoFileToken({ videoUUID: this.video.uuid, videoPassword: this.videoPassword() })
.subscribe(({ token }) => {
this.videoFileToken = token
@@ -103,8 +103,7 @@ export class VideoDownloadComponent {
if (!this.video.isLocal || !this.authService.isLoggedIn()) return of(undefined)
const user = this.authService.getUser()
- // User that can update the video can also get the original video file
- if (!this.video.canBeUpdatedBy(user)) return of(undefined)
+ if (!this.video.canGetOriginalFile(user)) return of(undefined)
return this.videoService.getSource(this.video.id)
.pipe(catchError(err => {
diff --git a/client/src/app/shared/shared-video-miniature/download/video-files-download.component.ts b/client/src/app/shared/shared-video-miniature/download/video-files-download.component.ts
index 34aecee890..7e89f88614 100644
--- a/client/src/app/shared/shared-video-miniature/download/video-files-download.component.ts
+++ b/client/src/app/shared/shared-video-miniature/download/video-files-download.component.ts
@@ -6,7 +6,7 @@ import { NgbCollapse, NgbNavModule, NgbTooltip } from '@ng-bootstrap/ng-bootstra
import { objectKeysTyped, pick } from '@peertube/peertube-core-utils'
import { VideoFile, VideoFileMetadata, VideoSource } from '@peertube/peertube-models'
import { logger } from '@root-helpers/logger'
-import { videoRequiresFileToken } from '@root-helpers/video'
+import { videoDownloadRequiresFileToken } from '@root-helpers/video'
import { firstValueFrom } from 'rxjs'
import { tap } from 'rxjs/operators'
import { InputTextComponent } from '../../shared-forms/input-text.component'
@@ -147,7 +147,7 @@ export class VideoFilesDownloadComponent implements OnInit {
// ---------------------------------------------------------------------------
isConfidentialVideo () {
- return this.activeResolutionId === 'original' || videoRequiresFileToken(this.video())
+ return this.activeResolutionId === 'original' || videoDownloadRequiresFileToken(this.video())
}
// ---------------------------------------------------------------------------
diff --git a/client/src/app/shared/shared-video-miniature/download/video-generate-download.component.ts b/client/src/app/shared/shared-video-miniature/download/video-generate-download.component.ts
index e078db312d..5bd12d2bd6 100644
--- a/client/src/app/shared/shared-video-miniature/download/video-generate-download.component.ts
+++ b/client/src/app/shared/shared-video-miniature/download/video-generate-download.component.ts
@@ -5,7 +5,7 @@ import { VideoService } from '@app/shared/shared-main/video/video.service'
import { NgbTooltip } from '@ng-bootstrap/ng-bootstrap'
import { getResolutionAndFPSLabel, maxBy } from '@peertube/peertube-core-utils'
import { VideoFile, VideoResolution, VideoSource } from '@peertube/peertube-models'
-import { videoRequiresFileToken } from '@root-helpers/video'
+import { videoDownloadRequiresFileToken } from '@root-helpers/video'
import { GlobalIconComponent } from '../../shared-icons/global-icon.component'
import { BytesPipe } from '../../shared-main/common/bytes.pipe'
import { VideoDetails } from '../../shared-main/video/video-details.model'
@@ -101,7 +101,7 @@ export class VideoGenerateDownloadComponent implements OnInit {
// ---------------------------------------------------------------------------
isConfidentialVideo () {
- return this.videoFileChosen === 'file-original' || videoRequiresFileToken(this.video())
+ return this.videoFileChosen === 'file-original' || videoDownloadRequiresFileToken(this.video())
}
// ---------------------------------------------------------------------------
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 ab01fb59fa..a52728c8bc 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
@@ -273,7 +273,7 @@ export class VideoActionsDropdownComponent implements OnChanges {
return (
video &&
video.isLive !== true &&
- video.canBeUpdatedBy(this.user)
+ video.canBypassDisabledDownload(this.user)
)
}
diff --git a/client/src/root-helpers/video.ts b/client/src/root-helpers/video.ts
index de4c33c806..73d3d86dfa 100644
--- a/client/src/root-helpers/video.ts
+++ b/client/src/root-helpers/video.ts
@@ -1,4 +1,4 @@
-import { HTMLServerConfig, User, Video, VideoPrivacy, VideoPrivacyType } from '@peertube/peertube-models'
+import { HTMLServerConfig, User, Video, VideoDetails, VideoPrivacy, VideoPrivacyType } from '@peertube/peertube-models'
export function buildVideoOrPlaylistEmbed (options: {
embedUrl: string
@@ -49,6 +49,11 @@ export function videoRequiresUserAuth (video: Video, videoPassword?: string) {
(video.privacy.id === VideoPrivacy.PASSWORD_PROTECTED && !videoPassword)
}
+// Download links can send the authorization header, so users bypassing a disabled download need a file token to identify themselves
+export function videoDownloadRequiresFileToken (video: VideoDetails) {
+ return video.downloadEnabled === false || videoRequiresFileToken(video)
+}
+
export function videoRequiresFileToken (video: Video) {
return new Set<VideoPrivacyType>([ VideoPrivacy.PRIVATE, VideoPrivacy.INTERNAL, VideoPrivacy.PASSWORD_PROTECTED ]).has(video.privacy.id)
}
diff --git a/server/core/controllers/download.ts b/server/core/controllers/download.ts
index 5acce66aeb..24554e8e44 100644
--- a/server/core/controllers/download.ts
+++ b/server/core/controllers/download.ts
@@ -417,7 +417,8 @@ async function commonDownloadAllowed (object: {
}): Promise<AllowedResult> {
const { req, res, video } = object
- const user = getAuthUser(res)
+ // Download links are opened by the browser without authorization header: fallback to video file token user
+ const user = getAuthUser(res) || res.locals.videoFileToken?.user
if (video.downloadEnabled === true) {
return { allowed: true }