aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--client/src/app/+videos/+video-watch/video-watch.component.ts21
-rw-r--r--server/middlewares/validators/videos/videos.ts34
-rw-r--r--shared/models/server/index.ts1
-rw-r--r--shared/models/server/server-error-code.enum.ts3
4 files changed, 41 insertions, 18 deletions
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'
15import { VideoPlaylist, VideoPlaylistService } from '@app/shared/shared-video-playlist' 15import { VideoPlaylist, VideoPlaylistService } from '@app/shared/shared-video-playlist'
16import { MetaService } from '@ngx-meta/core' 16import { MetaService } from '@ngx-meta/core'
17import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage' 17import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage'
18import { ServerConfig, UserVideoRateType, VideoCaption, VideoPrivacy, VideoState } from '@shared/models' 18import { ServerConfig, ServerErrorCode, UserVideoRateType, VideoCaption, VideoPrivacy, VideoState } from '@shared/models'
19import { getStoredP2PEnabled, getStoredTheater } from '../../../assets/player/peertube-player-local-storage' 19import { getStoredP2PEnabled, getStoredTheater } from '../../../assets/player/peertube-player-local-storage'
20import { 20import {
21 CustomizationOptions, 21 CustomizationOptions,
@@ -361,7 +361,24 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
361 ]) 361 ])
362 .pipe( 362 .pipe(
363 // If 401, the video is private or blocked so redirect to 404 363 // If 401, the video is private or blocked so redirect to 404
364 catchError(err => this.restExtractor.redirectTo404IfNotFound(err, [ 400, 401, 403, 404 ])) 364 catchError(err => {
365 if (err.body.errorCode === ServerErrorCode.DOES_NOT_RESPECT_FOLLOW_CONSTRAINTS && err.body.originUrl) {
366 const search = window.location.search
367 let originUrl = err.body.originUrl
368 if (search) originUrl += search
369
370 this.confirmService.confirm(
371 $localize`This video is not available on this instance. Do you want to be redirected on the origin instance: <a href="${originUrl}">${originUrl}</a>?`,
372 $localize`Redirection`
373 ).then(res => {
374 if (res === false) return this.restExtractor.redirectTo404IfNotFound(err, [ 400, 401, 403, 404 ])
375
376 return window.location.href = originUrl
377 })
378 }
379
380 return this.restExtractor.redirectTo404IfNotFound(err, [ 400, 401, 403, 404 ])
381 })
365 ) 382 )
366 .subscribe(([ video, captionsResult ]) => { 383 .subscribe(([ video, captionsResult ]) => {
367 const queryParams = this.route.snapshot.queryParams 384 const queryParams = this.route.snapshot.queryParams
diff --git a/server/middlewares/validators/videos/videos.ts b/server/middlewares/validators/videos/videos.ts
index 40a34d3b8..b022b2c23 100644
--- a/server/middlewares/validators/videos/videos.ts
+++ b/server/middlewares/validators/videos/videos.ts
@@ -1,6 +1,9 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body, param, query, ValidationChain } from 'express-validator' 2import { body, param, query, ValidationChain } from 'express-validator'
3import { UserRight, VideoChangeOwnershipStatus, VideoPrivacy } from '../../../../shared' 3import { getServerActor } from '@server/models/application/application'
4import { MVideoFullLight } from '@server/types/models'
5import { ServerErrorCode, UserRight, VideoChangeOwnershipStatus, VideoPrivacy } from '../../../../shared'
6import { VideoChangeOwnershipAccept } from '../../../../shared/models/videos/video-change-ownership-accept.model'
4import { 7import {
5 isBooleanValid, 8 isBooleanValid,
6 isDateValid, 9 isDateValid,
@@ -12,6 +15,8 @@ import {
12 toIntOrNull, 15 toIntOrNull,
13 toValueOrNull 16 toValueOrNull
14} from '../../../helpers/custom-validators/misc' 17} from '../../../helpers/custom-validators/misc'
18import { isNSFWQueryValid, isNumberArray, isStringArray } from '../../../helpers/custom-validators/search'
19import { checkUserCanTerminateOwnershipChange, doesChangeVideoOwnershipExist } from '../../../helpers/custom-validators/video-ownership'
15import { 20import {
16 isScheduleVideoUpdatePrivacyValid, 21 isScheduleVideoUpdatePrivacyValid,
17 isVideoCategoryValid, 22 isVideoCategoryValid,
@@ -27,29 +32,24 @@ import {
27 isVideoSupportValid, 32 isVideoSupportValid,
28 isVideoTagsValid 33 isVideoTagsValid
29} from '../../../helpers/custom-validators/videos' 34} from '../../../helpers/custom-validators/videos'
35import { cleanUpReqFiles } from '../../../helpers/express-utils'
30import { getDurationFromVideoFile } from '../../../helpers/ffmpeg-utils' 36import { getDurationFromVideoFile } from '../../../helpers/ffmpeg-utils'
31import { logger } from '../../../helpers/logger' 37import { logger } from '../../../helpers/logger'
32import { CONSTRAINTS_FIELDS, OVERVIEWS } from '../../../initializers/constants'
33import { authenticatePromiseIfNeeded } from '../../oauth'
34import { areValidationErrors } from '../utils'
35import { cleanUpReqFiles } from '../../../helpers/express-utils'
36import { VideoModel } from '../../../models/video/video'
37import { checkUserCanTerminateOwnershipChange, doesChangeVideoOwnershipExist } from '../../../helpers/custom-validators/video-ownership'
38import { VideoChangeOwnershipAccept } from '../../../../shared/models/videos/video-change-ownership-accept.model'
39import { AccountModel } from '../../../models/account/account'
40import { isNSFWQueryValid, isNumberArray, isStringArray } from '../../../helpers/custom-validators/search'
41import { CONFIG } from '../../../initializers/config'
42import { isLocalVideoAccepted } from '../../../lib/moderation'
43import { Hooks } from '../../../lib/plugins/hooks'
44import { 38import {
45 checkUserCanManageVideo, 39 checkUserCanManageVideo,
46 doesVideoChannelOfAccountExist, 40 doesVideoChannelOfAccountExist,
47 doesVideoExist, 41 doesVideoExist,
48 doesVideoFileOfVideoExist 42 doesVideoFileOfVideoExist
49} from '../../../helpers/middlewares' 43} from '../../../helpers/middlewares'
50import { MVideoFullLight } from '@server/types/models'
51import { getVideoWithAttributes } from '../../../helpers/video' 44import { getVideoWithAttributes } from '../../../helpers/video'
52import { getServerActor } from '@server/models/application/application' 45import { CONFIG } from '../../../initializers/config'
46import { CONSTRAINTS_FIELDS, OVERVIEWS } from '../../../initializers/constants'
47import { isLocalVideoAccepted } from '../../../lib/moderation'
48import { Hooks } from '../../../lib/plugins/hooks'
49import { AccountModel } from '../../../models/account/account'
50import { VideoModel } from '../../../models/video/video'
51import { authenticatePromiseIfNeeded } from '../../oauth'
52import { areValidationErrors } from '../utils'
53 53
54const videosAddValidator = getCommonVideoEditAttributes().concat([ 54const videosAddValidator = getCommonVideoEditAttributes().concat([
55 body('videofile') 55 body('videofile')
@@ -148,7 +148,9 @@ async function checkVideoFollowConstraints (req: express.Request, res: express.R
148 148
149 return res.status(403) 149 return res.status(403)
150 .json({ 150 .json({
151 error: 'Cannot get this video regarding follow constraints.' 151 errorCode: ServerErrorCode.DOES_NOT_RESPECT_FOLLOW_CONSTRAINTS,
152 error: 'Cannot get this video regarding follow constraints.',
153 originUrl: video.url
152 }) 154 })
153} 155}
154 156
diff --git a/shared/models/server/index.ts b/shared/models/server/index.ts
index b079bc9a0..f253a3a79 100644
--- a/shared/models/server/index.ts
+++ b/shared/models/server/index.ts
@@ -7,4 +7,5 @@ export * from './emailer.model'
7export * from './job.model' 7export * from './job.model'
8export * from './log-level.type' 8export * from './log-level.type'
9export * from './server-config.model' 9export * from './server-config.model'
10export * from './server-error-code.enum'
10export * from './server-stats.model' 11export * from './server-stats.model'
diff --git a/shared/models/server/server-error-code.enum.ts b/shared/models/server/server-error-code.enum.ts
new file mode 100644
index 000000000..0bfb2c470
--- /dev/null
+++ b/shared/models/server/server-error-code.enum.ts
@@ -0,0 +1,3 @@
1export const enum ServerErrorCode {
2 DOES_NOT_RESPECT_FOLLOW_CONSTRAINTS = 1
3}