From e6abf95e9fc9fde52d583850cf7faafdf7d050d5 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 26 Aug 2020 09:14:14 +0200 Subject: Add redirection on unavailable video due to follow constraints --- .../+videos/+video-watch/video-watch.component.ts | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'client/src') diff --git a/client/src/app/+videos/+video-watch/video-watch.component.ts b/client/src/app/+videos/+video-watch/video-watch.component.ts index 1b2820810..f048edec4 100644 --- a/client/src/app/+videos/+video-watch/video-watch.component.ts +++ b/client/src/app/+videos/+video-watch/video-watch.component.ts @@ -15,7 +15,7 @@ import { VideoDownloadComponent } from '@app/shared/shared-video-miniature' import { VideoPlaylist, VideoPlaylistService } from '@app/shared/shared-video-playlist' import { MetaService } from '@ngx-meta/core' import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage' -import { ServerConfig, UserVideoRateType, VideoCaption, VideoPrivacy, VideoState } from '@shared/models' +import { ServerConfig, ServerErrorCode, UserVideoRateType, VideoCaption, VideoPrivacy, VideoState } from '@shared/models' import { getStoredP2PEnabled, getStoredTheater } from '../../../assets/player/peertube-player-local-storage' import { CustomizationOptions, @@ -361,7 +361,24 @@ export class VideoWatchComponent implements OnInit, OnDestroy { ]) .pipe( // If 401, the video is private or blocked so redirect to 404 - catchError(err => this.restExtractor.redirectTo404IfNotFound(err, [ 400, 401, 403, 404 ])) + catchError(err => { + if (err.body.errorCode === ServerErrorCode.DOES_NOT_RESPECT_FOLLOW_CONSTRAINTS && err.body.originUrl) { + const search = window.location.search + let originUrl = err.body.originUrl + if (search) originUrl += search + + this.confirmService.confirm( + $localize`This video is not available on this instance. Do you want to be redirected on the origin instance: ${originUrl}?`, + $localize`Redirection` + ).then(res => { + if (res === false) return this.restExtractor.redirectTo404IfNotFound(err, [ 400, 401, 403, 404 ]) + + return window.location.href = originUrl + }) + } + + return this.restExtractor.redirectTo404IfNotFound(err, [ 400, 401, 403, 404 ]) + }) ) .subscribe(([ video, captionsResult ]) => { const queryParams = this.route.snapshot.queryParams -- cgit v1.2.3