diff options
-rw-r--r-- | client/src/app/+videos/+video-watch/video-watch.component.ts | 21 | ||||
-rw-r--r-- | server/middlewares/validators/videos/videos.ts | 34 | ||||
-rw-r--r-- | shared/models/server/index.ts | 1 | ||||
-rw-r--r-- | shared/models/server/server-error-code.enum.ts | 3 |
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' | |||
15 | import { VideoPlaylist, VideoPlaylistService } from '@app/shared/shared-video-playlist' | 15 | import { VideoPlaylist, VideoPlaylistService } from '@app/shared/shared-video-playlist' |
16 | import { MetaService } from '@ngx-meta/core' | 16 | import { MetaService } from '@ngx-meta/core' |
17 | import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage' | 17 | import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage' |
18 | import { ServerConfig, UserVideoRateType, VideoCaption, VideoPrivacy, VideoState } from '@shared/models' | 18 | import { ServerConfig, ServerErrorCode, UserVideoRateType, VideoCaption, VideoPrivacy, VideoState } from '@shared/models' |
19 | import { getStoredP2PEnabled, getStoredTheater } from '../../../assets/player/peertube-player-local-storage' | 19 | import { getStoredP2PEnabled, getStoredTheater } from '../../../assets/player/peertube-player-local-storage' |
20 | import { | 20 | import { |
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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body, param, query, ValidationChain } from 'express-validator' | 2 | import { body, param, query, ValidationChain } from 'express-validator' |
3 | import { UserRight, VideoChangeOwnershipStatus, VideoPrivacy } from '../../../../shared' | 3 | import { getServerActor } from '@server/models/application/application' |
4 | import { MVideoFullLight } from '@server/types/models' | ||
5 | import { ServerErrorCode, UserRight, VideoChangeOwnershipStatus, VideoPrivacy } from '../../../../shared' | ||
6 | import { VideoChangeOwnershipAccept } from '../../../../shared/models/videos/video-change-ownership-accept.model' | ||
4 | import { | 7 | import { |
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' |
18 | import { isNSFWQueryValid, isNumberArray, isStringArray } from '../../../helpers/custom-validators/search' | ||
19 | import { checkUserCanTerminateOwnershipChange, doesChangeVideoOwnershipExist } from '../../../helpers/custom-validators/video-ownership' | ||
15 | import { | 20 | import { |
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' |
35 | import { cleanUpReqFiles } from '../../../helpers/express-utils' | ||
30 | import { getDurationFromVideoFile } from '../../../helpers/ffmpeg-utils' | 36 | import { getDurationFromVideoFile } from '../../../helpers/ffmpeg-utils' |
31 | import { logger } from '../../../helpers/logger' | 37 | import { logger } from '../../../helpers/logger' |
32 | import { CONSTRAINTS_FIELDS, OVERVIEWS } from '../../../initializers/constants' | ||
33 | import { authenticatePromiseIfNeeded } from '../../oauth' | ||
34 | import { areValidationErrors } from '../utils' | ||
35 | import { cleanUpReqFiles } from '../../../helpers/express-utils' | ||
36 | import { VideoModel } from '../../../models/video/video' | ||
37 | import { checkUserCanTerminateOwnershipChange, doesChangeVideoOwnershipExist } from '../../../helpers/custom-validators/video-ownership' | ||
38 | import { VideoChangeOwnershipAccept } from '../../../../shared/models/videos/video-change-ownership-accept.model' | ||
39 | import { AccountModel } from '../../../models/account/account' | ||
40 | import { isNSFWQueryValid, isNumberArray, isStringArray } from '../../../helpers/custom-validators/search' | ||
41 | import { CONFIG } from '../../../initializers/config' | ||
42 | import { isLocalVideoAccepted } from '../../../lib/moderation' | ||
43 | import { Hooks } from '../../../lib/plugins/hooks' | ||
44 | import { | 38 | import { |
45 | checkUserCanManageVideo, | 39 | checkUserCanManageVideo, |
46 | doesVideoChannelOfAccountExist, | 40 | doesVideoChannelOfAccountExist, |
47 | doesVideoExist, | 41 | doesVideoExist, |
48 | doesVideoFileOfVideoExist | 42 | doesVideoFileOfVideoExist |
49 | } from '../../../helpers/middlewares' | 43 | } from '../../../helpers/middlewares' |
50 | import { MVideoFullLight } from '@server/types/models' | ||
51 | import { getVideoWithAttributes } from '../../../helpers/video' | 44 | import { getVideoWithAttributes } from '../../../helpers/video' |
52 | import { getServerActor } from '@server/models/application/application' | 45 | import { CONFIG } from '../../../initializers/config' |
46 | import { CONSTRAINTS_FIELDS, OVERVIEWS } from '../../../initializers/constants' | ||
47 | import { isLocalVideoAccepted } from '../../../lib/moderation' | ||
48 | import { Hooks } from '../../../lib/plugins/hooks' | ||
49 | import { AccountModel } from '../../../models/account/account' | ||
50 | import { VideoModel } from '../../../models/video/video' | ||
51 | import { authenticatePromiseIfNeeded } from '../../oauth' | ||
52 | import { areValidationErrors } from '../utils' | ||
53 | 53 | ||
54 | const videosAddValidator = getCommonVideoEditAttributes().concat([ | 54 | const 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' | |||
7 | export * from './job.model' | 7 | export * from './job.model' |
8 | export * from './log-level.type' | 8 | export * from './log-level.type' |
9 | export * from './server-config.model' | 9 | export * from './server-config.model' |
10 | export * from './server-error-code.enum' | ||
10 | export * from './server-stats.model' | 11 | export * 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 @@ | |||
1 | export const enum ServerErrorCode { | ||
2 | DOES_NOT_RESPECT_FOLLOW_CONSTRAINTS = 1 | ||
3 | } | ||