Add redirection on unavailable video due to follow constraints

pull/3127/head
Chocobozzz 2020-08-26 09:14:14 +02:00
parent ca00baa75a
commit e6abf95e9f
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
4 changed files with 41 additions and 18 deletions

View File

@ -15,7 +15,7 @@ import { VideoDownloadComponent } from '@app/shared/shared-video-miniature'
import { VideoPlaylist, VideoPlaylistService } from '@app/shared/shared-video-playlist' import { VideoPlaylist, VideoPlaylistService } from '@app/shared/shared-video-playlist'
import { MetaService } from '@ngx-meta/core' import { MetaService } from '@ngx-meta/core'
import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage' 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 { getStoredP2PEnabled, getStoredTheater } from '../../../assets/player/peertube-player-local-storage'
import { import {
CustomizationOptions, CustomizationOptions,
@ -361,7 +361,24 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
]) ])
.pipe( .pipe(
// If 401, the video is private or blocked so redirect to 404 // 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: <a href="${originUrl}">${originUrl}</a>?`,
$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 ]) => { .subscribe(([ video, captionsResult ]) => {
const queryParams = this.route.snapshot.queryParams const queryParams = this.route.snapshot.queryParams

View File

@ -1,6 +1,9 @@
import * as express from 'express' import * as express from 'express'
import { body, param, query, ValidationChain } from 'express-validator' import { body, param, query, ValidationChain } from 'express-validator'
import { UserRight, VideoChangeOwnershipStatus, VideoPrivacy } from '../../../../shared' import { getServerActor } from '@server/models/application/application'
import { MVideoFullLight } from '@server/types/models'
import { ServerErrorCode, UserRight, VideoChangeOwnershipStatus, VideoPrivacy } from '../../../../shared'
import { VideoChangeOwnershipAccept } from '../../../../shared/models/videos/video-change-ownership-accept.model'
import { import {
isBooleanValid, isBooleanValid,
isDateValid, isDateValid,
@ -12,6 +15,8 @@ import {
toIntOrNull, toIntOrNull,
toValueOrNull toValueOrNull
} from '../../../helpers/custom-validators/misc' } from '../../../helpers/custom-validators/misc'
import { isNSFWQueryValid, isNumberArray, isStringArray } from '../../../helpers/custom-validators/search'
import { checkUserCanTerminateOwnershipChange, doesChangeVideoOwnershipExist } from '../../../helpers/custom-validators/video-ownership'
import { import {
isScheduleVideoUpdatePrivacyValid, isScheduleVideoUpdatePrivacyValid,
isVideoCategoryValid, isVideoCategoryValid,
@ -27,29 +32,24 @@ import {
isVideoSupportValid, isVideoSupportValid,
isVideoTagsValid isVideoTagsValid
} from '../../../helpers/custom-validators/videos' } from '../../../helpers/custom-validators/videos'
import { cleanUpReqFiles } from '../../../helpers/express-utils'
import { getDurationFromVideoFile } from '../../../helpers/ffmpeg-utils' import { getDurationFromVideoFile } from '../../../helpers/ffmpeg-utils'
import { logger } from '../../../helpers/logger' import { logger } from '../../../helpers/logger'
import { CONSTRAINTS_FIELDS, OVERVIEWS } from '../../../initializers/constants'
import { authenticatePromiseIfNeeded } from '../../oauth'
import { areValidationErrors } from '../utils'
import { cleanUpReqFiles } from '../../../helpers/express-utils'
import { VideoModel } from '../../../models/video/video'
import { checkUserCanTerminateOwnershipChange, doesChangeVideoOwnershipExist } from '../../../helpers/custom-validators/video-ownership'
import { VideoChangeOwnershipAccept } from '../../../../shared/models/videos/video-change-ownership-accept.model'
import { AccountModel } from '../../../models/account/account'
import { isNSFWQueryValid, isNumberArray, isStringArray } from '../../../helpers/custom-validators/search'
import { CONFIG } from '../../../initializers/config'
import { isLocalVideoAccepted } from '../../../lib/moderation'
import { Hooks } from '../../../lib/plugins/hooks'
import { import {
checkUserCanManageVideo, checkUserCanManageVideo,
doesVideoChannelOfAccountExist, doesVideoChannelOfAccountExist,
doesVideoExist, doesVideoExist,
doesVideoFileOfVideoExist doesVideoFileOfVideoExist
} from '../../../helpers/middlewares' } from '../../../helpers/middlewares'
import { MVideoFullLight } from '@server/types/models'
import { getVideoWithAttributes } from '../../../helpers/video' import { getVideoWithAttributes } from '../../../helpers/video'
import { getServerActor } from '@server/models/application/application' import { CONFIG } from '../../../initializers/config'
import { CONSTRAINTS_FIELDS, OVERVIEWS } from '../../../initializers/constants'
import { isLocalVideoAccepted } from '../../../lib/moderation'
import { Hooks } from '../../../lib/plugins/hooks'
import { AccountModel } from '../../../models/account/account'
import { VideoModel } from '../../../models/video/video'
import { authenticatePromiseIfNeeded } from '../../oauth'
import { areValidationErrors } from '../utils'
const videosAddValidator = getCommonVideoEditAttributes().concat([ const videosAddValidator = getCommonVideoEditAttributes().concat([
body('videofile') body('videofile')
@ -148,7 +148,9 @@ async function checkVideoFollowConstraints (req: express.Request, res: express.R
return res.status(403) return res.status(403)
.json({ .json({
error: 'Cannot get this video regarding follow constraints.' errorCode: ServerErrorCode.DOES_NOT_RESPECT_FOLLOW_CONSTRAINTS,
error: 'Cannot get this video regarding follow constraints.',
originUrl: video.url
}) })
} }

View File

@ -7,4 +7,5 @@ export * from './emailer.model'
export * from './job.model' export * from './job.model'
export * from './log-level.type' export * from './log-level.type'
export * from './server-config.model' export * from './server-config.model'
export * from './server-error-code.enum'
export * from './server-stats.model' export * from './server-stats.model'

View File

@ -0,0 +1,3 @@
export const enum ServerErrorCode {
DOES_NOT_RESPECT_FOLLOW_CONSTRAINTS = 1
}