aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-06-03 17:33:44 +0200
committerChocobozzz <me@florianbigard.com>2021-06-03 18:03:36 +0200
commit10363c74c1d869f0e0c7bc4d0367b1f34d1bb6a4 (patch)
tree008f8dad8032684f46105a261b27b2d6f05b36eb
parent5e08989ede1a340b9edb94465a11b1e04bf24094 (diff)
downloadPeerTube-10363c74c1d869f0e0c7bc4d0367b1f34d1bb6a4.tar.gz
PeerTube-10363c74c1d869f0e0c7bc4d0367b1f34d1bb6a4.tar.zst
PeerTube-10363c74c1d869f0e0c7bc4d0367b1f34d1bb6a4.zip
Move middleware utils in middlewares
helpers modules should not import models
-rw-r--r--server/controllers/api/search.ts3
-rw-r--r--server/helpers/custom-validators/video-comments.ts72
-rw-r--r--server/helpers/custom-validators/video-imports.ts19
-rw-r--r--server/helpers/custom-validators/video-ownership.ts25
-rw-r--r--server/helpers/video.ts65
-rw-r--r--server/lib/activitypub/actors/get.ts2
-rw-r--r--server/lib/activitypub/actors/index.ts1
-rw-r--r--server/lib/activitypub/actors/refresh.ts4
-rw-r--r--server/lib/activitypub/actors/shared/index.ts2
-rw-r--r--server/lib/activitypub/actors/webfinger.ts (renamed from server/helpers/webfinger.ts)12
-rw-r--r--server/lib/activitypub/videos/get.ts2
-rw-r--r--server/lib/activitypub/videos/refresh.ts2
-rw-r--r--server/lib/job-queue/handlers/activitypub-follow.ts3
-rw-r--r--server/lib/job-queue/handlers/activitypub-refresher.ts2
-rw-r--r--server/lib/model-loaders/actor.ts (renamed from server/helpers/actor.ts)4
-rw-r--r--server/lib/model-loaders/index.ts2
-rw-r--r--server/lib/model-loaders/video.ts64
-rw-r--r--server/lib/server-config-manager.ts2
-rw-r--r--server/lib/signup.ts (renamed from server/helpers/signup.ts)0
-rw-r--r--server/middlewares/activitypub.ts9
-rw-r--r--server/middlewares/validators/abuse.ts4
-rw-r--r--server/middlewares/validators/account.ts3
-rw-r--r--server/middlewares/validators/activitypub/pagination.ts4
-rw-r--r--server/middlewares/validators/activitypub/signature.ts5
-rw-r--r--server/middlewares/validators/actor-image.ts2
-rw-r--r--server/middlewares/validators/blocklist.ts15
-rw-r--r--server/middlewares/validators/bulk.ts5
-rw-r--r--server/middlewares/validators/config.ts2
-rw-r--r--server/middlewares/validators/feeds.ts10
-rw-r--r--server/middlewares/validators/follows.ts4
-rw-r--r--server/middlewares/validators/jobs.ts2
-rw-r--r--server/middlewares/validators/logs.ts6
-rw-r--r--server/middlewares/validators/oembed.ts4
-rw-r--r--server/middlewares/validators/pagination.ts4
-rw-r--r--server/middlewares/validators/plugins.ts2
-rw-r--r--server/middlewares/validators/redundancy.ts9
-rw-r--r--server/middlewares/validators/search.ts6
-rw-r--r--server/middlewares/validators/server.ts12
-rw-r--r--server/middlewares/validators/shared/abuses.ts (renamed from server/helpers/middlewares/abuses.ts)4
-rw-r--r--server/middlewares/validators/shared/accounts.ts (renamed from server/helpers/middlewares/accounts.ts)6
-rw-r--r--server/middlewares/validators/shared/index.ts (renamed from server/helpers/middlewares/index.ts)4
-rw-r--r--server/middlewares/validators/shared/utils.ts (renamed from server/middlewares/validators/utils.ts)2
-rw-r--r--server/middlewares/validators/shared/video-blacklists.ts (renamed from server/helpers/middlewares/video-blacklists.ts)4
-rw-r--r--server/middlewares/validators/shared/video-captions.ts (renamed from server/helpers/middlewares/video-captions.ts)4
-rw-r--r--server/middlewares/validators/shared/video-channels.ts (renamed from server/helpers/middlewares/video-channels.ts)4
-rw-r--r--server/middlewares/validators/shared/video-comments.ts73
-rw-r--r--server/middlewares/validators/shared/video-imports.ts22
-rw-r--r--server/middlewares/validators/shared/video-ownerships.ts24
-rw-r--r--server/middlewares/validators/shared/video-playlists.ts (renamed from server/helpers/middlewares/video-playlists.ts)6
-rw-r--r--server/middlewares/validators/shared/videos.ts (renamed from server/helpers/middlewares/videos.ts)10
-rw-r--r--server/middlewares/validators/sort.ts2
-rw-r--r--server/middlewares/validators/themes.ts8
-rw-r--r--server/middlewares/validators/user-history.ts4
-rw-r--r--server/middlewares/validators/user-notifications.ts6
-rw-r--r--server/middlewares/validators/user-subscriptions.ts2
-rw-r--r--server/middlewares/validators/users.ts7
-rw-r--r--server/middlewares/validators/videos/video-blacklist.ts5
-rw-r--r--server/middlewares/validators/videos/video-captions.ts9
-rw-r--r--server/middlewares/validators/videos/video-channels.ts3
-rw-r--r--server/middlewares/validators/videos/video-comments.ts11
-rw-r--r--server/middlewares/validators/videos/video-imports.ts5
-rw-r--r--server/middlewares/validators/videos/video-live.ts13
-rw-r--r--server/middlewares/validators/videos/video-playlists.ts3
-rw-r--r--server/middlewares/validators/videos/video-rates.ts9
-rw-r--r--server/middlewares/validators/videos/video-shares.ts5
-rw-r--r--server/middlewares/validators/videos/video-watch.ts7
-rw-r--r--server/middlewares/validators/videos/videos.ts17
-rw-r--r--server/middlewares/validators/webfinger.ts2
68 files changed, 339 insertions, 336 deletions
diff --git a/server/controllers/api/search.ts b/server/controllers/api/search.ts
index ef0f4285d..a3b66b2a6 100644
--- a/server/controllers/api/search.ts
+++ b/server/controllers/api/search.ts
@@ -14,8 +14,7 @@ import { VideoChannelsSearchQuery, VideosSearchQuery } from '../../../shared/mod
14import { buildNSFWFilter, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils' 14import { buildNSFWFilter, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils'
15import { logger } from '../../helpers/logger' 15import { logger } from '../../helpers/logger'
16import { getFormattedObjects } from '../../helpers/utils' 16import { getFormattedObjects } from '../../helpers/utils'
17import { loadActorUrlOrGetFromWebfinger } from '../../helpers/webfinger' 17import { getOrCreateAPActor, loadActorUrlOrGetFromWebfinger } from '../../lib/activitypub/actors'
18import { getOrCreateAPActor } from '../../lib/activitypub/actors'
19import { 18import {
20 asyncMiddleware, 19 asyncMiddleware,
21 commonVideosFiltersValidator, 20 commonVideosFiltersValidator,
diff --git a/server/helpers/custom-validators/video-comments.ts b/server/helpers/custom-validators/video-comments.ts
index 5c88447ad..94bdf237a 100644
--- a/server/helpers/custom-validators/video-comments.ts
+++ b/server/helpers/custom-validators/video-comments.ts
@@ -1,9 +1,5 @@
1import * as express from 'express'
2import validator from 'validator' 1import validator from 'validator'
3import { VideoCommentModel } from '@server/models/video/video-comment'
4import { CONSTRAINTS_FIELDS } from '../../initializers/constants' 2import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
5import { MVideoId } from '@server/types/models'
6import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
7 3
8const VIDEO_COMMENTS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_COMMENTS 4const VIDEO_COMMENTS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_COMMENTS
9 5
@@ -11,74 +7,8 @@ function isValidVideoCommentText (value: string) {
11 return value === null || validator.isLength(value, VIDEO_COMMENTS_CONSTRAINTS_FIELDS.TEXT) 7 return value === null || validator.isLength(value, VIDEO_COMMENTS_CONSTRAINTS_FIELDS.TEXT)
12} 8}
13 9
14async function doesVideoCommentThreadExist (idArg: number | string, video: MVideoId, res: express.Response) {
15 const id = parseInt(idArg + '', 10)
16 const videoComment = await VideoCommentModel.loadById(id)
17
18 if (!videoComment) {
19 res.fail({
20 status: HttpStatusCode.NOT_FOUND_404,
21 message: 'Video comment thread not found'
22 })
23 return false
24 }
25
26 if (videoComment.videoId !== video.id) {
27 res.fail({ message: 'Video comment is not associated to this video.' })
28 return false
29 }
30
31 if (videoComment.inReplyToCommentId !== null) {
32 res.fail({ message: 'Video comment is not a thread.' })
33 return false
34 }
35
36 res.locals.videoCommentThread = videoComment
37 return true
38}
39
40async function doesVideoCommentExist (idArg: number | string, video: MVideoId, res: express.Response) {
41 const id = parseInt(idArg + '', 10)
42 const videoComment = await VideoCommentModel.loadByIdAndPopulateVideoAndAccountAndReply(id)
43
44 if (!videoComment) {
45 res.fail({
46 status: HttpStatusCode.NOT_FOUND_404,
47 message: 'Video comment thread not found'
48 })
49 return false
50 }
51
52 if (videoComment.videoId !== video.id) {
53 res.fail({ message: 'Video comment is not associated to this video.' })
54 return false
55 }
56
57 res.locals.videoCommentFull = videoComment
58 return true
59}
60
61async function doesCommentIdExist (idArg: number | string, res: express.Response) {
62 const id = parseInt(idArg + '', 10)
63 const videoComment = await VideoCommentModel.loadByIdAndPopulateVideoAndAccountAndReply(id)
64
65 if (!videoComment) {
66 res.fail({
67 status: HttpStatusCode.NOT_FOUND_404,
68 message: 'Video comment thread not found'
69 })
70 return false
71 }
72
73 res.locals.videoCommentFull = videoComment
74 return true
75}
76
77// --------------------------------------------------------------------------- 10// ---------------------------------------------------------------------------
78 11
79export { 12export {
80 isValidVideoCommentText, 13 isValidVideoCommentText
81 doesVideoCommentThreadExist,
82 doesVideoCommentExist,
83 doesCommentIdExist
84} 14}
diff --git a/server/helpers/custom-validators/video-imports.ts b/server/helpers/custom-validators/video-imports.ts
index 3ad7a4648..dbf6a3504 100644
--- a/server/helpers/custom-validators/video-imports.ts
+++ b/server/helpers/custom-validators/video-imports.ts
@@ -2,9 +2,6 @@ import 'multer'
2import validator from 'validator' 2import validator from 'validator'
3import { CONSTRAINTS_FIELDS, MIMETYPES, VIDEO_IMPORT_STATES } from '../../initializers/constants' 3import { CONSTRAINTS_FIELDS, MIMETYPES, VIDEO_IMPORT_STATES } from '../../initializers/constants'
4import { exists, isFileValid } from './misc' 4import { exists, isFileValid } from './misc'
5import * as express from 'express'
6import { VideoImportModel } from '../../models/video/video-import'
7import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
8 5
9function isVideoImportTargetUrlValid (url: string) { 6function isVideoImportTargetUrlValid (url: string) {
10 const isURLOptions = { 7 const isURLOptions = {
@@ -32,26 +29,10 @@ function isVideoImportTorrentFile (files: { [ fieldname: string ]: Express.Multe
32 return isFileValid(files, videoTorrentImportRegex, 'torrentfile', CONSTRAINTS_FIELDS.VIDEO_IMPORTS.TORRENT_FILE.FILE_SIZE.max, true) 29 return isFileValid(files, videoTorrentImportRegex, 'torrentfile', CONSTRAINTS_FIELDS.VIDEO_IMPORTS.TORRENT_FILE.FILE_SIZE.max, true)
33} 30}
34 31
35async function doesVideoImportExist (id: number, res: express.Response) {
36 const videoImport = await VideoImportModel.loadAndPopulateVideo(id)
37
38 if (!videoImport) {
39 res.fail({
40 status: HttpStatusCode.NOT_FOUND_404,
41 message: 'Video import not found'
42 })
43 return false
44 }
45
46 res.locals.videoImport = videoImport
47 return true
48}
49
50// --------------------------------------------------------------------------- 32// ---------------------------------------------------------------------------
51 33
52export { 34export {
53 isVideoImportStateValid, 35 isVideoImportStateValid,
54 isVideoImportTargetUrlValid, 36 isVideoImportTargetUrlValid,
55 doesVideoImportExist,
56 isVideoImportTorrentFile 37 isVideoImportTorrentFile
57} 38}
diff --git a/server/helpers/custom-validators/video-ownership.ts b/server/helpers/custom-validators/video-ownership.ts
index 21a6b7203..0e1c63bad 100644
--- a/server/helpers/custom-validators/video-ownership.ts
+++ b/server/helpers/custom-validators/video-ownership.ts
@@ -1,26 +1,9 @@
1import { Response } from 'express' 1import { Response } from 'express'
2import { VideoChangeOwnershipModel } from '../../models/video/video-change-ownership'
3import { MVideoChangeOwnershipFull } from '@server/types/models/video/video-change-ownership'
4import { MUserId } from '@server/types/models' 2import { MUserId } from '@server/types/models'
3import { MVideoChangeOwnershipFull } from '@server/types/models/video/video-change-ownership'
5import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' 4import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
6 5
7export async function doesChangeVideoOwnershipExist (idArg: number | string, res: Response) { 6function checkUserCanTerminateOwnershipChange (user: MUserId, videoChangeOwnership: MVideoChangeOwnershipFull, res: Response) {
8 const id = parseInt(idArg + '', 10)
9 const videoChangeOwnership = await VideoChangeOwnershipModel.load(id)
10
11 if (!videoChangeOwnership) {
12 res.fail({
13 status: HttpStatusCode.NOT_FOUND_404,
14 message: 'Video change ownership not found'
15 })
16 return false
17 }
18
19 res.locals.videoChangeOwnership = videoChangeOwnership
20 return true
21}
22
23export function checkUserCanTerminateOwnershipChange (user: MUserId, videoChangeOwnership: MVideoChangeOwnershipFull, res: Response) {
24 if (videoChangeOwnership.NextOwner.userId === user.id) { 7 if (videoChangeOwnership.NextOwner.userId === user.id) {
25 return true 8 return true
26 } 9 }
@@ -31,3 +14,7 @@ export function checkUserCanTerminateOwnershipChange (user: MUserId, videoChange
31 }) 14 })
32 return false 15 return false
33} 16}
17
18export {
19 checkUserCanTerminateOwnershipChange
20}
diff --git a/server/helpers/video.ts b/server/helpers/video.ts
index 7c510f474..d3445bed5 100644
--- a/server/helpers/video.ts
+++ b/server/helpers/video.ts
@@ -1,66 +1,7 @@
1import { Response } from 'express' 1import { Response } from 'express'
2import { CONFIG } from '@server/initializers/config' 2import { CONFIG } from '@server/initializers/config'
3import { 3import { isStreamingPlaylist, MStreamingPlaylistVideo, MVideo } from '@server/types/models'
4 isStreamingPlaylist,
5 MStreamingPlaylistVideo,
6 MVideo,
7 MVideoAccountLightBlacklistAllFiles,
8 MVideoFullLight,
9 MVideoIdThumbnail,
10 MVideoImmutable,
11 MVideoThumbnail,
12 MVideoWithRights
13} from '@server/types/models'
14import { VideoPrivacy, VideoState } from '@shared/models' 4import { VideoPrivacy, VideoState } from '@shared/models'
15import { VideoModel } from '../models/video/video'
16
17type VideoFetchType = 'all' | 'only-video' | 'only-video-with-rights' | 'id' | 'none' | 'only-immutable-attributes'
18
19function fetchVideo (id: number | string, fetchType: 'all', userId?: number): Promise<MVideoFullLight>
20function fetchVideo (id: number | string, fetchType: 'only-immutable-attributes'): Promise<MVideoImmutable>
21function fetchVideo (id: number | string, fetchType: 'only-video', userId?: number): Promise<MVideoThumbnail>
22function fetchVideo (id: number | string, fetchType: 'only-video-with-rights', userId?: number): Promise<MVideoWithRights>
23function fetchVideo (id: number | string, fetchType: 'id' | 'none', userId?: number): Promise<MVideoIdThumbnail>
24function fetchVideo (
25 id: number | string,
26 fetchType: VideoFetchType,
27 userId?: number
28): Promise<MVideoFullLight | MVideoThumbnail | MVideoWithRights | MVideoIdThumbnail | MVideoImmutable>
29function fetchVideo (
30 id: number | string,
31 fetchType: VideoFetchType,
32 userId?: number
33): Promise<MVideoFullLight | MVideoThumbnail | MVideoWithRights | MVideoIdThumbnail | MVideoImmutable> {
34 if (fetchType === 'all') return VideoModel.loadAndPopulateAccountAndServerAndTags(id, undefined, userId)
35
36 if (fetchType === 'only-immutable-attributes') return VideoModel.loadImmutableAttributes(id)
37
38 if (fetchType === 'only-video-with-rights') return VideoModel.loadWithRights(id)
39
40 if (fetchType === 'only-video') return VideoModel.load(id)
41
42 if (fetchType === 'id' || fetchType === 'none') return VideoModel.loadOnlyId(id)
43}
44
45type VideoFetchByUrlType = 'all' | 'only-video' | 'only-immutable-attributes'
46
47function fetchVideoByUrl (url: string, fetchType: 'all'): Promise<MVideoAccountLightBlacklistAllFiles>
48function fetchVideoByUrl (url: string, fetchType: 'only-immutable-attributes'): Promise<MVideoImmutable>
49function fetchVideoByUrl (url: string, fetchType: 'only-video'): Promise<MVideoThumbnail>
50function fetchVideoByUrl (
51 url: string,
52 fetchType: VideoFetchByUrlType
53): Promise<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable>
54function fetchVideoByUrl (
55 url: string,
56 fetchType: VideoFetchByUrlType
57): Promise<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable> {
58 if (fetchType === 'all') return VideoModel.loadByUrlAndPopulateAccount(url)
59
60 if (fetchType === 'only-immutable-attributes') return VideoModel.loadByUrlImmutableAttributes(url)
61
62 if (fetchType === 'only-video') return VideoModel.loadByUrl(url)
63}
64 5
65function getVideoWithAttributes (res: Response) { 6function getVideoWithAttributes (res: Response) {
66 return res.locals.videoAll || res.locals.onlyVideo || res.locals.onlyVideoWithRights 7 return res.locals.videoAll || res.locals.onlyVideo || res.locals.onlyVideoWithRights
@@ -100,11 +41,7 @@ function getExtFromMimetype (mimeTypes: { [id: string]: string | string[] }, mim
100} 41}
101 42
102export { 43export {
103 VideoFetchType,
104 VideoFetchByUrlType,
105 fetchVideo,
106 getVideoWithAttributes, 44 getVideoWithAttributes,
107 fetchVideoByUrl,
108 extractVideo, 45 extractVideo,
109 getExtFromMimetype, 46 getExtFromMimetype,
110 isStateForFederation, 47 isStateForFederation,
diff --git a/server/lib/activitypub/actors/get.ts b/server/lib/activitypub/actors/get.ts
index 0d5bea789..e7e87a967 100644
--- a/server/lib/activitypub/actors/get.ts
+++ b/server/lib/activitypub/actors/get.ts
@@ -1,9 +1,9 @@
1 1
2import { checkUrlsSameHost, getAPId } from '@server/helpers/activitypub' 2import { checkUrlsSameHost, getAPId } from '@server/helpers/activitypub'
3import { ActorFetchByUrlType, fetchActorByUrl } from '@server/helpers/actor'
4import { retryTransactionWrapper } from '@server/helpers/database-utils' 3import { retryTransactionWrapper } from '@server/helpers/database-utils'
5import { logger } from '@server/helpers/logger' 4import { logger } from '@server/helpers/logger'
6import { JobQueue } from '@server/lib/job-queue' 5import { JobQueue } from '@server/lib/job-queue'
6import { ActorFetchByUrlType, fetchActorByUrl } from '@server/lib/model-loaders'
7import { MActor, MActorAccountChannelId, MActorAccountChannelIdActor, MActorAccountId, MActorFullActor } from '@server/types/models' 7import { MActor, MActorAccountChannelId, MActorAccountChannelIdActor, MActorAccountId, MActorFullActor } from '@server/types/models'
8import { ActivityPubActor } from '@shared/models' 8import { ActivityPubActor } from '@shared/models'
9import { refreshActorIfNeeded } from './refresh' 9import { refreshActorIfNeeded } from './refresh'
diff --git a/server/lib/activitypub/actors/index.ts b/server/lib/activitypub/actors/index.ts
index a54da6798..5ee2a6f1a 100644
--- a/server/lib/activitypub/actors/index.ts
+++ b/server/lib/activitypub/actors/index.ts
@@ -3,3 +3,4 @@ export * from './image'
3export * from './keys' 3export * from './keys'
4export * from './refresh' 4export * from './refresh'
5export * from './updater' 5export * from './updater'
6export * from './webfinger'
diff --git a/server/lib/activitypub/actors/refresh.ts b/server/lib/activitypub/actors/refresh.ts
index ff3b249d0..9f2289bfa 100644
--- a/server/lib/activitypub/actors/refresh.ts
+++ b/server/lib/activitypub/actors/refresh.ts
@@ -1,12 +1,12 @@
1import { ActorFetchByUrlType } from '@server/helpers/actor'
2import { logger } from '@server/helpers/logger' 1import { logger } from '@server/helpers/logger'
3import { PeerTubeRequestError } from '@server/helpers/requests' 2import { PeerTubeRequestError } from '@server/helpers/requests'
4import { getUrlFromWebfinger } from '@server/helpers/webfinger' 3import { ActorFetchByUrlType } from '@server/lib/model-loaders'
5import { ActorModel } from '@server/models/actor/actor' 4import { ActorModel } from '@server/models/actor/actor'
6import { MActorAccountChannelId, MActorFull } from '@server/types/models' 5import { MActorAccountChannelId, MActorFull } from '@server/types/models'
7import { HttpStatusCode } from '@shared/core-utils' 6import { HttpStatusCode } from '@shared/core-utils'
8import { fetchRemoteActor } from './shared' 7import { fetchRemoteActor } from './shared'
9import { APActorUpdater } from './updater' 8import { APActorUpdater } from './updater'
9import { getUrlFromWebfinger } from './webfinger'
10 10
11async function refreshActorIfNeeded <T extends MActorFull | MActorAccountChannelId> ( 11async function refreshActorIfNeeded <T extends MActorFull | MActorAccountChannelId> (
12 actorArg: T, 12 actorArg: T,
diff --git a/server/lib/activitypub/actors/shared/index.ts b/server/lib/activitypub/actors/shared/index.ts
index a2ff468cf..52af1a8e1 100644
--- a/server/lib/activitypub/actors/shared/index.ts
+++ b/server/lib/activitypub/actors/shared/index.ts
@@ -1,3 +1,3 @@
1export * from './creator' 1export * from './creator'
2export * from './url-to-object'
3export * from './object-to-model-attributes' 2export * from './object-to-model-attributes'
3export * from './url-to-object'
diff --git a/server/helpers/webfinger.ts b/server/lib/activitypub/actors/webfinger.ts
index 33367f651..cf8eddfc7 100644
--- a/server/helpers/webfinger.ts
+++ b/server/lib/activitypub/actors/webfinger.ts
@@ -1,10 +1,10 @@
1import * as WebFinger from 'webfinger.js' 1import * as WebFinger from 'webfinger.js'
2import { WebFingerData } from '../../shared' 2import { isTestInstance } from '@server/helpers/core-utils'
3import { WEBSERVER } from '../initializers/constants' 3import { isActivityPubUrlValid } from '@server/helpers/custom-validators/activitypub/misc'
4import { ActorModel } from '../models/actor/actor' 4import { WEBSERVER } from '@server/initializers/constants'
5import { MActorFull } from '../types/models' 5import { ActorModel } from '@server/models/actor/actor'
6import { isTestInstance } from './core-utils' 6import { MActorFull } from '@server/types/models'
7import { isActivityPubUrlValid } from './custom-validators/activitypub/misc' 7import { WebFingerData } from '@shared/models'
8 8
9const webfinger = new WebFinger({ 9const webfinger = new WebFinger({
10 webfist_fallback: false, 10 webfist_fallback: false,
diff --git a/server/lib/activitypub/videos/get.ts b/server/lib/activitypub/videos/get.ts
index a8c41e178..38ba4978c 100644
--- a/server/lib/activitypub/videos/get.ts
+++ b/server/lib/activitypub/videos/get.ts
@@ -1,7 +1,7 @@
1import { getAPId } from '@server/helpers/activitypub' 1import { getAPId } from '@server/helpers/activitypub'
2import { retryTransactionWrapper } from '@server/helpers/database-utils' 2import { retryTransactionWrapper } from '@server/helpers/database-utils'
3import { fetchVideoByUrl, VideoFetchByUrlType } from '@server/helpers/video'
4import { JobQueue } from '@server/lib/job-queue' 3import { JobQueue } from '@server/lib/job-queue'
4import { fetchVideoByUrl, VideoFetchByUrlType } from '@server/lib/model-loaders'
5import { MVideoAccountLightBlacklistAllFiles, MVideoImmutable, MVideoThumbnail } from '@server/types/models' 5import { MVideoAccountLightBlacklistAllFiles, MVideoImmutable, MVideoThumbnail } from '@server/types/models'
6import { refreshVideoIfNeeded } from './refresh' 6import { refreshVideoIfNeeded } from './refresh'
7import { APVideoCreator, fetchRemoteVideo, SyncParam, syncVideoExternalAttributes } from './shared' 7import { APVideoCreator, fetchRemoteVideo, SyncParam, syncVideoExternalAttributes } from './shared'
diff --git a/server/lib/activitypub/videos/refresh.ts b/server/lib/activitypub/videos/refresh.ts
index 71a4e75b0..f1a3a6fac 100644
--- a/server/lib/activitypub/videos/refresh.ts
+++ b/server/lib/activitypub/videos/refresh.ts
@@ -1,7 +1,7 @@
1import { logger, loggerTagsFactory } from '@server/helpers/logger' 1import { logger, loggerTagsFactory } from '@server/helpers/logger'
2import { PeerTubeRequestError } from '@server/helpers/requests' 2import { PeerTubeRequestError } from '@server/helpers/requests'
3import { VideoFetchByUrlType } from '@server/helpers/video'
4import { ActorFollowScoreCache } from '@server/lib/files-cache' 3import { ActorFollowScoreCache } from '@server/lib/files-cache'
4import { VideoFetchByUrlType } from '@server/lib/model-loaders'
5import { VideoModel } from '@server/models/video/video' 5import { VideoModel } from '@server/models/video/video'
6import { MVideoAccountLightBlacklistAllFiles, MVideoThumbnail } from '@server/types/models' 6import { MVideoAccountLightBlacklistAllFiles, MVideoThumbnail } from '@server/types/models'
7import { HttpStatusCode } from '@shared/core-utils' 7import { HttpStatusCode } from '@shared/core-utils'
diff --git a/server/lib/job-queue/handlers/activitypub-follow.ts b/server/lib/job-queue/handlers/activitypub-follow.ts
index 76b6fcaae..f896d7af4 100644
--- a/server/lib/job-queue/handlers/activitypub-follow.ts
+++ b/server/lib/job-queue/handlers/activitypub-follow.ts
@@ -4,13 +4,12 @@ import { ActivitypubFollowPayload } from '@shared/models'
4import { sanitizeHost } from '../../../helpers/core-utils' 4import { sanitizeHost } from '../../../helpers/core-utils'
5import { retryTransactionWrapper } from '../../../helpers/database-utils' 5import { retryTransactionWrapper } from '../../../helpers/database-utils'
6import { logger } from '../../../helpers/logger' 6import { logger } from '../../../helpers/logger'
7import { loadActorUrlOrGetFromWebfinger } from '../../../helpers/webfinger'
8import { REMOTE_SCHEME, WEBSERVER } from '../../../initializers/constants' 7import { REMOTE_SCHEME, WEBSERVER } from '../../../initializers/constants'
9import { sequelizeTypescript } from '../../../initializers/database' 8import { sequelizeTypescript } from '../../../initializers/database'
10import { ActorModel } from '../../../models/actor/actor' 9import { ActorModel } from '../../../models/actor/actor'
11import { ActorFollowModel } from '../../../models/actor/actor-follow' 10import { ActorFollowModel } from '../../../models/actor/actor-follow'
12import { MActor, MActorFollowActors, MActorFull } from '../../../types/models' 11import { MActor, MActorFollowActors, MActorFull } from '../../../types/models'
13import { getOrCreateAPActor } from '../../activitypub/actors' 12import { getOrCreateAPActor, loadActorUrlOrGetFromWebfinger } from '../../activitypub/actors'
14import { sendFollow } from '../../activitypub/send' 13import { sendFollow } from '../../activitypub/send'
15import { Notifier } from '../../notifier' 14import { Notifier } from '../../notifier'
16 15
diff --git a/server/lib/job-queue/handlers/activitypub-refresher.ts b/server/lib/job-queue/handlers/activitypub-refresher.ts
index 29483f310..2508a4793 100644
--- a/server/lib/job-queue/handlers/activitypub-refresher.ts
+++ b/server/lib/job-queue/handlers/activitypub-refresher.ts
@@ -1,9 +1,9 @@
1import * as Bull from 'bull' 1import * as Bull from 'bull'
2import { refreshVideoPlaylistIfNeeded } from '@server/lib/activitypub/playlists' 2import { refreshVideoPlaylistIfNeeded } from '@server/lib/activitypub/playlists'
3import { refreshVideoIfNeeded } from '@server/lib/activitypub/videos' 3import { refreshVideoIfNeeded } from '@server/lib/activitypub/videos'
4import { fetchVideoByUrl } from '@server/lib/model-loaders'
4import { RefreshPayload } from '@shared/models' 5import { RefreshPayload } from '@shared/models'
5import { logger } from '../../../helpers/logger' 6import { logger } from '../../../helpers/logger'
6import { fetchVideoByUrl } from '../../../helpers/video'
7import { ActorModel } from '../../../models/actor/actor' 7import { ActorModel } from '../../../models/actor/actor'
8import { VideoPlaylistModel } from '../../../models/video/video-playlist' 8import { VideoPlaylistModel } from '../../../models/video/video-playlist'
9import { refreshActorIfNeeded } from '../../activitypub/actors' 9import { refreshActorIfNeeded } from '../../activitypub/actors'
diff --git a/server/helpers/actor.ts b/server/lib/model-loaders/actor.ts
index 5f742505b..234cb344f 100644
--- a/server/helpers/actor.ts
+++ b/server/lib/model-loaders/actor.ts
@@ -1,6 +1,6 @@
1 1
2import { ActorModel } from '../models/actor/actor' 2import { ActorModel } from '../../models/actor/actor'
3import { MActorAccountChannelId, MActorFull } from '../types/models' 3import { MActorAccountChannelId, MActorFull } from '../../types/models'
4 4
5type ActorFetchByUrlType = 'all' | 'association-ids' 5type ActorFetchByUrlType = 'all' | 'association-ids'
6 6
diff --git a/server/lib/model-loaders/index.ts b/server/lib/model-loaders/index.ts
new file mode 100644
index 000000000..9e5152cb2
--- /dev/null
+++ b/server/lib/model-loaders/index.ts
@@ -0,0 +1,2 @@
1export * from './actor'
2export * from './video'
diff --git a/server/lib/model-loaders/video.ts b/server/lib/model-loaders/video.ts
new file mode 100644
index 000000000..7aaf00e89
--- /dev/null
+++ b/server/lib/model-loaders/video.ts
@@ -0,0 +1,64 @@
1import { VideoModel } from '@server/models/video/video'
2import {
3 MVideoAccountLightBlacklistAllFiles,
4 MVideoFullLight,
5 MVideoIdThumbnail,
6 MVideoImmutable,
7 MVideoThumbnail,
8 MVideoWithRights
9} from '@server/types/models'
10
11type VideoFetchType = 'all' | 'only-video' | 'only-video-with-rights' | 'id' | 'none' | 'only-immutable-attributes'
12
13function fetchVideo (id: number | string, fetchType: 'all', userId?: number): Promise<MVideoFullLight>
14function fetchVideo (id: number | string, fetchType: 'only-immutable-attributes'): Promise<MVideoImmutable>
15function fetchVideo (id: number | string, fetchType: 'only-video', userId?: number): Promise<MVideoThumbnail>
16function fetchVideo (id: number | string, fetchType: 'only-video-with-rights', userId?: number): Promise<MVideoWithRights>
17function fetchVideo (id: number | string, fetchType: 'id' | 'none', userId?: number): Promise<MVideoIdThumbnail>
18function fetchVideo (
19 id: number | string,
20 fetchType: VideoFetchType,
21 userId?: number
22): Promise<MVideoFullLight | MVideoThumbnail | MVideoWithRights | MVideoIdThumbnail | MVideoImmutable>
23function fetchVideo (
24 id: number | string,
25 fetchType: VideoFetchType,
26 userId?: number
27): Promise<MVideoFullLight | MVideoThumbnail | MVideoWithRights | MVideoIdThumbnail | MVideoImmutable> {
28 if (fetchType === 'all') return VideoModel.loadAndPopulateAccountAndServerAndTags(id, undefined, userId)
29
30 if (fetchType === 'only-immutable-attributes') return VideoModel.loadImmutableAttributes(id)
31
32 if (fetchType === 'only-video-with-rights') return VideoModel.loadWithRights(id)
33
34 if (fetchType === 'only-video') return VideoModel.load(id)
35
36 if (fetchType === 'id' || fetchType === 'none') return VideoModel.loadOnlyId(id)
37}
38
39type VideoFetchByUrlType = 'all' | 'only-video' | 'only-immutable-attributes'
40
41function fetchVideoByUrl (url: string, fetchType: 'all'): Promise<MVideoAccountLightBlacklistAllFiles>
42function fetchVideoByUrl (url: string, fetchType: 'only-immutable-attributes'): Promise<MVideoImmutable>
43function fetchVideoByUrl (url: string, fetchType: 'only-video'): Promise<MVideoThumbnail>
44function fetchVideoByUrl (
45 url: string,
46 fetchType: VideoFetchByUrlType
47): Promise<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable>
48function fetchVideoByUrl (
49 url: string,
50 fetchType: VideoFetchByUrlType
51): Promise<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable> {
52 if (fetchType === 'all') return VideoModel.loadByUrlAndPopulateAccount(url)
53
54 if (fetchType === 'only-immutable-attributes') return VideoModel.loadByUrlImmutableAttributes(url)
55
56 if (fetchType === 'only-video') return VideoModel.loadByUrl(url)
57}
58
59export {
60 VideoFetchType,
61 VideoFetchByUrlType,
62 fetchVideo,
63 fetchVideoByUrl
64}
diff --git a/server/lib/server-config-manager.ts b/server/lib/server-config-manager.ts
index 25a770c6b..80d87a9d3 100644
--- a/server/lib/server-config-manager.ts
+++ b/server/lib/server-config-manager.ts
@@ -1,7 +1,7 @@
1import { isSignupAllowed, isSignupAllowedForCurrentIP } from '@server/helpers/signup'
2import { getServerCommit } from '@server/helpers/utils' 1import { getServerCommit } from '@server/helpers/utils'
3import { CONFIG, isEmailEnabled } from '@server/initializers/config' 2import { CONFIG, isEmailEnabled } from '@server/initializers/config'
4import { CONSTRAINTS_FIELDS, DEFAULT_THEME_NAME, PEERTUBE_VERSION } from '@server/initializers/constants' 3import { CONSTRAINTS_FIELDS, DEFAULT_THEME_NAME, PEERTUBE_VERSION } from '@server/initializers/constants'
4import { isSignupAllowed, isSignupAllowedForCurrentIP } from '@server/lib/signup'
5import { ActorCustomPageModel } from '@server/models/account/actor-custom-page' 5import { ActorCustomPageModel } from '@server/models/account/actor-custom-page'
6import { HTMLServerConfig, RegisteredExternalAuthConfig, RegisteredIdAndPassAuthConfig, ServerConfig } from '@shared/models' 6import { HTMLServerConfig, RegisteredExternalAuthConfig, RegisteredIdAndPassAuthConfig, ServerConfig } from '@shared/models'
7import { Hooks } from './plugins/hooks' 7import { Hooks } from './plugins/hooks'
diff --git a/server/helpers/signup.ts b/server/lib/signup.ts
index 8fa81e601..8fa81e601 100644
--- a/server/helpers/signup.ts
+++ b/server/lib/signup.ts
diff --git a/server/middlewares/activitypub.ts b/server/middlewares/activitypub.ts
index a1fdfafcf..6b43b7764 100644
--- a/server/middlewares/activitypub.ts
+++ b/server/middlewares/activitypub.ts
@@ -1,13 +1,12 @@
1import { NextFunction, Request, Response } from 'express' 1import { NextFunction, Request, Response } from 'express'
2import { getAPId } from '@server/helpers/activitypub'
3import { isActorDeleteActivityValid } from '@server/helpers/custom-validators/activitypub/actor'
2import { ActivityDelete, ActivityPubSignature } from '../../shared' 4import { ActivityDelete, ActivityPubSignature } from '../../shared'
5import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes'
3import { logger } from '../helpers/logger' 6import { logger } from '../helpers/logger'
4import { isHTTPSignatureVerified, isJsonLDSignatureVerified, parseHTTPSignature } from '../helpers/peertube-crypto' 7import { isHTTPSignatureVerified, isJsonLDSignatureVerified, parseHTTPSignature } from '../helpers/peertube-crypto'
5import { ACCEPT_HEADERS, ACTIVITY_PUB, HTTP_SIGNATURE } from '../initializers/constants' 8import { ACCEPT_HEADERS, ACTIVITY_PUB, HTTP_SIGNATURE } from '../initializers/constants'
6import { getOrCreateAPActor } from '../lib/activitypub/actors' 9import { getOrCreateAPActor, loadActorUrlOrGetFromWebfinger } from '../lib/activitypub/actors'
7import { loadActorUrlOrGetFromWebfinger } from '../helpers/webfinger'
8import { isActorDeleteActivityValid } from '@server/helpers/custom-validators/activitypub/actor'
9import { getAPId } from '@server/helpers/activitypub'
10import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes'
11 10
12async function checkSignature (req: Request, res: Response, next: NextFunction) { 11async function checkSignature (req: Request, res: Response, next: NextFunction) {
13 try { 12 try {
diff --git a/server/middlewares/validators/abuse.ts b/server/middlewares/validators/abuse.ts
index 7f002e0d5..56c97747c 100644
--- a/server/middlewares/validators/abuse.ts
+++ b/server/middlewares/validators/abuse.ts
@@ -13,13 +13,11 @@ import {
13 isAbuseVideoIsValid 13 isAbuseVideoIsValid
14} from '@server/helpers/custom-validators/abuses' 14} from '@server/helpers/custom-validators/abuses'
15import { exists, isIdOrUUIDValid, isIdValid, toIntOrNull } from '@server/helpers/custom-validators/misc' 15import { exists, isIdOrUUIDValid, isIdValid, toIntOrNull } from '@server/helpers/custom-validators/misc'
16import { doesCommentIdExist } from '@server/helpers/custom-validators/video-comments'
17import { logger } from '@server/helpers/logger' 16import { logger } from '@server/helpers/logger'
18import { doesAbuseExist, doesAccountIdExist, doesVideoExist } from '@server/helpers/middlewares'
19import { AbuseMessageModel } from '@server/models/abuse/abuse-message' 17import { AbuseMessageModel } from '@server/models/abuse/abuse-message'
20import { AbuseCreate, UserRight } from '@shared/models' 18import { AbuseCreate, UserRight } from '@shared/models'
21import { areValidationErrors } from './utils'
22import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' 19import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
20import { areValidationErrors, doesAbuseExist, doesAccountIdExist, doesCommentIdExist, doesVideoExist } from './shared'
23 21
24const abuseReportValidator = [ 22const abuseReportValidator = [
25 body('account.id') 23 body('account.id')
diff --git a/server/middlewares/validators/account.ts b/server/middlewares/validators/account.ts
index cbdcef2fd..599eb10bb 100644
--- a/server/middlewares/validators/account.ts
+++ b/server/middlewares/validators/account.ts
@@ -2,8 +2,7 @@ import * as express from 'express'
2import { param } from 'express-validator' 2import { param } from 'express-validator'
3import { isAccountNameValid } from '../../helpers/custom-validators/accounts' 3import { isAccountNameValid } from '../../helpers/custom-validators/accounts'
4import { logger } from '../../helpers/logger' 4import { logger } from '../../helpers/logger'
5import { areValidationErrors } from './utils' 5import { areValidationErrors, doesAccountNameWithHostExist, doesLocalAccountNameExist } from './shared'
6import { doesAccountNameWithHostExist, doesLocalAccountNameExist } from '../../helpers/middlewares'
7 6
8const localAccountValidator = [ 7const localAccountValidator = [
9 param('name').custom(isAccountNameValid).withMessage('Should have a valid account name'), 8 param('name').custom(isAccountNameValid).withMessage('Should have a valid account name'),
diff --git a/server/middlewares/validators/activitypub/pagination.ts b/server/middlewares/validators/activitypub/pagination.ts
index fa21f063d..c8ec34eb6 100644
--- a/server/middlewares/validators/activitypub/pagination.ts
+++ b/server/middlewares/validators/activitypub/pagination.ts
@@ -1,8 +1,8 @@
1import * as express from 'express' 1import * as express from 'express'
2import { query } from 'express-validator' 2import { query } from 'express-validator'
3import { logger } from '../../../helpers/logger'
4import { areValidationErrors } from '../utils'
5import { PAGINATION } from '@server/initializers/constants' 3import { PAGINATION } from '@server/initializers/constants'
4import { logger } from '../../../helpers/logger'
5import { areValidationErrors } from '../shared'
6 6
7const apPaginationValidator = [ 7const apPaginationValidator = [
8 query('page') 8 query('page')
diff --git a/server/middlewares/validators/activitypub/signature.ts b/server/middlewares/validators/activitypub/signature.ts
index 7896a6128..f2f7d5848 100644
--- a/server/middlewares/validators/activitypub/signature.ts
+++ b/server/middlewares/validators/activitypub/signature.ts
@@ -1,12 +1,13 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body } from 'express-validator' 2import { body } from 'express-validator'
3import { 3import {
4 isSignatureCreatorValid, isSignatureTypeValid, 4 isSignatureCreatorValid,
5 isSignatureTypeValid,
5 isSignatureValueValid 6 isSignatureValueValid
6} from '../../../helpers/custom-validators/activitypub/signature' 7} from '../../../helpers/custom-validators/activitypub/signature'
7import { isDateValid } from '../../../helpers/custom-validators/misc' 8import { isDateValid } from '../../../helpers/custom-validators/misc'
8import { logger } from '../../../helpers/logger' 9import { logger } from '../../../helpers/logger'
9import { areValidationErrors } from '../utils' 10import { areValidationErrors } from '../shared'
10 11
11const signatureValidator = [ 12const signatureValidator = [
12 body('signature.type') 13 body('signature.type')
diff --git a/server/middlewares/validators/actor-image.ts b/server/middlewares/validators/actor-image.ts
index 961d7a7e5..49daadd61 100644
--- a/server/middlewares/validators/actor-image.ts
+++ b/server/middlewares/validators/actor-image.ts
@@ -4,7 +4,7 @@ import { isActorImageFile } from '@server/helpers/custom-validators/actor-images
4import { cleanUpReqFiles } from '../../helpers/express-utils' 4import { cleanUpReqFiles } from '../../helpers/express-utils'
5import { logger } from '../../helpers/logger' 5import { logger } from '../../helpers/logger'
6import { CONSTRAINTS_FIELDS } from '../../initializers/constants' 6import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
7import { areValidationErrors } from './utils' 7import { areValidationErrors } from './shared'
8 8
9const updateActorImageValidatorFactory = (fieldname: string) => ([ 9const updateActorImageValidatorFactory = (fieldname: string) => ([
10 body(fieldname).custom((value, { req }) => isActorImageFile(req.files, fieldname)).withMessage( 10 body(fieldname).custom((value, { req }) => isActorImageFile(req.files, fieldname)).withMessage(
diff --git a/server/middlewares/validators/blocklist.ts b/server/middlewares/validators/blocklist.ts
index 125ff882c..826b16fc8 100644
--- a/server/middlewares/validators/blocklist.ts
+++ b/server/middlewares/validators/blocklist.ts
@@ -1,15 +1,14 @@
1import { body, param } from 'express-validator'
2import * as express from 'express' 1import * as express from 'express'
2import { body, param } from 'express-validator'
3import { getServerActor } from '@server/models/application/application'
4import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
5import { isHostValid } from '../../helpers/custom-validators/servers'
3import { logger } from '../../helpers/logger' 6import { logger } from '../../helpers/logger'
4import { areValidationErrors } from './utils' 7import { WEBSERVER } from '../../initializers/constants'
5import { AccountBlocklistModel } from '../../models/account/account-blocklist' 8import { AccountBlocklistModel } from '../../models/account/account-blocklist'
6import { isHostValid } from '../../helpers/custom-validators/servers'
7import { ServerBlocklistModel } from '../../models/server/server-blocklist'
8import { ServerModel } from '../../models/server/server' 9import { ServerModel } from '../../models/server/server'
9import { WEBSERVER } from '../../initializers/constants' 10import { ServerBlocklistModel } from '../../models/server/server-blocklist'
10import { doesAccountNameWithHostExist } from '../../helpers/middlewares' 11import { areValidationErrors, doesAccountNameWithHostExist } from './shared'
11import { getServerActor } from '@server/models/application/application'
12import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
13 12
14const blockAccountValidator = [ 13const blockAccountValidator = [
15 body('accountName').exists().withMessage('Should have an account name with host'), 14 body('accountName').exists().withMessage('Should have an account name with host'),
diff --git a/server/middlewares/validators/bulk.ts b/server/middlewares/validators/bulk.ts
index 847885101..9bb95f5b7 100644
--- a/server/middlewares/validators/bulk.ts
+++ b/server/middlewares/validators/bulk.ts
@@ -1,12 +1,11 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body } from 'express-validator' 2import { body } from 'express-validator'
3import { isBulkRemoveCommentsOfScopeValid } from '@server/helpers/custom-validators/bulk' 3import { isBulkRemoveCommentsOfScopeValid } from '@server/helpers/custom-validators/bulk'
4import { doesAccountNameWithHostExist } from '@server/helpers/middlewares' 4import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
5import { UserRight } from '@shared/models' 5import { UserRight } from '@shared/models'
6import { BulkRemoveCommentsOfBody } from '@shared/models/bulk/bulk-remove-comments-of-body.model' 6import { BulkRemoveCommentsOfBody } from '@shared/models/bulk/bulk-remove-comments-of-body.model'
7import { logger } from '../../helpers/logger' 7import { logger } from '../../helpers/logger'
8import { areValidationErrors } from './utils' 8import { areValidationErrors, doesAccountNameWithHostExist } from './shared'
9import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
10 9
11const bulkRemoveCommentsOfValidator = [ 10const bulkRemoveCommentsOfValidator = [
12 body('accountName').exists().withMessage('Should have an account name with host'), 11 body('accountName').exists().withMessage('Should have an account name with host'),
diff --git a/server/middlewares/validators/config.ts b/server/middlewares/validators/config.ts
index b5d6b4622..1aeadbe65 100644
--- a/server/middlewares/validators/config.ts
+++ b/server/middlewares/validators/config.ts
@@ -7,7 +7,7 @@ import { isThemeNameValid } from '../../helpers/custom-validators/plugins'
7import { isUserNSFWPolicyValid, isUserVideoQuotaDailyValid, isUserVideoQuotaValid } from '../../helpers/custom-validators/users' 7import { isUserNSFWPolicyValid, isUserVideoQuotaDailyValid, isUserVideoQuotaValid } from '../../helpers/custom-validators/users'
8import { logger } from '../../helpers/logger' 8import { logger } from '../../helpers/logger'
9import { isThemeRegistered } from '../../lib/plugins/theme-utils' 9import { isThemeRegistered } from '../../lib/plugins/theme-utils'
10import { areValidationErrors } from './utils' 10import { areValidationErrors } from './shared'
11 11
12const customConfigUpdateValidator = [ 12const customConfigUpdateValidator = [
13 body('instance.name').exists().withMessage('Should have a valid instance name'), 13 body('instance.name').exists().withMessage('Should have a valid instance name'),
diff --git a/server/middlewares/validators/feeds.ts b/server/middlewares/validators/feeds.ts
index aa16cc993..51e6d6fff 100644
--- a/server/middlewares/validators/feeds.ts
+++ b/server/middlewares/validators/feeds.ts
@@ -1,18 +1,18 @@
1import * as express from 'express' 1import * as express from 'express'
2import { param, query } from 'express-validator' 2import { param, query } from 'express-validator'
3import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
3import { isValidRSSFeed } from '../../helpers/custom-validators/feeds' 4import { isValidRSSFeed } from '../../helpers/custom-validators/feeds'
4import { exists, isIdOrUUIDValid, isIdValid } from '../../helpers/custom-validators/misc' 5import { exists, isIdOrUUIDValid, isIdValid } from '../../helpers/custom-validators/misc'
5import { logger } from '../../helpers/logger' 6import { logger } from '../../helpers/logger'
6import { 7import {
8 areValidationErrors,
7 doesAccountIdExist, 9 doesAccountIdExist,
8 doesAccountNameWithHostExist, 10 doesAccountNameWithHostExist,
9 doesUserFeedTokenCorrespond, 11 doesUserFeedTokenCorrespond,
10 doesVideoChannelIdExist, 12 doesVideoChannelIdExist,
11 doesVideoChannelNameWithHostExist 13 doesVideoChannelNameWithHostExist,
12} from '../../helpers/middlewares' 14 doesVideoExist
13import { doesVideoExist } from '../../helpers/middlewares/videos' 15} from './shared'
14import { areValidationErrors } from './utils'
15import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
16 16
17const feedsFormatValidator = [ 17const feedsFormatValidator = [
18 param('format').optional().custom(isValidRSSFeed).withMessage('Should have a valid format (rss, atom, json)'), 18 param('format').optional().custom(isValidRSSFeed).withMessage('Should have a valid format (rss, atom, json)'),
diff --git a/server/middlewares/validators/follows.ts b/server/middlewares/validators/follows.ts
index 733be379b..205baca48 100644
--- a/server/middlewares/validators/follows.ts
+++ b/server/middlewares/validators/follows.ts
@@ -1,6 +1,7 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body, param, query } from 'express-validator' 2import { body, param, query } from 'express-validator'
3import { isFollowStateValid } from '@server/helpers/custom-validators/follows' 3import { isFollowStateValid } from '@server/helpers/custom-validators/follows'
4import { loadActorUrlOrGetFromWebfinger } from '@server/lib/activitypub/actors'
4import { getServerActor } from '@server/models/application/application' 5import { getServerActor } from '@server/models/application/application'
5import { MActorFollowActorsDefault } from '@server/types/models' 6import { MActorFollowActorsDefault } from '@server/types/models'
6import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' 7import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
@@ -8,11 +9,10 @@ import { isTestInstance } from '../../helpers/core-utils'
8import { isActorTypeValid, isValidActorHandle } from '../../helpers/custom-validators/activitypub/actor' 9import { isActorTypeValid, isValidActorHandle } from '../../helpers/custom-validators/activitypub/actor'
9import { isEachUniqueHostValid, isHostValid } from '../../helpers/custom-validators/servers' 10import { isEachUniqueHostValid, isHostValid } from '../../helpers/custom-validators/servers'
10import { logger } from '../../helpers/logger' 11import { logger } from '../../helpers/logger'
11import { loadActorUrlOrGetFromWebfinger } from '../../helpers/webfinger'
12import { SERVER_ACTOR_NAME, WEBSERVER } from '../../initializers/constants' 12import { SERVER_ACTOR_NAME, WEBSERVER } from '../../initializers/constants'
13import { ActorModel } from '../../models/actor/actor' 13import { ActorModel } from '../../models/actor/actor'
14import { ActorFollowModel } from '../../models/actor/actor-follow' 14import { ActorFollowModel } from '../../models/actor/actor-follow'
15import { areValidationErrors } from './utils' 15import { areValidationErrors } from './shared'
16 16
17const listFollowsValidator = [ 17const listFollowsValidator = [
18 query('state') 18 query('state')
diff --git a/server/middlewares/validators/jobs.ts b/server/middlewares/validators/jobs.ts
index d87b28c06..5d89d167f 100644
--- a/server/middlewares/validators/jobs.ts
+++ b/server/middlewares/validators/jobs.ts
@@ -2,7 +2,7 @@ import * as express from 'express'
2import { param, query } from 'express-validator' 2import { param, query } from 'express-validator'
3import { isValidJobState, isValidJobType } from '../../helpers/custom-validators/jobs' 3import { isValidJobState, isValidJobType } from '../../helpers/custom-validators/jobs'
4import { logger, loggerTagsFactory } from '../../helpers/logger' 4import { logger, loggerTagsFactory } from '../../helpers/logger'
5import { areValidationErrors } from './utils' 5import { areValidationErrors } from './shared'
6 6
7const lTags = loggerTagsFactory('validators', 'jobs') 7const lTags = loggerTagsFactory('validators', 'jobs')
8 8
diff --git a/server/middlewares/validators/logs.ts b/server/middlewares/validators/logs.ts
index ba817d9a9..c55baaee3 100644
--- a/server/middlewares/validators/logs.ts
+++ b/server/middlewares/validators/logs.ts
@@ -1,9 +1,9 @@
1import * as express from 'express' 1import * as express from 'express'
2import { logger } from '../../helpers/logger'
3import { areValidationErrors } from './utils'
4import { isDateValid } from '../../helpers/custom-validators/misc'
5import { query } from 'express-validator' 2import { query } from 'express-validator'
6import { isValidLogLevel } from '../../helpers/custom-validators/logs' 3import { isValidLogLevel } from '../../helpers/custom-validators/logs'
4import { isDateValid } from '../../helpers/custom-validators/misc'
5import { logger } from '../../helpers/logger'
6import { areValidationErrors } from './shared'
7 7
8const getLogsValidator = [ 8const getLogsValidator = [
9 query('startDate') 9 query('startDate')
diff --git a/server/middlewares/validators/oembed.ts b/server/middlewares/validators/oembed.ts
index b1d763fbe..ab117635e 100644
--- a/server/middlewares/validators/oembed.ts
+++ b/server/middlewares/validators/oembed.ts
@@ -1,7 +1,7 @@
1import * as express from 'express' 1import * as express from 'express'
2import { query } from 'express-validator' 2import { query } from 'express-validator'
3import { join } from 'path' 3import { join } from 'path'
4import { fetchVideo } from '@server/helpers/video' 4import { fetchVideo } from '@server/lib/model-loaders'
5import { VideoPlaylistModel } from '@server/models/video/video-playlist' 5import { VideoPlaylistModel } from '@server/models/video/video-playlist'
6import { VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models' 6import { VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'
7import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' 7import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
@@ -9,7 +9,7 @@ import { isTestInstance } from '../../helpers/core-utils'
9import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' 9import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc'
10import { logger } from '../../helpers/logger' 10import { logger } from '../../helpers/logger'
11import { WEBSERVER } from '../../initializers/constants' 11import { WEBSERVER } from '../../initializers/constants'
12import { areValidationErrors } from './utils' 12import { areValidationErrors } from './shared'
13 13
14const playlistPaths = [ 14const playlistPaths = [
15 join('videos', 'watch', 'playlist'), 15 join('videos', 'watch', 'playlist'),
diff --git a/server/middlewares/validators/pagination.ts b/server/middlewares/validators/pagination.ts
index 6b0a83d80..74eae251e 100644
--- a/server/middlewares/validators/pagination.ts
+++ b/server/middlewares/validators/pagination.ts
@@ -1,8 +1,8 @@
1import * as express from 'express' 1import * as express from 'express'
2import { query } from 'express-validator' 2import { query } from 'express-validator'
3import { logger } from '../../helpers/logger'
4import { areValidationErrors } from './utils'
5import { PAGINATION } from '@server/initializers/constants' 3import { PAGINATION } from '@server/initializers/constants'
4import { logger } from '../../helpers/logger'
5import { areValidationErrors } from './shared'
6 6
7const paginationValidator = paginationValidatorBuilder() 7const paginationValidator = paginationValidatorBuilder()
8 8
diff --git a/server/middlewares/validators/plugins.ts b/server/middlewares/validators/plugins.ts
index 5934a28bc..8c76d2e36 100644
--- a/server/middlewares/validators/plugins.ts
+++ b/server/middlewares/validators/plugins.ts
@@ -9,7 +9,7 @@ import { logger } from '../../helpers/logger'
9import { CONFIG } from '../../initializers/config' 9import { CONFIG } from '../../initializers/config'
10import { PluginManager } from '../../lib/plugins/plugin-manager' 10import { PluginManager } from '../../lib/plugins/plugin-manager'
11import { PluginModel } from '../../models/server/plugin' 11import { PluginModel } from '../../models/server/plugin'
12import { areValidationErrors } from './utils' 12import { areValidationErrors } from './shared'
13 13
14const getPluginValidator = (pluginType: PluginType, withVersion = true) => { 14const getPluginValidator = (pluginType: PluginType, withVersion = true) => {
15 const validators: (ValidationChain | express.Handler)[] = [ 15 const validators: (ValidationChain | express.Handler)[] = [
diff --git a/server/middlewares/validators/redundancy.ts b/server/middlewares/validators/redundancy.ts
index 3d557048a..da24f4c9b 100644
--- a/server/middlewares/validators/redundancy.ts
+++ b/server/middlewares/validators/redundancy.ts
@@ -1,14 +1,13 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body, param, query } from 'express-validator' 2import { body, param, query } from 'express-validator'
3import { isVideoRedundancyTarget } from '@server/helpers/custom-validators/video-redundancies'
4import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
3import { exists, isBooleanValid, isIdOrUUIDValid, isIdValid, toBooleanOrNull, toIntOrNull } from '../../helpers/custom-validators/misc' 5import { exists, isBooleanValid, isIdOrUUIDValid, isIdValid, toBooleanOrNull, toIntOrNull } from '../../helpers/custom-validators/misc'
6import { isHostValid } from '../../helpers/custom-validators/servers'
4import { logger } from '../../helpers/logger' 7import { logger } from '../../helpers/logger'
5import { areValidationErrors } from './utils'
6import { VideoRedundancyModel } from '../../models/redundancy/video-redundancy' 8import { VideoRedundancyModel } from '../../models/redundancy/video-redundancy'
7import { isHostValid } from '../../helpers/custom-validators/servers'
8import { ServerModel } from '../../models/server/server' 9import { ServerModel } from '../../models/server/server'
9import { doesVideoExist } from '../../helpers/middlewares' 10import { areValidationErrors, doesVideoExist } from './shared'
10import { isVideoRedundancyTarget } from '@server/helpers/custom-validators/video-redundancies'
11import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
12 11
13const videoFileRedundancyGetValidator = [ 12const videoFileRedundancyGetValidator = [
14 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid video id'), 13 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid video id'),
diff --git a/server/middlewares/validators/search.ts b/server/middlewares/validators/search.ts
index d2f527750..e2e1c6aae 100644
--- a/server/middlewares/validators/search.ts
+++ b/server/middlewares/validators/search.ts
@@ -1,9 +1,9 @@
1import * as express from 'express' 1import * as express from 'express'
2import { areValidationErrors } from './utils'
3import { logger } from '../../helpers/logger'
4import { query } from 'express-validator' 2import { query } from 'express-validator'
5import { isDateValid } from '../../helpers/custom-validators/misc'
6import { isSearchTargetValid } from '@server/helpers/custom-validators/search' 3import { isSearchTargetValid } from '@server/helpers/custom-validators/search'
4import { isDateValid } from '../../helpers/custom-validators/misc'
5import { logger } from '../../helpers/logger'
6import { areValidationErrors } from './shared'
7 7
8const videosSearchValidator = [ 8const videosSearchValidator = [
9 query('search').optional().not().isEmpty().withMessage('Should have a valid search'), 9 query('search').optional().not().isEmpty().withMessage('Should have a valid search'),
diff --git a/server/middlewares/validators/server.ts b/server/middlewares/validators/server.ts
index 2b34c4a76..fc7239b25 100644
--- a/server/middlewares/validators/server.ts
+++ b/server/middlewares/validators/server.ts
@@ -1,13 +1,13 @@
1import * as express from 'express' 1import * as express from 'express'
2import { logger } from '../../helpers/logger'
3import { areValidationErrors } from './utils'
4import { isHostValid, isValidContactBody } from '../../helpers/custom-validators/servers'
5import { ServerModel } from '../../models/server/server'
6import { body } from 'express-validator' 2import { body } from 'express-validator'
3import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
4import { isHostValid, isValidContactBody } from '../../helpers/custom-validators/servers'
7import { isUserDisplayNameValid } from '../../helpers/custom-validators/users' 5import { isUserDisplayNameValid } from '../../helpers/custom-validators/users'
8import { Redis } from '../../lib/redis' 6import { logger } from '../../helpers/logger'
9import { CONFIG, isEmailEnabled } from '../../initializers/config' 7import { CONFIG, isEmailEnabled } from '../../initializers/config'
10import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' 8import { Redis } from '../../lib/redis'
9import { ServerModel } from '../../models/server/server'
10import { areValidationErrors } from './shared'
11 11
12const serverGetValidator = [ 12const serverGetValidator = [
13 body('host').custom(isHostValid).withMessage('Should have a valid host'), 13 body('host').custom(isHostValid).withMessage('Should have a valid host'),
diff --git a/server/helpers/middlewares/abuses.ts b/server/middlewares/validators/shared/abuses.ts
index f0b1caba8..4a20a55fa 100644
--- a/server/helpers/middlewares/abuses.ts
+++ b/server/middlewares/validators/shared/abuses.ts
@@ -1,6 +1,6 @@
1import { Response } from 'express' 1import { Response } from 'express'
2import { AbuseModel } from '../../models/abuse/abuse' 2import { AbuseModel } from '@server/models/abuse/abuse'
3import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' 3import { HttpStatusCode } from '@shared/core-utils'
4 4
5async function doesAbuseExist (abuseId: number | string, res: Response) { 5async function doesAbuseExist (abuseId: number | string, res: Response) {
6 const abuse = await AbuseModel.loadByIdWithReporter(parseInt(abuseId + '', 10)) 6 const abuse = await AbuseModel.loadByIdWithReporter(parseInt(abuseId + '', 10))
diff --git a/server/helpers/middlewares/accounts.ts b/server/middlewares/validators/shared/accounts.ts
index 7db79bc48..04da15441 100644
--- a/server/helpers/middlewares/accounts.ts
+++ b/server/middlewares/validators/shared/accounts.ts
@@ -1,8 +1,8 @@
1import { Response } from 'express' 1import { Response } from 'express'
2import { AccountModel } from '@server/models/account/account'
2import { UserModel } from '@server/models/user/user' 3import { UserModel } from '@server/models/user/user'
3import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' 4import { MAccountDefault } from '@server/types/models'
4import { AccountModel } from '../../models/account/account' 5import { HttpStatusCode } from '@shared/core-utils'
5import { MAccountDefault } from '../../types/models'
6 6
7function doesAccountIdExist (id: number | string, res: Response, sendNotFound = true) { 7function doesAccountIdExist (id: number | string, res: Response, sendNotFound = true) {
8 const promise = AccountModel.load(parseInt(id + '', 10)) 8 const promise = AccountModel.load(parseInt(id + '', 10))
diff --git a/server/helpers/middlewares/index.ts b/server/middlewares/validators/shared/index.ts
index f57f3ad31..fa89d05f2 100644
--- a/server/helpers/middlewares/index.ts
+++ b/server/middlewares/validators/shared/index.ts
@@ -1,7 +1,11 @@
1export * from './abuses' 1export * from './abuses'
2export * from './accounts' 2export * from './accounts'
3export * from './utils'
3export * from './video-blacklists' 4export * from './video-blacklists'
4export * from './video-captions' 5export * from './video-captions'
5export * from './video-channels' 6export * from './video-channels'
7export * from './video-comments'
8export * from './video-imports'
9export * from './video-ownerships'
6export * from './video-playlists' 10export * from './video-playlists'
7export * from './videos' 11export * from './videos'
diff --git a/server/middlewares/validators/utils.ts b/server/middlewares/validators/shared/utils.ts
index e291f1b17..d3e4870a9 100644
--- a/server/middlewares/validators/utils.ts
+++ b/server/middlewares/validators/shared/utils.ts
@@ -1,6 +1,6 @@
1import * as express from 'express' 1import * as express from 'express'
2import { query, validationResult } from 'express-validator' 2import { query, validationResult } from 'express-validator'
3import { logger } from '../../helpers/logger' 3import { logger } from '../../../helpers/logger'
4 4
5function areValidationErrors (req: express.Request, res: express.Response) { 5function areValidationErrors (req: express.Request, res: express.Response) {
6 const errors = validationResult(req) 6 const errors = validationResult(req)
diff --git a/server/helpers/middlewares/video-blacklists.ts b/server/middlewares/validators/shared/video-blacklists.ts
index 3494fd6b0..01491c10f 100644
--- a/server/helpers/middlewares/video-blacklists.ts
+++ b/server/middlewares/validators/shared/video-blacklists.ts
@@ -1,6 +1,6 @@
1import { Response } from 'express' 1import { Response } from 'express'
2import { VideoBlacklistModel } from '../../models/video/video-blacklist' 2import { VideoBlacklistModel } from '@server/models/video/video-blacklist'
3import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' 3import { HttpStatusCode } from '@shared/core-utils'
4 4
5async function doesVideoBlacklistExist (videoId: number, res: Response) { 5async function doesVideoBlacklistExist (videoId: number, res: Response) {
6 const videoBlacklist = await VideoBlacklistModel.loadByVideoId(videoId) 6 const videoBlacklist = await VideoBlacklistModel.loadByVideoId(videoId)
diff --git a/server/helpers/middlewares/video-captions.ts b/server/middlewares/validators/shared/video-captions.ts
index 2a12c4813..80f6c5a52 100644
--- a/server/helpers/middlewares/video-captions.ts
+++ b/server/middlewares/validators/shared/video-captions.ts
@@ -1,7 +1,7 @@
1import { Response } from 'express' 1import { Response } from 'express'
2import { VideoCaptionModel } from '../../models/video/video-caption' 2import { VideoCaptionModel } from '@server/models/video/video-caption'
3import { MVideoId } from '@server/types/models' 3import { MVideoId } from '@server/types/models'
4import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' 4import { HttpStatusCode } from '@shared/core-utils'
5 5
6async function doesVideoCaptionExist (video: MVideoId, language: string, res: Response) { 6async function doesVideoCaptionExist (video: MVideoId, language: string, res: Response) {
7 const videoCaption = await VideoCaptionModel.loadByVideoIdAndLanguage(video.id, language) 7 const videoCaption = await VideoCaptionModel.loadByVideoIdAndLanguage(video.id, language)
diff --git a/server/helpers/middlewares/video-channels.ts b/server/middlewares/validators/shared/video-channels.ts
index f5ed5ef0f..fe2e663b7 100644
--- a/server/helpers/middlewares/video-channels.ts
+++ b/server/middlewares/validators/shared/video-channels.ts
@@ -1,7 +1,7 @@
1import * as express from 'express' 1import * as express from 'express'
2import { VideoChannelModel } from '@server/models/video/video-channel'
2import { MChannelBannerAccountDefault } from '@server/types/models' 3import { MChannelBannerAccountDefault } from '@server/types/models'
3import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' 4import { HttpStatusCode } from '@shared/core-utils'
4import { VideoChannelModel } from '../../models/video/video-channel'
5 5
6async function doesLocalVideoChannelNameExist (name: string, res: express.Response) { 6async function doesLocalVideoChannelNameExist (name: string, res: express.Response) {
7 const videoChannel = await VideoChannelModel.loadLocalByNameAndPopulateAccount(name) 7 const videoChannel = await VideoChannelModel.loadLocalByNameAndPopulateAccount(name)
diff --git a/server/middlewares/validators/shared/video-comments.ts b/server/middlewares/validators/shared/video-comments.ts
new file mode 100644
index 000000000..83ea15c98
--- /dev/null
+++ b/server/middlewares/validators/shared/video-comments.ts
@@ -0,0 +1,73 @@
1import * as express from 'express'
2import { VideoCommentModel } from '@server/models/video/video-comment'
3import { MVideoId } from '@server/types/models'
4import { HttpStatusCode } from '@shared/core-utils'
5
6async function doesVideoCommentThreadExist (idArg: number | string, video: MVideoId, res: express.Response) {
7 const id = parseInt(idArg + '', 10)
8 const videoComment = await VideoCommentModel.loadById(id)
9
10 if (!videoComment) {
11 res.fail({
12 status: HttpStatusCode.NOT_FOUND_404,
13 message: 'Video comment thread not found'
14 })
15 return false
16 }
17
18 if (videoComment.videoId !== video.id) {
19 res.fail({ message: 'Video comment is not associated to this video.' })
20 return false
21 }
22
23 if (videoComment.inReplyToCommentId !== null) {
24 res.fail({ message: 'Video comment is not a thread.' })
25 return false
26 }
27
28 res.locals.videoCommentThread = videoComment
29 return true
30}
31
32async function doesVideoCommentExist (idArg: number | string, video: MVideoId, res: express.Response) {
33 const id = parseInt(idArg + '', 10)
34 const videoComment = await VideoCommentModel.loadByIdAndPopulateVideoAndAccountAndReply(id)
35
36 if (!videoComment) {
37 res.fail({
38 status: HttpStatusCode.NOT_FOUND_404,
39 message: 'Video comment thread not found'
40 })
41 return false
42 }
43
44 if (videoComment.videoId !== video.id) {
45 res.fail({ message: 'Video comment is not associated to this video.' })
46 return false
47 }
48
49 res.locals.videoCommentFull = videoComment
50 return true
51}
52
53async function doesCommentIdExist (idArg: number | string, res: express.Response) {
54 const id = parseInt(idArg + '', 10)
55 const videoComment = await VideoCommentModel.loadByIdAndPopulateVideoAndAccountAndReply(id)
56
57 if (!videoComment) {
58 res.fail({
59 status: HttpStatusCode.NOT_FOUND_404,
60 message: 'Video comment thread not found'
61 })
62 return false
63 }
64
65 res.locals.videoCommentFull = videoComment
66 return true
67}
68
69export {
70 doesVideoCommentThreadExist,
71 doesVideoCommentExist,
72 doesCommentIdExist
73}
diff --git a/server/middlewares/validators/shared/video-imports.ts b/server/middlewares/validators/shared/video-imports.ts
new file mode 100644
index 000000000..0f984bc17
--- /dev/null
+++ b/server/middlewares/validators/shared/video-imports.ts
@@ -0,0 +1,22 @@
1import * as express from 'express'
2import { VideoImportModel } from '@server/models/video/video-import'
3import { HttpStatusCode } from '@shared/core-utils'
4
5async function doesVideoImportExist (id: number, res: express.Response) {
6 const videoImport = await VideoImportModel.loadAndPopulateVideo(id)
7
8 if (!videoImport) {
9 res.fail({
10 status: HttpStatusCode.NOT_FOUND_404,
11 message: 'Video import not found'
12 })
13 return false
14 }
15
16 res.locals.videoImport = videoImport
17 return true
18}
19
20export {
21 doesVideoImportExist
22}
diff --git a/server/middlewares/validators/shared/video-ownerships.ts b/server/middlewares/validators/shared/video-ownerships.ts
new file mode 100644
index 000000000..fc27006ce
--- /dev/null
+++ b/server/middlewares/validators/shared/video-ownerships.ts
@@ -0,0 +1,24 @@
1import * as express from 'express'
2import { VideoChangeOwnershipModel } from '@server/models/video/video-change-ownership'
3import { HttpStatusCode } from '@shared/core-utils'
4
5async function doesChangeVideoOwnershipExist (idArg: number | string, res: express.Response) {
6 const id = parseInt(idArg + '', 10)
7 const videoChangeOwnership = await VideoChangeOwnershipModel.load(id)
8
9 if (!videoChangeOwnership) {
10 res.fail({
11 status: HttpStatusCode.NOT_FOUND_404,
12 message: 'Video change ownership not found'
13 })
14 return false
15 }
16
17 res.locals.videoChangeOwnership = videoChangeOwnership
18
19 return true
20}
21
22export {
23 doesChangeVideoOwnershipExist
24}
diff --git a/server/helpers/middlewares/video-playlists.ts b/server/middlewares/validators/shared/video-playlists.ts
index 3faeab677..d762859a8 100644
--- a/server/helpers/middlewares/video-playlists.ts
+++ b/server/middlewares/validators/shared/video-playlists.ts
@@ -1,7 +1,7 @@
1import * as express from 'express' 1import * as express from 'express'
2import { VideoPlaylistModel } from '../../models/video/video-playlist' 2import { VideoPlaylistModel } from '@server/models/video/video-playlist'
3import { MVideoPlaylist } from '../../types/models/video/video-playlist' 3import { MVideoPlaylist } from '@server/types/models'
4import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' 4import { HttpStatusCode } from '@shared/core-utils'
5 5
6export type VideoPlaylistFetchType = 'summary' | 'all' 6export type VideoPlaylistFetchType = 'summary' | 'all'
7async function doesVideoPlaylistExist (id: number | string, res: express.Response, fetchType: VideoPlaylistFetchType = 'summary') { 7async function doesVideoPlaylistExist (id: number | string, res: express.Response, fetchType: VideoPlaylistFetchType = 'summary') {
diff --git a/server/helpers/middlewares/videos.ts b/server/middlewares/validators/shared/videos.ts
index 52b934eb7..a6dad4374 100644
--- a/server/helpers/middlewares/videos.ts
+++ b/server/middlewares/validators/shared/videos.ts
@@ -1,7 +1,7 @@
1import { Response } from 'express' 1import { Response } from 'express'
2import { fetchVideo, VideoFetchType } from '../video' 2import { fetchVideo, VideoFetchType } from '@server/lib/model-loaders'
3import { UserRight } from '../../../shared/models/users' 3import { VideoChannelModel } from '@server/models/video/video-channel'
4import { VideoChannelModel } from '../../models/video/video-channel' 4import { VideoFileModel } from '@server/models/video/video-file'
5import { 5import {
6 MUser, 6 MUser,
7 MUserAccountId, 7 MUserAccountId,
@@ -12,8 +12,8 @@ import {
12 MVideoThumbnail, 12 MVideoThumbnail,
13 MVideoWithRights 13 MVideoWithRights
14} from '@server/types/models' 14} from '@server/types/models'
15import { VideoFileModel } from '@server/models/video/video-file' 15import { HttpStatusCode } from '@shared/core-utils'
16import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' 16import { UserRight } from '@shared/models'
17 17
18async function doesVideoExist (id: number | string, res: Response, fetchType: VideoFetchType = 'all') { 18async function doesVideoExist (id: number | string, res: Response, fetchType: VideoFetchType = 'all') {
19 const userId = res.locals.oauth ? res.locals.oauth.token.User.id : undefined 19 const userId = res.locals.oauth ? res.locals.oauth.token.User.id : undefined
diff --git a/server/middlewares/validators/sort.ts b/server/middlewares/validators/sort.ts
index beecc155b..d67b6f3ba 100644
--- a/server/middlewares/validators/sort.ts
+++ b/server/middlewares/validators/sort.ts
@@ -1,5 +1,5 @@
1import { SORTABLE_COLUMNS } from '../../initializers/constants' 1import { SORTABLE_COLUMNS } from '../../initializers/constants'
2import { checkSort, createSortableColumns } from './utils' 2import { checkSort, createSortableColumns } from './shared'
3 3
4// Initialize constants here for better performances 4// Initialize constants here for better performances
5const SORTABLE_USERS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.USERS) 5const SORTABLE_USERS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.USERS)
diff --git a/server/middlewares/validators/themes.ts b/server/middlewares/validators/themes.ts
index 91ec0d7ac..d4716257f 100644
--- a/server/middlewares/validators/themes.ts
+++ b/server/middlewares/validators/themes.ts
@@ -1,11 +1,11 @@
1import * as express from 'express' 1import * as express from 'express'
2import { param } from 'express-validator' 2import { param } from 'express-validator'
3import { logger } from '../../helpers/logger' 3import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
4import { areValidationErrors } from './utils' 4import { isSafePath } from '../../helpers/custom-validators/misc'
5import { isPluginNameValid, isPluginVersionValid } from '../../helpers/custom-validators/plugins' 5import { isPluginNameValid, isPluginVersionValid } from '../../helpers/custom-validators/plugins'
6import { logger } from '../../helpers/logger'
6import { PluginManager } from '../../lib/plugins/plugin-manager' 7import { PluginManager } from '../../lib/plugins/plugin-manager'
7import { isSafePath } from '../../helpers/custom-validators/misc' 8import { areValidationErrors } from './shared'
8import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
9 9
10const serveThemeCSSValidator = [ 10const serveThemeCSSValidator = [
11 param('themeName').custom(isPluginNameValid).withMessage('Should have a valid theme name'), 11 param('themeName').custom(isPluginNameValid).withMessage('Should have a valid theme name'),
diff --git a/server/middlewares/validators/user-history.ts b/server/middlewares/validators/user-history.ts
index 647294cc3..1db0d9b26 100644
--- a/server/middlewares/validators/user-history.ts
+++ b/server/middlewares/validators/user-history.ts
@@ -1,8 +1,8 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body, query } from 'express-validator' 2import { body, query } from 'express-validator'
3import { logger } from '../../helpers/logger'
4import { areValidationErrors } from './utils'
5import { exists, isDateValid } from '../../helpers/custom-validators/misc' 3import { exists, isDateValid } from '../../helpers/custom-validators/misc'
4import { logger } from '../../helpers/logger'
5import { areValidationErrors } from './shared'
6 6
7const userHistoryListValidator = [ 7const userHistoryListValidator = [
8 query('search') 8 query('search')
diff --git a/server/middlewares/validators/user-notifications.ts b/server/middlewares/validators/user-notifications.ts
index 21a7be08d..2f8e7686e 100644
--- a/server/middlewares/validators/user-notifications.ts
+++ b/server/middlewares/validators/user-notifications.ts
@@ -1,9 +1,9 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body, query } from 'express-validator' 2import { body, query } from 'express-validator'
3import { logger } from '../../helpers/logger'
4import { areValidationErrors } from './utils'
5import { isUserNotificationSettingValid } from '../../helpers/custom-validators/user-notifications'
6import { isNotEmptyIntArray, toBooleanOrNull } from '../../helpers/custom-validators/misc' 3import { isNotEmptyIntArray, toBooleanOrNull } from '../../helpers/custom-validators/misc'
4import { isUserNotificationSettingValid } from '../../helpers/custom-validators/user-notifications'
5import { logger } from '../../helpers/logger'
6import { areValidationErrors } from './shared'
7 7
8const listUserNotificationsValidator = [ 8const listUserNotificationsValidator = [
9 query('unread') 9 query('unread')
diff --git a/server/middlewares/validators/user-subscriptions.ts b/server/middlewares/validators/user-subscriptions.ts
index 5f928b05b..ab7962923 100644
--- a/server/middlewares/validators/user-subscriptions.ts
+++ b/server/middlewares/validators/user-subscriptions.ts
@@ -6,7 +6,7 @@ import { toArray } from '../../helpers/custom-validators/misc'
6import { logger } from '../../helpers/logger' 6import { logger } from '../../helpers/logger'
7import { WEBSERVER } from '../../initializers/constants' 7import { WEBSERVER } from '../../initializers/constants'
8import { ActorFollowModel } from '../../models/actor/actor-follow' 8import { ActorFollowModel } from '../../models/actor/actor-follow'
9import { areValidationErrors } from './utils' 9import { areValidationErrors } from './shared'
10 10
11const userSubscriptionListValidator = [ 11const userSubscriptionListValidator = [
12 query('search').optional().not().isEmpty().withMessage('Should have a valid search'), 12 query('search').optional().not().isEmpty().withMessage('Should have a valid search'),
diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts
index 0eb9172c4..218633b8d 100644
--- a/server/middlewares/validators/users.ts
+++ b/server/middlewares/validators/users.ts
@@ -30,13 +30,12 @@ import {
30} from '../../helpers/custom-validators/users' 30} from '../../helpers/custom-validators/users'
31import { isVideoChannelNameValid } from '../../helpers/custom-validators/video-channels' 31import { isVideoChannelNameValid } from '../../helpers/custom-validators/video-channels'
32import { logger } from '../../helpers/logger' 32import { logger } from '../../helpers/logger'
33import { doesVideoExist } from '../../helpers/middlewares'
34import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../helpers/signup'
35import { isThemeRegistered } from '../../lib/plugins/theme-utils' 33import { isThemeRegistered } from '../../lib/plugins/theme-utils'
36import { Redis } from '../../lib/redis' 34import { Redis } from '../../lib/redis'
37import { UserModel } from '../../models/user/user' 35import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../lib/signup'
38import { ActorModel } from '../../models/actor/actor' 36import { ActorModel } from '../../models/actor/actor'
39import { areValidationErrors } from './utils' 37import { UserModel } from '../../models/user/user'
38import { areValidationErrors, doesVideoExist } from './shared'
40 39
41const usersListValidator = [ 40const usersListValidator = [
42 query('blocked') 41 query('blocked')
diff --git a/server/middlewares/validators/videos/video-blacklist.ts b/server/middlewares/validators/videos/video-blacklist.ts
index 65132a09f..7374ba774 100644
--- a/server/middlewares/validators/videos/video-blacklist.ts
+++ b/server/middlewares/validators/videos/video-blacklist.ts
@@ -1,11 +1,10 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body, param, query } from 'express-validator' 2import { body, param, query } from 'express-validator'
3import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
3import { isBooleanValid, isIdOrUUIDValid, toBooleanOrNull, toIntOrNull } from '../../../helpers/custom-validators/misc' 4import { isBooleanValid, isIdOrUUIDValid, toBooleanOrNull, toIntOrNull } from '../../../helpers/custom-validators/misc'
4import { isVideoBlacklistReasonValid, isVideoBlacklistTypeValid } from '../../../helpers/custom-validators/video-blacklist' 5import { isVideoBlacklistReasonValid, isVideoBlacklistTypeValid } from '../../../helpers/custom-validators/video-blacklist'
5import { logger } from '../../../helpers/logger' 6import { logger } from '../../../helpers/logger'
6import { doesVideoBlacklistExist, doesVideoExist } from '../../../helpers/middlewares' 7import { areValidationErrors, doesVideoBlacklistExist, doesVideoExist } from '../shared'
7import { areValidationErrors } from '../utils'
8import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
9 8
10const videosBlacklistRemoveValidator = [ 9const videosBlacklistRemoveValidator = [
11 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), 10 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),
diff --git a/server/middlewares/validators/videos/video-captions.ts b/server/middlewares/validators/videos/video-captions.ts
index 872d9c2ab..2295e049a 100644
--- a/server/middlewares/validators/videos/video-captions.ts
+++ b/server/middlewares/validators/videos/video-captions.ts
@@ -1,13 +1,12 @@
1import * as express from 'express' 1import * as express from 'express'
2import { areValidationErrors } from '../utils'
3import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc'
4import { body, param } from 'express-validator' 2import { body, param } from 'express-validator'
5import { CONSTRAINTS_FIELDS, MIMETYPES } from '../../../initializers/constants'
6import { UserRight } from '../../../../shared' 3import { UserRight } from '../../../../shared'
7import { logger } from '../../../helpers/logger' 4import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc'
8import { isVideoCaptionFile, isVideoCaptionLanguageValid } from '../../../helpers/custom-validators/video-captions' 5import { isVideoCaptionFile, isVideoCaptionLanguageValid } from '../../../helpers/custom-validators/video-captions'
9import { cleanUpReqFiles } from '../../../helpers/express-utils' 6import { cleanUpReqFiles } from '../../../helpers/express-utils'
10import { checkUserCanManageVideo, doesVideoCaptionExist, doesVideoExist } from '../../../helpers/middlewares' 7import { logger } from '../../../helpers/logger'
8import { CONSTRAINTS_FIELDS, MIMETYPES } from '../../../initializers/constants'
9import { areValidationErrors, checkUserCanManageVideo, doesVideoCaptionExist, doesVideoExist } from '../shared'
11 10
12const addVideoCaptionValidator = [ 11const addVideoCaptionValidator = [
13 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid video id'), 12 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid video id'),
diff --git a/server/middlewares/validators/videos/video-channels.ts b/server/middlewares/validators/videos/video-channels.ts
index 331a51007..911a25bfb 100644
--- a/server/middlewares/validators/videos/video-channels.ts
+++ b/server/middlewares/validators/videos/video-channels.ts
@@ -12,10 +12,9 @@ import {
12 isVideoChannelSupportValid 12 isVideoChannelSupportValid
13} from '../../../helpers/custom-validators/video-channels' 13} from '../../../helpers/custom-validators/video-channels'
14import { logger } from '../../../helpers/logger' 14import { logger } from '../../../helpers/logger'
15import { doesLocalVideoChannelNameExist, doesVideoChannelNameWithHostExist } from '../../../helpers/middlewares'
16import { ActorModel } from '../../../models/actor/actor' 15import { ActorModel } from '../../../models/actor/actor'
17import { VideoChannelModel } from '../../../models/video/video-channel' 16import { VideoChannelModel } from '../../../models/video/video-channel'
18import { areValidationErrors } from '../utils' 17import { areValidationErrors, doesLocalVideoChannelNameExist, doesVideoChannelNameWithHostExist } from '../shared'
19 18
20const videoChannelsAddValidator = [ 19const videoChannelsAddValidator = [
21 body('name').custom(isActorPreferredUsernameValid).withMessage('Should have a valid channel name'), 20 body('name').custom(isActorPreferredUsernameValid).withMessage('Should have a valid channel name'),
diff --git a/server/middlewares/validators/videos/video-comments.ts b/server/middlewares/validators/videos/video-comments.ts
index aac25a787..1451ab988 100644
--- a/server/middlewares/validators/videos/video-comments.ts
+++ b/server/middlewares/validators/videos/video-comments.ts
@@ -2,19 +2,14 @@ import * as express from 'express'
2import { body, param, query } from 'express-validator' 2import { body, param, query } from 'express-validator'
3import { MUserAccountUrl } from '@server/types/models' 3import { MUserAccountUrl } from '@server/types/models'
4import { UserRight } from '../../../../shared' 4import { UserRight } from '../../../../shared'
5import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
5import { exists, isBooleanValid, isIdOrUUIDValid, isIdValid, toBooleanOrNull } from '../../../helpers/custom-validators/misc' 6import { exists, isBooleanValid, isIdOrUUIDValid, isIdValid, toBooleanOrNull } from '../../../helpers/custom-validators/misc'
6import { 7import { isValidVideoCommentText } from '../../../helpers/custom-validators/video-comments'
7 doesVideoCommentExist,
8 doesVideoCommentThreadExist,
9 isValidVideoCommentText
10} from '../../../helpers/custom-validators/video-comments'
11import { logger } from '../../../helpers/logger' 8import { logger } from '../../../helpers/logger'
12import { doesVideoExist } from '../../../helpers/middlewares'
13import { AcceptResult, isLocalVideoCommentReplyAccepted, isLocalVideoThreadAccepted } from '../../../lib/moderation' 9import { AcceptResult, isLocalVideoCommentReplyAccepted, isLocalVideoThreadAccepted } from '../../../lib/moderation'
14import { Hooks } from '../../../lib/plugins/hooks' 10import { Hooks } from '../../../lib/plugins/hooks'
15import { MCommentOwnerVideoReply, MVideo, MVideoFullLight } from '../../../types/models/video' 11import { MCommentOwnerVideoReply, MVideo, MVideoFullLight } from '../../../types/models/video'
16import { areValidationErrors } from '../utils' 12import { areValidationErrors, doesVideoCommentExist, doesVideoCommentThreadExist, doesVideoExist } from '../shared'
17import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
18 13
19const listVideoCommentsValidator = [ 14const listVideoCommentsValidator = [
20 query('isLocal') 15 query('isLocal')
diff --git a/server/middlewares/validators/videos/video-imports.ts b/server/middlewares/validators/videos/video-imports.ts
index 55ff09124..85dc647ce 100644
--- a/server/middlewares/validators/videos/video-imports.ts
+++ b/server/middlewares/validators/videos/video-imports.ts
@@ -2,18 +2,17 @@ import * as express from 'express'
2import { body } from 'express-validator' 2import { body } from 'express-validator'
3import { isPreImportVideoAccepted } from '@server/lib/moderation' 3import { isPreImportVideoAccepted } from '@server/lib/moderation'
4import { Hooks } from '@server/lib/plugins/hooks' 4import { Hooks } from '@server/lib/plugins/hooks'
5import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
5import { VideoImportCreate } from '@shared/models/videos/import/video-import-create.model' 6import { VideoImportCreate } from '@shared/models/videos/import/video-import-create.model'
6import { isIdValid, toIntOrNull } from '../../../helpers/custom-validators/misc' 7import { isIdValid, toIntOrNull } from '../../../helpers/custom-validators/misc'
7import { isVideoImportTargetUrlValid, isVideoImportTorrentFile } from '../../../helpers/custom-validators/video-imports' 8import { isVideoImportTargetUrlValid, isVideoImportTorrentFile } from '../../../helpers/custom-validators/video-imports'
8import { isVideoMagnetUriValid, isVideoNameValid } from '../../../helpers/custom-validators/videos' 9import { isVideoMagnetUriValid, isVideoNameValid } from '../../../helpers/custom-validators/videos'
9import { cleanUpReqFiles } from '../../../helpers/express-utils' 10import { cleanUpReqFiles } from '../../../helpers/express-utils'
10import { logger } from '../../../helpers/logger' 11import { logger } from '../../../helpers/logger'
11import { doesVideoChannelOfAccountExist } from '../../../helpers/middlewares'
12import { CONFIG } from '../../../initializers/config' 12import { CONFIG } from '../../../initializers/config'
13import { CONSTRAINTS_FIELDS } from '../../../initializers/constants' 13import { CONSTRAINTS_FIELDS } from '../../../initializers/constants'
14import { areValidationErrors } from '../utils' 14import { areValidationErrors, doesVideoChannelOfAccountExist } from '../shared'
15import { getCommonVideoEditAttributes } from './videos' 15import { getCommonVideoEditAttributes } from './videos'
16import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
17 16
18const videoImportAddValidator = getCommonVideoEditAttributes().concat([ 17const videoImportAddValidator = getCommonVideoEditAttributes().concat([
19 body('channelId') 18 body('channelId')
diff --git a/server/middlewares/validators/videos/video-live.ts b/server/middlewares/validators/videos/video-live.ts
index 0fb864098..ffc8c47b3 100644
--- a/server/middlewares/validators/videos/video-live.ts
+++ b/server/middlewares/validators/videos/video-live.ts
@@ -1,20 +1,19 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body, param } from 'express-validator' 2import { body, param } from 'express-validator'
3import { checkUserCanManageVideo, doesVideoChannelOfAccountExist, doesVideoExist } from '@server/helpers/middlewares/videos' 3import { CONSTRAINTS_FIELDS } from '@server/initializers/constants'
4import { isLocalLiveVideoAccepted } from '@server/lib/moderation'
5import { Hooks } from '@server/lib/plugins/hooks'
6import { VideoModel } from '@server/models/video/video'
4import { VideoLiveModel } from '@server/models/video/video-live' 7import { VideoLiveModel } from '@server/models/video/video-live'
8import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
5import { ServerErrorCode, UserRight, VideoState } from '@shared/models' 9import { ServerErrorCode, UserRight, VideoState } from '@shared/models'
6import { isBooleanValid, isIdOrUUIDValid, isIdValid, toBooleanOrNull, toIntOrNull } from '../../../helpers/custom-validators/misc' 10import { isBooleanValid, isIdOrUUIDValid, isIdValid, toBooleanOrNull, toIntOrNull } from '../../../helpers/custom-validators/misc'
7import { isVideoNameValid } from '../../../helpers/custom-validators/videos' 11import { isVideoNameValid } from '../../../helpers/custom-validators/videos'
8import { cleanUpReqFiles } from '../../../helpers/express-utils' 12import { cleanUpReqFiles } from '../../../helpers/express-utils'
9import { logger } from '../../../helpers/logger' 13import { logger } from '../../../helpers/logger'
10import { CONFIG } from '../../../initializers/config' 14import { CONFIG } from '../../../initializers/config'
11import { areValidationErrors } from '../utils' 15import { areValidationErrors, checkUserCanManageVideo, doesVideoChannelOfAccountExist, doesVideoExist } from '../shared'
12import { getCommonVideoEditAttributes } from './videos' 16import { getCommonVideoEditAttributes } from './videos'
13import { VideoModel } from '@server/models/video/video'
14import { Hooks } from '@server/lib/plugins/hooks'
15import { isLocalLiveVideoAccepted } from '@server/lib/moderation'
16import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
17import { CONSTRAINTS_FIELDS } from '@server/initializers/constants'
18 17
19const videoLiveGetValidator = [ 18const videoLiveGetValidator = [
20 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), 19 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),
diff --git a/server/middlewares/validators/videos/video-playlists.ts b/server/middlewares/validators/videos/video-playlists.ts
index 90815dd3a..0d2e6e90c 100644
--- a/server/middlewares/validators/videos/video-playlists.ts
+++ b/server/middlewares/validators/videos/video-playlists.ts
@@ -25,12 +25,11 @@ import {
25import { isVideoImage } from '../../../helpers/custom-validators/videos' 25import { isVideoImage } from '../../../helpers/custom-validators/videos'
26import { cleanUpReqFiles } from '../../../helpers/express-utils' 26import { cleanUpReqFiles } from '../../../helpers/express-utils'
27import { logger } from '../../../helpers/logger' 27import { logger } from '../../../helpers/logger'
28import { doesVideoChannelIdExist, doesVideoExist, doesVideoPlaylistExist, VideoPlaylistFetchType } from '../../../helpers/middlewares'
29import { CONSTRAINTS_FIELDS } from '../../../initializers/constants' 28import { CONSTRAINTS_FIELDS } from '../../../initializers/constants'
30import { VideoPlaylistElementModel } from '../../../models/video/video-playlist-element' 29import { VideoPlaylistElementModel } from '../../../models/video/video-playlist-element'
31import { MVideoPlaylist } from '../../../types/models/video/video-playlist' 30import { MVideoPlaylist } from '../../../types/models/video/video-playlist'
32import { authenticatePromiseIfNeeded } from '../../auth' 31import { authenticatePromiseIfNeeded } from '../../auth'
33import { areValidationErrors } from '../utils' 32import { areValidationErrors, doesVideoChannelIdExist, doesVideoExist, doesVideoPlaylistExist, VideoPlaylistFetchType } from '../shared'
34 33
35const videoPlaylistsAddValidator = getCommonPlaylistEditAttributes().concat([ 34const videoPlaylistsAddValidator = getCommonPlaylistEditAttributes().concat([
36 body('displayName') 35 body('displayName')
diff --git a/server/middlewares/validators/videos/video-rates.ts b/server/middlewares/validators/videos/video-rates.ts
index 5c4176f54..4a802e75e 100644
--- a/server/middlewares/validators/videos/video-rates.ts
+++ b/server/middlewares/validators/videos/video-rates.ts
@@ -1,15 +1,14 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body, param, query } from 'express-validator' 2import { body, param, query } from 'express-validator'
3import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
4import { VideoRateType } from '../../../../shared/models/videos'
5import { isAccountNameValid } from '../../../helpers/custom-validators/accounts'
3import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' 6import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc'
4import { isRatingValid } from '../../../helpers/custom-validators/video-rates' 7import { isRatingValid } from '../../../helpers/custom-validators/video-rates'
5import { isVideoRatingTypeValid } from '../../../helpers/custom-validators/videos' 8import { isVideoRatingTypeValid } from '../../../helpers/custom-validators/videos'
6import { logger } from '../../../helpers/logger' 9import { logger } from '../../../helpers/logger'
7import { areValidationErrors } from '../utils'
8import { AccountVideoRateModel } from '../../../models/account/account-video-rate' 10import { AccountVideoRateModel } from '../../../models/account/account-video-rate'
9import { VideoRateType } from '../../../../shared/models/videos' 11import { areValidationErrors, doesVideoExist } from '../shared'
10import { isAccountNameValid } from '../../../helpers/custom-validators/accounts'
11import { doesVideoExist } from '../../../helpers/middlewares'
12import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
13 12
14const videoUpdateRateValidator = [ 13const videoUpdateRateValidator = [
15 param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), 14 param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
diff --git a/server/middlewares/validators/videos/video-shares.ts b/server/middlewares/validators/videos/video-shares.ts
index f0d8e0c36..cc2f66e94 100644
--- a/server/middlewares/validators/videos/video-shares.ts
+++ b/server/middlewares/validators/videos/video-shares.ts
@@ -1,11 +1,10 @@
1import * as express from 'express' 1import * as express from 'express'
2import { param } from 'express-validator' 2import { param } from 'express-validator'
3import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
3import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' 4import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc'
4import { logger } from '../../../helpers/logger' 5import { logger } from '../../../helpers/logger'
5import { VideoShareModel } from '../../../models/video/video-share' 6import { VideoShareModel } from '../../../models/video/video-share'
6import { areValidationErrors } from '../utils' 7import { areValidationErrors, doesVideoExist } from '../shared'
7import { doesVideoExist } from '../../../helpers/middlewares'
8import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
9 8
10const videosShareValidator = [ 9const videosShareValidator = [
11 param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), 10 param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
diff --git a/server/middlewares/validators/videos/video-watch.ts b/server/middlewares/validators/videos/video-watch.ts
index 00c739d31..ef8b89ece 100644
--- a/server/middlewares/validators/videos/video-watch.ts
+++ b/server/middlewares/validators/videos/video-watch.ts
@@ -1,10 +1,9 @@
1import { body, param } from 'express-validator'
2import * as express from 'express' 1import * as express from 'express'
2import { body, param } from 'express-validator'
3import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
3import { isIdOrUUIDValid, toIntOrNull } from '../../../helpers/custom-validators/misc' 4import { isIdOrUUIDValid, toIntOrNull } from '../../../helpers/custom-validators/misc'
4import { areValidationErrors } from '../utils'
5import { logger } from '../../../helpers/logger' 5import { logger } from '../../../helpers/logger'
6import { doesVideoExist } from '../../../helpers/middlewares' 6import { areValidationErrors, doesVideoExist } from '../shared'
7import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
8 7
9const videoWatchingValidator = [ 8const videoWatchingValidator = [
10 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), 9 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
diff --git a/server/middlewares/validators/videos/videos.ts b/server/middlewares/validators/videos/videos.ts
index b7a9bcbe3..52e6c5762 100644
--- a/server/middlewares/validators/videos/videos.ts
+++ b/server/middlewares/validators/videos/videos.ts
@@ -22,7 +22,7 @@ import {
22 toValueOrNull 22 toValueOrNull
23} from '../../../helpers/custom-validators/misc' 23} from '../../../helpers/custom-validators/misc'
24import { isBooleanBothQueryValid, isNumberArray, isStringArray } from '../../../helpers/custom-validators/search' 24import { isBooleanBothQueryValid, isNumberArray, isStringArray } from '../../../helpers/custom-validators/search'
25import { checkUserCanTerminateOwnershipChange, doesChangeVideoOwnershipExist } from '../../../helpers/custom-validators/video-ownership' 25import { checkUserCanTerminateOwnershipChange } from '../../../helpers/custom-validators/video-ownership'
26import { 26import {
27 isScheduleVideoUpdatePrivacyValid, 27 isScheduleVideoUpdatePrivacyValid,
28 isVideoCategoryValid, 28 isVideoCategoryValid,
@@ -42,12 +42,6 @@ import {
42import { cleanUpReqFiles } from '../../../helpers/express-utils' 42import { cleanUpReqFiles } from '../../../helpers/express-utils'
43import { getDurationFromVideoFile } from '../../../helpers/ffprobe-utils' 43import { getDurationFromVideoFile } from '../../../helpers/ffprobe-utils'
44import { logger } from '../../../helpers/logger' 44import { logger } from '../../../helpers/logger'
45import {
46 checkUserCanManageVideo,
47 doesVideoChannelOfAccountExist,
48 doesVideoExist,
49 doesVideoFileOfVideoExist
50} from '../../../helpers/middlewares'
51import { deleteFileAndCatch } from '../../../helpers/utils' 45import { deleteFileAndCatch } from '../../../helpers/utils'
52import { getVideoWithAttributes } from '../../../helpers/video' 46import { getVideoWithAttributes } from '../../../helpers/video'
53import { CONFIG } from '../../../initializers/config' 47import { CONFIG } from '../../../initializers/config'
@@ -57,7 +51,14 @@ import { Hooks } from '../../../lib/plugins/hooks'
57import { AccountModel } from '../../../models/account/account' 51import { AccountModel } from '../../../models/account/account'
58import { VideoModel } from '../../../models/video/video' 52import { VideoModel } from '../../../models/video/video'
59import { authenticatePromiseIfNeeded } from '../../auth' 53import { authenticatePromiseIfNeeded } from '../../auth'
60import { areValidationErrors } from '../utils' 54import {
55 areValidationErrors,
56 checkUserCanManageVideo,
57 doesChangeVideoOwnershipExist,
58 doesVideoChannelOfAccountExist,
59 doesVideoExist,
60 doesVideoFileOfVideoExist
61} from '../shared'
61 62
62const videosAddLegacyValidator = getCommonVideoEditAttributes().concat([ 63const videosAddLegacyValidator = getCommonVideoEditAttributes().concat([
63 body('videofile') 64 body('videofile')
diff --git a/server/middlewares/validators/webfinger.ts b/server/middlewares/validators/webfinger.ts
index 097a5ece1..bcdd136c6 100644
--- a/server/middlewares/validators/webfinger.ts
+++ b/server/middlewares/validators/webfinger.ts
@@ -5,7 +5,7 @@ import { isWebfingerLocalResourceValid } from '../../helpers/custom-validators/w
5import { getHostWithPort } from '../../helpers/express-utils' 5import { getHostWithPort } from '../../helpers/express-utils'
6import { logger } from '../../helpers/logger' 6import { logger } from '../../helpers/logger'
7import { ActorModel } from '../../models/actor/actor' 7import { ActorModel } from '../../models/actor/actor'
8import { areValidationErrors } from './utils' 8import { areValidationErrors } from './shared'
9 9
10const webfingerValidator = [ 10const webfingerValidator = [
11 query('resource').custom(isWebfingerLocalResourceValid).withMessage('Should have a valid webfinger resource'), 11 query('resource').custom(isWebfingerLocalResourceValid).withMessage('Should have a valid webfinger resource'),