diff options
Diffstat (limited to 'server')
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 | |||
14 | import { buildNSFWFilter, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils' | 14 | import { buildNSFWFilter, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils' |
15 | import { logger } from '../../helpers/logger' | 15 | import { logger } from '../../helpers/logger' |
16 | import { getFormattedObjects } from '../../helpers/utils' | 16 | import { getFormattedObjects } from '../../helpers/utils' |
17 | import { loadActorUrlOrGetFromWebfinger } from '../../helpers/webfinger' | 17 | import { getOrCreateAPActor, loadActorUrlOrGetFromWebfinger } from '../../lib/activitypub/actors' |
18 | import { getOrCreateAPActor } from '../../lib/activitypub/actors' | ||
19 | import { | 18 | import { |
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 @@ | |||
1 | import * as express from 'express' | ||
2 | import validator from 'validator' | 1 | import validator from 'validator' |
3 | import { VideoCommentModel } from '@server/models/video/video-comment' | ||
4 | import { CONSTRAINTS_FIELDS } from '../../initializers/constants' | 2 | import { CONSTRAINTS_FIELDS } from '../../initializers/constants' |
5 | import { MVideoId } from '@server/types/models' | ||
6 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
7 | 3 | ||
8 | const VIDEO_COMMENTS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_COMMENTS | 4 | const 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 | ||
14 | async 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 | |||
40 | async 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 | |||
61 | async 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 | ||
79 | export { | 12 | export { |
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' | |||
2 | import validator from 'validator' | 2 | import validator from 'validator' |
3 | import { CONSTRAINTS_FIELDS, MIMETYPES, VIDEO_IMPORT_STATES } from '../../initializers/constants' | 3 | import { CONSTRAINTS_FIELDS, MIMETYPES, VIDEO_IMPORT_STATES } from '../../initializers/constants' |
4 | import { exists, isFileValid } from './misc' | 4 | import { exists, isFileValid } from './misc' |
5 | import * as express from 'express' | ||
6 | import { VideoImportModel } from '../../models/video/video-import' | ||
7 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
8 | 5 | ||
9 | function isVideoImportTargetUrlValid (url: string) { | 6 | function 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 | ||
35 | async 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 | ||
52 | export { | 34 | export { |
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 @@ | |||
1 | import { Response } from 'express' | 1 | import { Response } from 'express' |
2 | import { VideoChangeOwnershipModel } from '../../models/video/video-change-ownership' | ||
3 | import { MVideoChangeOwnershipFull } from '@server/types/models/video/video-change-ownership' | ||
4 | import { MUserId } from '@server/types/models' | 2 | import { MUserId } from '@server/types/models' |
3 | import { MVideoChangeOwnershipFull } from '@server/types/models/video/video-change-ownership' | ||
5 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | 4 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' |
6 | 5 | ||
7 | export async function doesChangeVideoOwnershipExist (idArg: number | string, res: Response) { | 6 | function 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 | |||
23 | export 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 | |||
18 | export { | ||
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 @@ | |||
1 | import { Response } from 'express' | 1 | import { Response } from 'express' |
2 | import { CONFIG } from '@server/initializers/config' | 2 | import { CONFIG } from '@server/initializers/config' |
3 | import { | 3 | import { 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' | ||
14 | import { VideoPrivacy, VideoState } from '@shared/models' | 4 | import { VideoPrivacy, VideoState } from '@shared/models' |
15 | import { VideoModel } from '../models/video/video' | ||
16 | |||
17 | type VideoFetchType = 'all' | 'only-video' | 'only-video-with-rights' | 'id' | 'none' | 'only-immutable-attributes' | ||
18 | |||
19 | function fetchVideo (id: number | string, fetchType: 'all', userId?: number): Promise<MVideoFullLight> | ||
20 | function fetchVideo (id: number | string, fetchType: 'only-immutable-attributes'): Promise<MVideoImmutable> | ||
21 | function fetchVideo (id: number | string, fetchType: 'only-video', userId?: number): Promise<MVideoThumbnail> | ||
22 | function fetchVideo (id: number | string, fetchType: 'only-video-with-rights', userId?: number): Promise<MVideoWithRights> | ||
23 | function fetchVideo (id: number | string, fetchType: 'id' | 'none', userId?: number): Promise<MVideoIdThumbnail> | ||
24 | function fetchVideo ( | ||
25 | id: number | string, | ||
26 | fetchType: VideoFetchType, | ||
27 | userId?: number | ||
28 | ): Promise<MVideoFullLight | MVideoThumbnail | MVideoWithRights | MVideoIdThumbnail | MVideoImmutable> | ||
29 | function 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 | |||
45 | type VideoFetchByUrlType = 'all' | 'only-video' | 'only-immutable-attributes' | ||
46 | |||
47 | function fetchVideoByUrl (url: string, fetchType: 'all'): Promise<MVideoAccountLightBlacklistAllFiles> | ||
48 | function fetchVideoByUrl (url: string, fetchType: 'only-immutable-attributes'): Promise<MVideoImmutable> | ||
49 | function fetchVideoByUrl (url: string, fetchType: 'only-video'): Promise<MVideoThumbnail> | ||
50 | function fetchVideoByUrl ( | ||
51 | url: string, | ||
52 | fetchType: VideoFetchByUrlType | ||
53 | ): Promise<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable> | ||
54 | function 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 | ||
65 | function getVideoWithAttributes (res: Response) { | 6 | function 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 | ||
102 | export { | 43 | export { |
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 | ||
2 | import { checkUrlsSameHost, getAPId } from '@server/helpers/activitypub' | 2 | import { checkUrlsSameHost, getAPId } from '@server/helpers/activitypub' |
3 | import { ActorFetchByUrlType, fetchActorByUrl } from '@server/helpers/actor' | ||
4 | import { retryTransactionWrapper } from '@server/helpers/database-utils' | 3 | import { retryTransactionWrapper } from '@server/helpers/database-utils' |
5 | import { logger } from '@server/helpers/logger' | 4 | import { logger } from '@server/helpers/logger' |
6 | import { JobQueue } from '@server/lib/job-queue' | 5 | import { JobQueue } from '@server/lib/job-queue' |
6 | import { ActorFetchByUrlType, fetchActorByUrl } from '@server/lib/model-loaders' | ||
7 | import { MActor, MActorAccountChannelId, MActorAccountChannelIdActor, MActorAccountId, MActorFullActor } from '@server/types/models' | 7 | import { MActor, MActorAccountChannelId, MActorAccountChannelIdActor, MActorAccountId, MActorFullActor } from '@server/types/models' |
8 | import { ActivityPubActor } from '@shared/models' | 8 | import { ActivityPubActor } from '@shared/models' |
9 | import { refreshActorIfNeeded } from './refresh' | 9 | import { 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' | |||
3 | export * from './keys' | 3 | export * from './keys' |
4 | export * from './refresh' | 4 | export * from './refresh' |
5 | export * from './updater' | 5 | export * from './updater' |
6 | export * 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 @@ | |||
1 | import { ActorFetchByUrlType } from '@server/helpers/actor' | ||
2 | import { logger } from '@server/helpers/logger' | 1 | import { logger } from '@server/helpers/logger' |
3 | import { PeerTubeRequestError } from '@server/helpers/requests' | 2 | import { PeerTubeRequestError } from '@server/helpers/requests' |
4 | import { getUrlFromWebfinger } from '@server/helpers/webfinger' | 3 | import { ActorFetchByUrlType } from '@server/lib/model-loaders' |
5 | import { ActorModel } from '@server/models/actor/actor' | 4 | import { ActorModel } from '@server/models/actor/actor' |
6 | import { MActorAccountChannelId, MActorFull } from '@server/types/models' | 5 | import { MActorAccountChannelId, MActorFull } from '@server/types/models' |
7 | import { HttpStatusCode } from '@shared/core-utils' | 6 | import { HttpStatusCode } from '@shared/core-utils' |
8 | import { fetchRemoteActor } from './shared' | 7 | import { fetchRemoteActor } from './shared' |
9 | import { APActorUpdater } from './updater' | 8 | import { APActorUpdater } from './updater' |
9 | import { getUrlFromWebfinger } from './webfinger' | ||
10 | 10 | ||
11 | async function refreshActorIfNeeded <T extends MActorFull | MActorAccountChannelId> ( | 11 | async 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 @@ | |||
1 | export * from './creator' | 1 | export * from './creator' |
2 | export * from './url-to-object' | ||
3 | export * from './object-to-model-attributes' | 2 | export * from './object-to-model-attributes' |
3 | export * 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 @@ | |||
1 | import * as WebFinger from 'webfinger.js' | 1 | import * as WebFinger from 'webfinger.js' |
2 | import { WebFingerData } from '../../shared' | 2 | import { isTestInstance } from '@server/helpers/core-utils' |
3 | import { WEBSERVER } from '../initializers/constants' | 3 | import { isActivityPubUrlValid } from '@server/helpers/custom-validators/activitypub/misc' |
4 | import { ActorModel } from '../models/actor/actor' | 4 | import { WEBSERVER } from '@server/initializers/constants' |
5 | import { MActorFull } from '../types/models' | 5 | import { ActorModel } from '@server/models/actor/actor' |
6 | import { isTestInstance } from './core-utils' | 6 | import { MActorFull } from '@server/types/models' |
7 | import { isActivityPubUrlValid } from './custom-validators/activitypub/misc' | 7 | import { WebFingerData } from '@shared/models' |
8 | 8 | ||
9 | const webfinger = new WebFinger({ | 9 | const 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 @@ | |||
1 | import { getAPId } from '@server/helpers/activitypub' | 1 | import { getAPId } from '@server/helpers/activitypub' |
2 | import { retryTransactionWrapper } from '@server/helpers/database-utils' | 2 | import { retryTransactionWrapper } from '@server/helpers/database-utils' |
3 | import { fetchVideoByUrl, VideoFetchByUrlType } from '@server/helpers/video' | ||
4 | import { JobQueue } from '@server/lib/job-queue' | 3 | import { JobQueue } from '@server/lib/job-queue' |
4 | import { fetchVideoByUrl, VideoFetchByUrlType } from '@server/lib/model-loaders' | ||
5 | import { MVideoAccountLightBlacklistAllFiles, MVideoImmutable, MVideoThumbnail } from '@server/types/models' | 5 | import { MVideoAccountLightBlacklistAllFiles, MVideoImmutable, MVideoThumbnail } from '@server/types/models' |
6 | import { refreshVideoIfNeeded } from './refresh' | 6 | import { refreshVideoIfNeeded } from './refresh' |
7 | import { APVideoCreator, fetchRemoteVideo, SyncParam, syncVideoExternalAttributes } from './shared' | 7 | import { 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 @@ | |||
1 | import { logger, loggerTagsFactory } from '@server/helpers/logger' | 1 | import { logger, loggerTagsFactory } from '@server/helpers/logger' |
2 | import { PeerTubeRequestError } from '@server/helpers/requests' | 2 | import { PeerTubeRequestError } from '@server/helpers/requests' |
3 | import { VideoFetchByUrlType } from '@server/helpers/video' | ||
4 | import { ActorFollowScoreCache } from '@server/lib/files-cache' | 3 | import { ActorFollowScoreCache } from '@server/lib/files-cache' |
4 | import { VideoFetchByUrlType } from '@server/lib/model-loaders' | ||
5 | import { VideoModel } from '@server/models/video/video' | 5 | import { VideoModel } from '@server/models/video/video' |
6 | import { MVideoAccountLightBlacklistAllFiles, MVideoThumbnail } from '@server/types/models' | 6 | import { MVideoAccountLightBlacklistAllFiles, MVideoThumbnail } from '@server/types/models' |
7 | import { HttpStatusCode } from '@shared/core-utils' | 7 | import { 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' | |||
4 | import { sanitizeHost } from '../../../helpers/core-utils' | 4 | import { sanitizeHost } from '../../../helpers/core-utils' |
5 | import { retryTransactionWrapper } from '../../../helpers/database-utils' | 5 | import { retryTransactionWrapper } from '../../../helpers/database-utils' |
6 | import { logger } from '../../../helpers/logger' | 6 | import { logger } from '../../../helpers/logger' |
7 | import { loadActorUrlOrGetFromWebfinger } from '../../../helpers/webfinger' | ||
8 | import { REMOTE_SCHEME, WEBSERVER } from '../../../initializers/constants' | 7 | import { REMOTE_SCHEME, WEBSERVER } from '../../../initializers/constants' |
9 | import { sequelizeTypescript } from '../../../initializers/database' | 8 | import { sequelizeTypescript } from '../../../initializers/database' |
10 | import { ActorModel } from '../../../models/actor/actor' | 9 | import { ActorModel } from '../../../models/actor/actor' |
11 | import { ActorFollowModel } from '../../../models/actor/actor-follow' | 10 | import { ActorFollowModel } from '../../../models/actor/actor-follow' |
12 | import { MActor, MActorFollowActors, MActorFull } from '../../../types/models' | 11 | import { MActor, MActorFollowActors, MActorFull } from '../../../types/models' |
13 | import { getOrCreateAPActor } from '../../activitypub/actors' | 12 | import { getOrCreateAPActor, loadActorUrlOrGetFromWebfinger } from '../../activitypub/actors' |
14 | import { sendFollow } from '../../activitypub/send' | 13 | import { sendFollow } from '../../activitypub/send' |
15 | import { Notifier } from '../../notifier' | 14 | import { 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 @@ | |||
1 | import * as Bull from 'bull' | 1 | import * as Bull from 'bull' |
2 | import { refreshVideoPlaylistIfNeeded } from '@server/lib/activitypub/playlists' | 2 | import { refreshVideoPlaylistIfNeeded } from '@server/lib/activitypub/playlists' |
3 | import { refreshVideoIfNeeded } from '@server/lib/activitypub/videos' | 3 | import { refreshVideoIfNeeded } from '@server/lib/activitypub/videos' |
4 | import { fetchVideoByUrl } from '@server/lib/model-loaders' | ||
4 | import { RefreshPayload } from '@shared/models' | 5 | import { RefreshPayload } from '@shared/models' |
5 | import { logger } from '../../../helpers/logger' | 6 | import { logger } from '../../../helpers/logger' |
6 | import { fetchVideoByUrl } from '../../../helpers/video' | ||
7 | import { ActorModel } from '../../../models/actor/actor' | 7 | import { ActorModel } from '../../../models/actor/actor' |
8 | import { VideoPlaylistModel } from '../../../models/video/video-playlist' | 8 | import { VideoPlaylistModel } from '../../../models/video/video-playlist' |
9 | import { refreshActorIfNeeded } from '../../activitypub/actors' | 9 | import { 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 | ||
2 | import { ActorModel } from '../models/actor/actor' | 2 | import { ActorModel } from '../../models/actor/actor' |
3 | import { MActorAccountChannelId, MActorFull } from '../types/models' | 3 | import { MActorAccountChannelId, MActorFull } from '../../types/models' |
4 | 4 | ||
5 | type ActorFetchByUrlType = 'all' | 'association-ids' | 5 | type 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 @@ | |||
1 | export * from './actor' | ||
2 | export * 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 @@ | |||
1 | import { VideoModel } from '@server/models/video/video' | ||
2 | import { | ||
3 | MVideoAccountLightBlacklistAllFiles, | ||
4 | MVideoFullLight, | ||
5 | MVideoIdThumbnail, | ||
6 | MVideoImmutable, | ||
7 | MVideoThumbnail, | ||
8 | MVideoWithRights | ||
9 | } from '@server/types/models' | ||
10 | |||
11 | type VideoFetchType = 'all' | 'only-video' | 'only-video-with-rights' | 'id' | 'none' | 'only-immutable-attributes' | ||
12 | |||
13 | function fetchVideo (id: number | string, fetchType: 'all', userId?: number): Promise<MVideoFullLight> | ||
14 | function fetchVideo (id: number | string, fetchType: 'only-immutable-attributes'): Promise<MVideoImmutable> | ||
15 | function fetchVideo (id: number | string, fetchType: 'only-video', userId?: number): Promise<MVideoThumbnail> | ||
16 | function fetchVideo (id: number | string, fetchType: 'only-video-with-rights', userId?: number): Promise<MVideoWithRights> | ||
17 | function fetchVideo (id: number | string, fetchType: 'id' | 'none', userId?: number): Promise<MVideoIdThumbnail> | ||
18 | function fetchVideo ( | ||
19 | id: number | string, | ||
20 | fetchType: VideoFetchType, | ||
21 | userId?: number | ||
22 | ): Promise<MVideoFullLight | MVideoThumbnail | MVideoWithRights | MVideoIdThumbnail | MVideoImmutable> | ||
23 | function 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 | |||
39 | type VideoFetchByUrlType = 'all' | 'only-video' | 'only-immutable-attributes' | ||
40 | |||
41 | function fetchVideoByUrl (url: string, fetchType: 'all'): Promise<MVideoAccountLightBlacklistAllFiles> | ||
42 | function fetchVideoByUrl (url: string, fetchType: 'only-immutable-attributes'): Promise<MVideoImmutable> | ||
43 | function fetchVideoByUrl (url: string, fetchType: 'only-video'): Promise<MVideoThumbnail> | ||
44 | function fetchVideoByUrl ( | ||
45 | url: string, | ||
46 | fetchType: VideoFetchByUrlType | ||
47 | ): Promise<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable> | ||
48 | function 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 | |||
59 | export { | ||
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 @@ | |||
1 | import { isSignupAllowed, isSignupAllowedForCurrentIP } from '@server/helpers/signup' | ||
2 | import { getServerCommit } from '@server/helpers/utils' | 1 | import { getServerCommit } from '@server/helpers/utils' |
3 | import { CONFIG, isEmailEnabled } from '@server/initializers/config' | 2 | import { CONFIG, isEmailEnabled } from '@server/initializers/config' |
4 | import { CONSTRAINTS_FIELDS, DEFAULT_THEME_NAME, PEERTUBE_VERSION } from '@server/initializers/constants' | 3 | import { CONSTRAINTS_FIELDS, DEFAULT_THEME_NAME, PEERTUBE_VERSION } from '@server/initializers/constants' |
4 | import { isSignupAllowed, isSignupAllowedForCurrentIP } from '@server/lib/signup' | ||
5 | import { ActorCustomPageModel } from '@server/models/account/actor-custom-page' | 5 | import { ActorCustomPageModel } from '@server/models/account/actor-custom-page' |
6 | import { HTMLServerConfig, RegisteredExternalAuthConfig, RegisteredIdAndPassAuthConfig, ServerConfig } from '@shared/models' | 6 | import { HTMLServerConfig, RegisteredExternalAuthConfig, RegisteredIdAndPassAuthConfig, ServerConfig } from '@shared/models' |
7 | import { Hooks } from './plugins/hooks' | 7 | import { 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 @@ | |||
1 | import { NextFunction, Request, Response } from 'express' | 1 | import { NextFunction, Request, Response } from 'express' |
2 | import { getAPId } from '@server/helpers/activitypub' | ||
3 | import { isActorDeleteActivityValid } from '@server/helpers/custom-validators/activitypub/actor' | ||
2 | import { ActivityDelete, ActivityPubSignature } from '../../shared' | 4 | import { ActivityDelete, ActivityPubSignature } from '../../shared' |
5 | import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes' | ||
3 | import { logger } from '../helpers/logger' | 6 | import { logger } from '../helpers/logger' |
4 | import { isHTTPSignatureVerified, isJsonLDSignatureVerified, parseHTTPSignature } from '../helpers/peertube-crypto' | 7 | import { isHTTPSignatureVerified, isJsonLDSignatureVerified, parseHTTPSignature } from '../helpers/peertube-crypto' |
5 | import { ACCEPT_HEADERS, ACTIVITY_PUB, HTTP_SIGNATURE } from '../initializers/constants' | 8 | import { ACCEPT_HEADERS, ACTIVITY_PUB, HTTP_SIGNATURE } from '../initializers/constants' |
6 | import { getOrCreateAPActor } from '../lib/activitypub/actors' | 9 | import { getOrCreateAPActor, loadActorUrlOrGetFromWebfinger } from '../lib/activitypub/actors' |
7 | import { loadActorUrlOrGetFromWebfinger } from '../helpers/webfinger' | ||
8 | import { isActorDeleteActivityValid } from '@server/helpers/custom-validators/activitypub/actor' | ||
9 | import { getAPId } from '@server/helpers/activitypub' | ||
10 | import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes' | ||
11 | 10 | ||
12 | async function checkSignature (req: Request, res: Response, next: NextFunction) { | 11 | async 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' |
15 | import { exists, isIdOrUUIDValid, isIdValid, toIntOrNull } from '@server/helpers/custom-validators/misc' | 15 | import { exists, isIdOrUUIDValid, isIdValid, toIntOrNull } from '@server/helpers/custom-validators/misc' |
16 | import { doesCommentIdExist } from '@server/helpers/custom-validators/video-comments' | ||
17 | import { logger } from '@server/helpers/logger' | 16 | import { logger } from '@server/helpers/logger' |
18 | import { doesAbuseExist, doesAccountIdExist, doesVideoExist } from '@server/helpers/middlewares' | ||
19 | import { AbuseMessageModel } from '@server/models/abuse/abuse-message' | 17 | import { AbuseMessageModel } from '@server/models/abuse/abuse-message' |
20 | import { AbuseCreate, UserRight } from '@shared/models' | 18 | import { AbuseCreate, UserRight } from '@shared/models' |
21 | import { areValidationErrors } from './utils' | ||
22 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | 19 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' |
20 | import { areValidationErrors, doesAbuseExist, doesAccountIdExist, doesCommentIdExist, doesVideoExist } from './shared' | ||
23 | 21 | ||
24 | const abuseReportValidator = [ | 22 | const 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' | |||
2 | import { param } from 'express-validator' | 2 | import { param } from 'express-validator' |
3 | import { isAccountNameValid } from '../../helpers/custom-validators/accounts' | 3 | import { isAccountNameValid } from '../../helpers/custom-validators/accounts' |
4 | import { logger } from '../../helpers/logger' | 4 | import { logger } from '../../helpers/logger' |
5 | import { areValidationErrors } from './utils' | 5 | import { areValidationErrors, doesAccountNameWithHostExist, doesLocalAccountNameExist } from './shared' |
6 | import { doesAccountNameWithHostExist, doesLocalAccountNameExist } from '../../helpers/middlewares' | ||
7 | 6 | ||
8 | const localAccountValidator = [ | 7 | const 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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { query } from 'express-validator' | 2 | import { query } from 'express-validator' |
3 | import { logger } from '../../../helpers/logger' | ||
4 | import { areValidationErrors } from '../utils' | ||
5 | import { PAGINATION } from '@server/initializers/constants' | 3 | import { PAGINATION } from '@server/initializers/constants' |
4 | import { logger } from '../../../helpers/logger' | ||
5 | import { areValidationErrors } from '../shared' | ||
6 | 6 | ||
7 | const apPaginationValidator = [ | 7 | const 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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body } from 'express-validator' | 2 | import { body } from 'express-validator' |
3 | import { | 3 | import { |
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' |
7 | import { isDateValid } from '../../../helpers/custom-validators/misc' | 8 | import { isDateValid } from '../../../helpers/custom-validators/misc' |
8 | import { logger } from '../../../helpers/logger' | 9 | import { logger } from '../../../helpers/logger' |
9 | import { areValidationErrors } from '../utils' | 10 | import { areValidationErrors } from '../shared' |
10 | 11 | ||
11 | const signatureValidator = [ | 12 | const 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 | |||
4 | import { cleanUpReqFiles } from '../../helpers/express-utils' | 4 | import { cleanUpReqFiles } from '../../helpers/express-utils' |
5 | import { logger } from '../../helpers/logger' | 5 | import { logger } from '../../helpers/logger' |
6 | import { CONSTRAINTS_FIELDS } from '../../initializers/constants' | 6 | import { CONSTRAINTS_FIELDS } from '../../initializers/constants' |
7 | import { areValidationErrors } from './utils' | 7 | import { areValidationErrors } from './shared' |
8 | 8 | ||
9 | const updateActorImageValidatorFactory = (fieldname: string) => ([ | 9 | const 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 @@ | |||
1 | import { body, param } from 'express-validator' | ||
2 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body, param } from 'express-validator' | ||
3 | import { getServerActor } from '@server/models/application/application' | ||
4 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
5 | import { isHostValid } from '../../helpers/custom-validators/servers' | ||
3 | import { logger } from '../../helpers/logger' | 6 | import { logger } from '../../helpers/logger' |
4 | import { areValidationErrors } from './utils' | 7 | import { WEBSERVER } from '../../initializers/constants' |
5 | import { AccountBlocklistModel } from '../../models/account/account-blocklist' | 8 | import { AccountBlocklistModel } from '../../models/account/account-blocklist' |
6 | import { isHostValid } from '../../helpers/custom-validators/servers' | ||
7 | import { ServerBlocklistModel } from '../../models/server/server-blocklist' | ||
8 | import { ServerModel } from '../../models/server/server' | 9 | import { ServerModel } from '../../models/server/server' |
9 | import { WEBSERVER } from '../../initializers/constants' | 10 | import { ServerBlocklistModel } from '../../models/server/server-blocklist' |
10 | import { doesAccountNameWithHostExist } from '../../helpers/middlewares' | 11 | import { areValidationErrors, doesAccountNameWithHostExist } from './shared' |
11 | import { getServerActor } from '@server/models/application/application' | ||
12 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
13 | 12 | ||
14 | const blockAccountValidator = [ | 13 | const 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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body } from 'express-validator' | 2 | import { body } from 'express-validator' |
3 | import { isBulkRemoveCommentsOfScopeValid } from '@server/helpers/custom-validators/bulk' | 3 | import { isBulkRemoveCommentsOfScopeValid } from '@server/helpers/custom-validators/bulk' |
4 | import { doesAccountNameWithHostExist } from '@server/helpers/middlewares' | 4 | import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' |
5 | import { UserRight } from '@shared/models' | 5 | import { UserRight } from '@shared/models' |
6 | import { BulkRemoveCommentsOfBody } from '@shared/models/bulk/bulk-remove-comments-of-body.model' | 6 | import { BulkRemoveCommentsOfBody } from '@shared/models/bulk/bulk-remove-comments-of-body.model' |
7 | import { logger } from '../../helpers/logger' | 7 | import { logger } from '../../helpers/logger' |
8 | import { areValidationErrors } from './utils' | 8 | import { areValidationErrors, doesAccountNameWithHostExist } from './shared' |
9 | import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' | ||
10 | 9 | ||
11 | const bulkRemoveCommentsOfValidator = [ | 10 | const 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' | |||
7 | import { isUserNSFWPolicyValid, isUserVideoQuotaDailyValid, isUserVideoQuotaValid } from '../../helpers/custom-validators/users' | 7 | import { isUserNSFWPolicyValid, isUserVideoQuotaDailyValid, isUserVideoQuotaValid } from '../../helpers/custom-validators/users' |
8 | import { logger } from '../../helpers/logger' | 8 | import { logger } from '../../helpers/logger' |
9 | import { isThemeRegistered } from '../../lib/plugins/theme-utils' | 9 | import { isThemeRegistered } from '../../lib/plugins/theme-utils' |
10 | import { areValidationErrors } from './utils' | 10 | import { areValidationErrors } from './shared' |
11 | 11 | ||
12 | const customConfigUpdateValidator = [ | 12 | const 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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { param, query } from 'express-validator' | 2 | import { param, query } from 'express-validator' |
3 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
3 | import { isValidRSSFeed } from '../../helpers/custom-validators/feeds' | 4 | import { isValidRSSFeed } from '../../helpers/custom-validators/feeds' |
4 | import { exists, isIdOrUUIDValid, isIdValid } from '../../helpers/custom-validators/misc' | 5 | import { exists, isIdOrUUIDValid, isIdValid } from '../../helpers/custom-validators/misc' |
5 | import { logger } from '../../helpers/logger' | 6 | import { logger } from '../../helpers/logger' |
6 | import { | 7 | import { |
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 |
13 | import { doesVideoExist } from '../../helpers/middlewares/videos' | 15 | } from './shared' |
14 | import { areValidationErrors } from './utils' | ||
15 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
16 | 16 | ||
17 | const feedsFormatValidator = [ | 17 | const 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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body, param, query } from 'express-validator' | 2 | import { body, param, query } from 'express-validator' |
3 | import { isFollowStateValid } from '@server/helpers/custom-validators/follows' | 3 | import { isFollowStateValid } from '@server/helpers/custom-validators/follows' |
4 | import { loadActorUrlOrGetFromWebfinger } from '@server/lib/activitypub/actors' | ||
4 | import { getServerActor } from '@server/models/application/application' | 5 | import { getServerActor } from '@server/models/application/application' |
5 | import { MActorFollowActorsDefault } from '@server/types/models' | 6 | import { MActorFollowActorsDefault } from '@server/types/models' |
6 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | 7 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' |
@@ -8,11 +9,10 @@ import { isTestInstance } from '../../helpers/core-utils' | |||
8 | import { isActorTypeValid, isValidActorHandle } from '../../helpers/custom-validators/activitypub/actor' | 9 | import { isActorTypeValid, isValidActorHandle } from '../../helpers/custom-validators/activitypub/actor' |
9 | import { isEachUniqueHostValid, isHostValid } from '../../helpers/custom-validators/servers' | 10 | import { isEachUniqueHostValid, isHostValid } from '../../helpers/custom-validators/servers' |
10 | import { logger } from '../../helpers/logger' | 11 | import { logger } from '../../helpers/logger' |
11 | import { loadActorUrlOrGetFromWebfinger } from '../../helpers/webfinger' | ||
12 | import { SERVER_ACTOR_NAME, WEBSERVER } from '../../initializers/constants' | 12 | import { SERVER_ACTOR_NAME, WEBSERVER } from '../../initializers/constants' |
13 | import { ActorModel } from '../../models/actor/actor' | 13 | import { ActorModel } from '../../models/actor/actor' |
14 | import { ActorFollowModel } from '../../models/actor/actor-follow' | 14 | import { ActorFollowModel } from '../../models/actor/actor-follow' |
15 | import { areValidationErrors } from './utils' | 15 | import { areValidationErrors } from './shared' |
16 | 16 | ||
17 | const listFollowsValidator = [ | 17 | const 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' | |||
2 | import { param, query } from 'express-validator' | 2 | import { param, query } from 'express-validator' |
3 | import { isValidJobState, isValidJobType } from '../../helpers/custom-validators/jobs' | 3 | import { isValidJobState, isValidJobType } from '../../helpers/custom-validators/jobs' |
4 | import { logger, loggerTagsFactory } from '../../helpers/logger' | 4 | import { logger, loggerTagsFactory } from '../../helpers/logger' |
5 | import { areValidationErrors } from './utils' | 5 | import { areValidationErrors } from './shared' |
6 | 6 | ||
7 | const lTags = loggerTagsFactory('validators', 'jobs') | 7 | const 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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { logger } from '../../helpers/logger' | ||
3 | import { areValidationErrors } from './utils' | ||
4 | import { isDateValid } from '../../helpers/custom-validators/misc' | ||
5 | import { query } from 'express-validator' | 2 | import { query } from 'express-validator' |
6 | import { isValidLogLevel } from '../../helpers/custom-validators/logs' | 3 | import { isValidLogLevel } from '../../helpers/custom-validators/logs' |
4 | import { isDateValid } from '../../helpers/custom-validators/misc' | ||
5 | import { logger } from '../../helpers/logger' | ||
6 | import { areValidationErrors } from './shared' | ||
7 | 7 | ||
8 | const getLogsValidator = [ | 8 | const 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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { query } from 'express-validator' | 2 | import { query } from 'express-validator' |
3 | import { join } from 'path' | 3 | import { join } from 'path' |
4 | import { fetchVideo } from '@server/helpers/video' | 4 | import { fetchVideo } from '@server/lib/model-loaders' |
5 | import { VideoPlaylistModel } from '@server/models/video/video-playlist' | 5 | import { VideoPlaylistModel } from '@server/models/video/video-playlist' |
6 | import { VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models' | 6 | import { VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models' |
7 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | 7 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' |
@@ -9,7 +9,7 @@ import { isTestInstance } from '../../helpers/core-utils' | |||
9 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' | 9 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' |
10 | import { logger } from '../../helpers/logger' | 10 | import { logger } from '../../helpers/logger' |
11 | import { WEBSERVER } from '../../initializers/constants' | 11 | import { WEBSERVER } from '../../initializers/constants' |
12 | import { areValidationErrors } from './utils' | 12 | import { areValidationErrors } from './shared' |
13 | 13 | ||
14 | const playlistPaths = [ | 14 | const 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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { query } from 'express-validator' | 2 | import { query } from 'express-validator' |
3 | import { logger } from '../../helpers/logger' | ||
4 | import { areValidationErrors } from './utils' | ||
5 | import { PAGINATION } from '@server/initializers/constants' | 3 | import { PAGINATION } from '@server/initializers/constants' |
4 | import { logger } from '../../helpers/logger' | ||
5 | import { areValidationErrors } from './shared' | ||
6 | 6 | ||
7 | const paginationValidator = paginationValidatorBuilder() | 7 | const 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' | |||
9 | import { CONFIG } from '../../initializers/config' | 9 | import { CONFIG } from '../../initializers/config' |
10 | import { PluginManager } from '../../lib/plugins/plugin-manager' | 10 | import { PluginManager } from '../../lib/plugins/plugin-manager' |
11 | import { PluginModel } from '../../models/server/plugin' | 11 | import { PluginModel } from '../../models/server/plugin' |
12 | import { areValidationErrors } from './utils' | 12 | import { areValidationErrors } from './shared' |
13 | 13 | ||
14 | const getPluginValidator = (pluginType: PluginType, withVersion = true) => { | 14 | const 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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body, param, query } from 'express-validator' | 2 | import { body, param, query } from 'express-validator' |
3 | import { isVideoRedundancyTarget } from '@server/helpers/custom-validators/video-redundancies' | ||
4 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
3 | import { exists, isBooleanValid, isIdOrUUIDValid, isIdValid, toBooleanOrNull, toIntOrNull } from '../../helpers/custom-validators/misc' | 5 | import { exists, isBooleanValid, isIdOrUUIDValid, isIdValid, toBooleanOrNull, toIntOrNull } from '../../helpers/custom-validators/misc' |
6 | import { isHostValid } from '../../helpers/custom-validators/servers' | ||
4 | import { logger } from '../../helpers/logger' | 7 | import { logger } from '../../helpers/logger' |
5 | import { areValidationErrors } from './utils' | ||
6 | import { VideoRedundancyModel } from '../../models/redundancy/video-redundancy' | 8 | import { VideoRedundancyModel } from '../../models/redundancy/video-redundancy' |
7 | import { isHostValid } from '../../helpers/custom-validators/servers' | ||
8 | import { ServerModel } from '../../models/server/server' | 9 | import { ServerModel } from '../../models/server/server' |
9 | import { doesVideoExist } from '../../helpers/middlewares' | 10 | import { areValidationErrors, doesVideoExist } from './shared' |
10 | import { isVideoRedundancyTarget } from '@server/helpers/custom-validators/video-redundancies' | ||
11 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
12 | 11 | ||
13 | const videoFileRedundancyGetValidator = [ | 12 | const 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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { areValidationErrors } from './utils' | ||
3 | import { logger } from '../../helpers/logger' | ||
4 | import { query } from 'express-validator' | 2 | import { query } from 'express-validator' |
5 | import { isDateValid } from '../../helpers/custom-validators/misc' | ||
6 | import { isSearchTargetValid } from '@server/helpers/custom-validators/search' | 3 | import { isSearchTargetValid } from '@server/helpers/custom-validators/search' |
4 | import { isDateValid } from '../../helpers/custom-validators/misc' | ||
5 | import { logger } from '../../helpers/logger' | ||
6 | import { areValidationErrors } from './shared' | ||
7 | 7 | ||
8 | const videosSearchValidator = [ | 8 | const 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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { logger } from '../../helpers/logger' | ||
3 | import { areValidationErrors } from './utils' | ||
4 | import { isHostValid, isValidContactBody } from '../../helpers/custom-validators/servers' | ||
5 | import { ServerModel } from '../../models/server/server' | ||
6 | import { body } from 'express-validator' | 2 | import { body } from 'express-validator' |
3 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
4 | import { isHostValid, isValidContactBody } from '../../helpers/custom-validators/servers' | ||
7 | import { isUserDisplayNameValid } from '../../helpers/custom-validators/users' | 5 | import { isUserDisplayNameValid } from '../../helpers/custom-validators/users' |
8 | import { Redis } from '../../lib/redis' | 6 | import { logger } from '../../helpers/logger' |
9 | import { CONFIG, isEmailEnabled } from '../../initializers/config' | 7 | import { CONFIG, isEmailEnabled } from '../../initializers/config' |
10 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | 8 | import { Redis } from '../../lib/redis' |
9 | import { ServerModel } from '../../models/server/server' | ||
10 | import { areValidationErrors } from './shared' | ||
11 | 11 | ||
12 | const serverGetValidator = [ | 12 | const 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 @@ | |||
1 | import { Response } from 'express' | 1 | import { Response } from 'express' |
2 | import { AbuseModel } from '../../models/abuse/abuse' | 2 | import { AbuseModel } from '@server/models/abuse/abuse' |
3 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | 3 | import { HttpStatusCode } from '@shared/core-utils' |
4 | 4 | ||
5 | async function doesAbuseExist (abuseId: number | string, res: Response) { | 5 | async 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 @@ | |||
1 | import { Response } from 'express' | 1 | import { Response } from 'express' |
2 | import { AccountModel } from '@server/models/account/account' | ||
2 | import { UserModel } from '@server/models/user/user' | 3 | import { UserModel } from '@server/models/user/user' |
3 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | 4 | import { MAccountDefault } from '@server/types/models' |
4 | import { AccountModel } from '../../models/account/account' | 5 | import { HttpStatusCode } from '@shared/core-utils' |
5 | import { MAccountDefault } from '../../types/models' | ||
6 | 6 | ||
7 | function doesAccountIdExist (id: number | string, res: Response, sendNotFound = true) { | 7 | function 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 @@ | |||
1 | export * from './abuses' | 1 | export * from './abuses' |
2 | export * from './accounts' | 2 | export * from './accounts' |
3 | export * from './utils' | ||
3 | export * from './video-blacklists' | 4 | export * from './video-blacklists' |
4 | export * from './video-captions' | 5 | export * from './video-captions' |
5 | export * from './video-channels' | 6 | export * from './video-channels' |
7 | export * from './video-comments' | ||
8 | export * from './video-imports' | ||
9 | export * from './video-ownerships' | ||
6 | export * from './video-playlists' | 10 | export * from './video-playlists' |
7 | export * from './videos' | 11 | export * 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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { query, validationResult } from 'express-validator' | 2 | import { query, validationResult } from 'express-validator' |
3 | import { logger } from '../../helpers/logger' | 3 | import { logger } from '../../../helpers/logger' |
4 | 4 | ||
5 | function areValidationErrors (req: express.Request, res: express.Response) { | 5 | function 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 @@ | |||
1 | import { Response } from 'express' | 1 | import { Response } from 'express' |
2 | import { VideoBlacklistModel } from '../../models/video/video-blacklist' | 2 | import { VideoBlacklistModel } from '@server/models/video/video-blacklist' |
3 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | 3 | import { HttpStatusCode } from '@shared/core-utils' |
4 | 4 | ||
5 | async function doesVideoBlacklistExist (videoId: number, res: Response) { | 5 | async 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 @@ | |||
1 | import { Response } from 'express' | 1 | import { Response } from 'express' |
2 | import { VideoCaptionModel } from '../../models/video/video-caption' | 2 | import { VideoCaptionModel } from '@server/models/video/video-caption' |
3 | import { MVideoId } from '@server/types/models' | 3 | import { MVideoId } from '@server/types/models' |
4 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | 4 | import { HttpStatusCode } from '@shared/core-utils' |
5 | 5 | ||
6 | async function doesVideoCaptionExist (video: MVideoId, language: string, res: Response) { | 6 | async 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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { VideoChannelModel } from '@server/models/video/video-channel' | ||
2 | import { MChannelBannerAccountDefault } from '@server/types/models' | 3 | import { MChannelBannerAccountDefault } from '@server/types/models' |
3 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | 4 | import { HttpStatusCode } from '@shared/core-utils' |
4 | import { VideoChannelModel } from '../../models/video/video-channel' | ||
5 | 5 | ||
6 | async function doesLocalVideoChannelNameExist (name: string, res: express.Response) { | 6 | async 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 @@ | |||
1 | import * as express from 'express' | ||
2 | import { VideoCommentModel } from '@server/models/video/video-comment' | ||
3 | import { MVideoId } from '@server/types/models' | ||
4 | import { HttpStatusCode } from '@shared/core-utils' | ||
5 | |||
6 | async 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 | |||
32 | async 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 | |||
53 | async 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 | |||
69 | export { | ||
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 @@ | |||
1 | import * as express from 'express' | ||
2 | import { VideoImportModel } from '@server/models/video/video-import' | ||
3 | import { HttpStatusCode } from '@shared/core-utils' | ||
4 | |||
5 | async 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 | |||
20 | export { | ||
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 @@ | |||
1 | import * as express from 'express' | ||
2 | import { VideoChangeOwnershipModel } from '@server/models/video/video-change-ownership' | ||
3 | import { HttpStatusCode } from '@shared/core-utils' | ||
4 | |||
5 | async 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 | |||
22 | export { | ||
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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { VideoPlaylistModel } from '../../models/video/video-playlist' | 2 | import { VideoPlaylistModel } from '@server/models/video/video-playlist' |
3 | import { MVideoPlaylist } from '../../types/models/video/video-playlist' | 3 | import { MVideoPlaylist } from '@server/types/models' |
4 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | 4 | import { HttpStatusCode } from '@shared/core-utils' |
5 | 5 | ||
6 | export type VideoPlaylistFetchType = 'summary' | 'all' | 6 | export type VideoPlaylistFetchType = 'summary' | 'all' |
7 | async function doesVideoPlaylistExist (id: number | string, res: express.Response, fetchType: VideoPlaylistFetchType = 'summary') { | 7 | async 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 @@ | |||
1 | import { Response } from 'express' | 1 | import { Response } from 'express' |
2 | import { fetchVideo, VideoFetchType } from '../video' | 2 | import { fetchVideo, VideoFetchType } from '@server/lib/model-loaders' |
3 | import { UserRight } from '../../../shared/models/users' | 3 | import { VideoChannelModel } from '@server/models/video/video-channel' |
4 | import { VideoChannelModel } from '../../models/video/video-channel' | 4 | import { VideoFileModel } from '@server/models/video/video-file' |
5 | import { | 5 | import { |
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' |
15 | import { VideoFileModel } from '@server/models/video/video-file' | 15 | import { HttpStatusCode } from '@shared/core-utils' |
16 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | 16 | import { UserRight } from '@shared/models' |
17 | 17 | ||
18 | async function doesVideoExist (id: number | string, res: Response, fetchType: VideoFetchType = 'all') { | 18 | async 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 @@ | |||
1 | import { SORTABLE_COLUMNS } from '../../initializers/constants' | 1 | import { SORTABLE_COLUMNS } from '../../initializers/constants' |
2 | import { checkSort, createSortableColumns } from './utils' | 2 | import { checkSort, createSortableColumns } from './shared' |
3 | 3 | ||
4 | // Initialize constants here for better performances | 4 | // Initialize constants here for better performances |
5 | const SORTABLE_USERS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.USERS) | 5 | const 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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { param } from 'express-validator' | 2 | import { param } from 'express-validator' |
3 | import { logger } from '../../helpers/logger' | 3 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' |
4 | import { areValidationErrors } from './utils' | 4 | import { isSafePath } from '../../helpers/custom-validators/misc' |
5 | import { isPluginNameValid, isPluginVersionValid } from '../../helpers/custom-validators/plugins' | 5 | import { isPluginNameValid, isPluginVersionValid } from '../../helpers/custom-validators/plugins' |
6 | import { logger } from '../../helpers/logger' | ||
6 | import { PluginManager } from '../../lib/plugins/plugin-manager' | 7 | import { PluginManager } from '../../lib/plugins/plugin-manager' |
7 | import { isSafePath } from '../../helpers/custom-validators/misc' | 8 | import { areValidationErrors } from './shared' |
8 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
9 | 9 | ||
10 | const serveThemeCSSValidator = [ | 10 | const 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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body, query } from 'express-validator' | 2 | import { body, query } from 'express-validator' |
3 | import { logger } from '../../helpers/logger' | ||
4 | import { areValidationErrors } from './utils' | ||
5 | import { exists, isDateValid } from '../../helpers/custom-validators/misc' | 3 | import { exists, isDateValid } from '../../helpers/custom-validators/misc' |
4 | import { logger } from '../../helpers/logger' | ||
5 | import { areValidationErrors } from './shared' | ||
6 | 6 | ||
7 | const userHistoryListValidator = [ | 7 | const 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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body, query } from 'express-validator' | 2 | import { body, query } from 'express-validator' |
3 | import { logger } from '../../helpers/logger' | ||
4 | import { areValidationErrors } from './utils' | ||
5 | import { isUserNotificationSettingValid } from '../../helpers/custom-validators/user-notifications' | ||
6 | import { isNotEmptyIntArray, toBooleanOrNull } from '../../helpers/custom-validators/misc' | 3 | import { isNotEmptyIntArray, toBooleanOrNull } from '../../helpers/custom-validators/misc' |
4 | import { isUserNotificationSettingValid } from '../../helpers/custom-validators/user-notifications' | ||
5 | import { logger } from '../../helpers/logger' | ||
6 | import { areValidationErrors } from './shared' | ||
7 | 7 | ||
8 | const listUserNotificationsValidator = [ | 8 | const 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' | |||
6 | import { logger } from '../../helpers/logger' | 6 | import { logger } from '../../helpers/logger' |
7 | import { WEBSERVER } from '../../initializers/constants' | 7 | import { WEBSERVER } from '../../initializers/constants' |
8 | import { ActorFollowModel } from '../../models/actor/actor-follow' | 8 | import { ActorFollowModel } from '../../models/actor/actor-follow' |
9 | import { areValidationErrors } from './utils' | 9 | import { areValidationErrors } from './shared' |
10 | 10 | ||
11 | const userSubscriptionListValidator = [ | 11 | const 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' |
31 | import { isVideoChannelNameValid } from '../../helpers/custom-validators/video-channels' | 31 | import { isVideoChannelNameValid } from '../../helpers/custom-validators/video-channels' |
32 | import { logger } from '../../helpers/logger' | 32 | import { logger } from '../../helpers/logger' |
33 | import { doesVideoExist } from '../../helpers/middlewares' | ||
34 | import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../helpers/signup' | ||
35 | import { isThemeRegistered } from '../../lib/plugins/theme-utils' | 33 | import { isThemeRegistered } from '../../lib/plugins/theme-utils' |
36 | import { Redis } from '../../lib/redis' | 34 | import { Redis } from '../../lib/redis' |
37 | import { UserModel } from '../../models/user/user' | 35 | import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../lib/signup' |
38 | import { ActorModel } from '../../models/actor/actor' | 36 | import { ActorModel } from '../../models/actor/actor' |
39 | import { areValidationErrors } from './utils' | 37 | import { UserModel } from '../../models/user/user' |
38 | import { areValidationErrors, doesVideoExist } from './shared' | ||
40 | 39 | ||
41 | const usersListValidator = [ | 40 | const 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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body, param, query } from 'express-validator' | 2 | import { body, param, query } from 'express-validator' |
3 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
3 | import { isBooleanValid, isIdOrUUIDValid, toBooleanOrNull, toIntOrNull } from '../../../helpers/custom-validators/misc' | 4 | import { isBooleanValid, isIdOrUUIDValid, toBooleanOrNull, toIntOrNull } from '../../../helpers/custom-validators/misc' |
4 | import { isVideoBlacklistReasonValid, isVideoBlacklistTypeValid } from '../../../helpers/custom-validators/video-blacklist' | 5 | import { isVideoBlacklistReasonValid, isVideoBlacklistTypeValid } from '../../../helpers/custom-validators/video-blacklist' |
5 | import { logger } from '../../../helpers/logger' | 6 | import { logger } from '../../../helpers/logger' |
6 | import { doesVideoBlacklistExist, doesVideoExist } from '../../../helpers/middlewares' | 7 | import { areValidationErrors, doesVideoBlacklistExist, doesVideoExist } from '../shared' |
7 | import { areValidationErrors } from '../utils' | ||
8 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
9 | 8 | ||
10 | const videosBlacklistRemoveValidator = [ | 9 | const 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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { areValidationErrors } from '../utils' | ||
3 | import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc' | ||
4 | import { body, param } from 'express-validator' | 2 | import { body, param } from 'express-validator' |
5 | import { CONSTRAINTS_FIELDS, MIMETYPES } from '../../../initializers/constants' | ||
6 | import { UserRight } from '../../../../shared' | 3 | import { UserRight } from '../../../../shared' |
7 | import { logger } from '../../../helpers/logger' | 4 | import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc' |
8 | import { isVideoCaptionFile, isVideoCaptionLanguageValid } from '../../../helpers/custom-validators/video-captions' | 5 | import { isVideoCaptionFile, isVideoCaptionLanguageValid } from '../../../helpers/custom-validators/video-captions' |
9 | import { cleanUpReqFiles } from '../../../helpers/express-utils' | 6 | import { cleanUpReqFiles } from '../../../helpers/express-utils' |
10 | import { checkUserCanManageVideo, doesVideoCaptionExist, doesVideoExist } from '../../../helpers/middlewares' | 7 | import { logger } from '../../../helpers/logger' |
8 | import { CONSTRAINTS_FIELDS, MIMETYPES } from '../../../initializers/constants' | ||
9 | import { areValidationErrors, checkUserCanManageVideo, doesVideoCaptionExist, doesVideoExist } from '../shared' | ||
11 | 10 | ||
12 | const addVideoCaptionValidator = [ | 11 | const 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' |
14 | import { logger } from '../../../helpers/logger' | 14 | import { logger } from '../../../helpers/logger' |
15 | import { doesLocalVideoChannelNameExist, doesVideoChannelNameWithHostExist } from '../../../helpers/middlewares' | ||
16 | import { ActorModel } from '../../../models/actor/actor' | 15 | import { ActorModel } from '../../../models/actor/actor' |
17 | import { VideoChannelModel } from '../../../models/video/video-channel' | 16 | import { VideoChannelModel } from '../../../models/video/video-channel' |
18 | import { areValidationErrors } from '../utils' | 17 | import { areValidationErrors, doesLocalVideoChannelNameExist, doesVideoChannelNameWithHostExist } from '../shared' |
19 | 18 | ||
20 | const videoChannelsAddValidator = [ | 19 | const 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' | |||
2 | import { body, param, query } from 'express-validator' | 2 | import { body, param, query } from 'express-validator' |
3 | import { MUserAccountUrl } from '@server/types/models' | 3 | import { MUserAccountUrl } from '@server/types/models' |
4 | import { UserRight } from '../../../../shared' | 4 | import { UserRight } from '../../../../shared' |
5 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
5 | import { exists, isBooleanValid, isIdOrUUIDValid, isIdValid, toBooleanOrNull } from '../../../helpers/custom-validators/misc' | 6 | import { exists, isBooleanValid, isIdOrUUIDValid, isIdValid, toBooleanOrNull } from '../../../helpers/custom-validators/misc' |
6 | import { | 7 | import { isValidVideoCommentText } from '../../../helpers/custom-validators/video-comments' |
7 | doesVideoCommentExist, | ||
8 | doesVideoCommentThreadExist, | ||
9 | isValidVideoCommentText | ||
10 | } from '../../../helpers/custom-validators/video-comments' | ||
11 | import { logger } from '../../../helpers/logger' | 8 | import { logger } from '../../../helpers/logger' |
12 | import { doesVideoExist } from '../../../helpers/middlewares' | ||
13 | import { AcceptResult, isLocalVideoCommentReplyAccepted, isLocalVideoThreadAccepted } from '../../../lib/moderation' | 9 | import { AcceptResult, isLocalVideoCommentReplyAccepted, isLocalVideoThreadAccepted } from '../../../lib/moderation' |
14 | import { Hooks } from '../../../lib/plugins/hooks' | 10 | import { Hooks } from '../../../lib/plugins/hooks' |
15 | import { MCommentOwnerVideoReply, MVideo, MVideoFullLight } from '../../../types/models/video' | 11 | import { MCommentOwnerVideoReply, MVideo, MVideoFullLight } from '../../../types/models/video' |
16 | import { areValidationErrors } from '../utils' | 12 | import { areValidationErrors, doesVideoCommentExist, doesVideoCommentThreadExist, doesVideoExist } from '../shared' |
17 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
18 | 13 | ||
19 | const listVideoCommentsValidator = [ | 14 | const 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' | |||
2 | import { body } from 'express-validator' | 2 | import { body } from 'express-validator' |
3 | import { isPreImportVideoAccepted } from '@server/lib/moderation' | 3 | import { isPreImportVideoAccepted } from '@server/lib/moderation' |
4 | import { Hooks } from '@server/lib/plugins/hooks' | 4 | import { Hooks } from '@server/lib/plugins/hooks' |
5 | import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' | ||
5 | import { VideoImportCreate } from '@shared/models/videos/import/video-import-create.model' | 6 | import { VideoImportCreate } from '@shared/models/videos/import/video-import-create.model' |
6 | import { isIdValid, toIntOrNull } from '../../../helpers/custom-validators/misc' | 7 | import { isIdValid, toIntOrNull } from '../../../helpers/custom-validators/misc' |
7 | import { isVideoImportTargetUrlValid, isVideoImportTorrentFile } from '../../../helpers/custom-validators/video-imports' | 8 | import { isVideoImportTargetUrlValid, isVideoImportTorrentFile } from '../../../helpers/custom-validators/video-imports' |
8 | import { isVideoMagnetUriValid, isVideoNameValid } from '../../../helpers/custom-validators/videos' | 9 | import { isVideoMagnetUriValid, isVideoNameValid } from '../../../helpers/custom-validators/videos' |
9 | import { cleanUpReqFiles } from '../../../helpers/express-utils' | 10 | import { cleanUpReqFiles } from '../../../helpers/express-utils' |
10 | import { logger } from '../../../helpers/logger' | 11 | import { logger } from '../../../helpers/logger' |
11 | import { doesVideoChannelOfAccountExist } from '../../../helpers/middlewares' | ||
12 | import { CONFIG } from '../../../initializers/config' | 12 | import { CONFIG } from '../../../initializers/config' |
13 | import { CONSTRAINTS_FIELDS } from '../../../initializers/constants' | 13 | import { CONSTRAINTS_FIELDS } from '../../../initializers/constants' |
14 | import { areValidationErrors } from '../utils' | 14 | import { areValidationErrors, doesVideoChannelOfAccountExist } from '../shared' |
15 | import { getCommonVideoEditAttributes } from './videos' | 15 | import { getCommonVideoEditAttributes } from './videos' |
16 | import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' | ||
17 | 16 | ||
18 | const videoImportAddValidator = getCommonVideoEditAttributes().concat([ | 17 | const 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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body, param } from 'express-validator' | 2 | import { body, param } from 'express-validator' |
3 | import { checkUserCanManageVideo, doesVideoChannelOfAccountExist, doesVideoExist } from '@server/helpers/middlewares/videos' | 3 | import { CONSTRAINTS_FIELDS } from '@server/initializers/constants' |
4 | import { isLocalLiveVideoAccepted } from '@server/lib/moderation' | ||
5 | import { Hooks } from '@server/lib/plugins/hooks' | ||
6 | import { VideoModel } from '@server/models/video/video' | ||
4 | import { VideoLiveModel } from '@server/models/video/video-live' | 7 | import { VideoLiveModel } from '@server/models/video/video-live' |
8 | import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' | ||
5 | import { ServerErrorCode, UserRight, VideoState } from '@shared/models' | 9 | import { ServerErrorCode, UserRight, VideoState } from '@shared/models' |
6 | import { isBooleanValid, isIdOrUUIDValid, isIdValid, toBooleanOrNull, toIntOrNull } from '../../../helpers/custom-validators/misc' | 10 | import { isBooleanValid, isIdOrUUIDValid, isIdValid, toBooleanOrNull, toIntOrNull } from '../../../helpers/custom-validators/misc' |
7 | import { isVideoNameValid } from '../../../helpers/custom-validators/videos' | 11 | import { isVideoNameValid } from '../../../helpers/custom-validators/videos' |
8 | import { cleanUpReqFiles } from '../../../helpers/express-utils' | 12 | import { cleanUpReqFiles } from '../../../helpers/express-utils' |
9 | import { logger } from '../../../helpers/logger' | 13 | import { logger } from '../../../helpers/logger' |
10 | import { CONFIG } from '../../../initializers/config' | 14 | import { CONFIG } from '../../../initializers/config' |
11 | import { areValidationErrors } from '../utils' | 15 | import { areValidationErrors, checkUserCanManageVideo, doesVideoChannelOfAccountExist, doesVideoExist } from '../shared' |
12 | import { getCommonVideoEditAttributes } from './videos' | 16 | import { getCommonVideoEditAttributes } from './videos' |
13 | import { VideoModel } from '@server/models/video/video' | ||
14 | import { Hooks } from '@server/lib/plugins/hooks' | ||
15 | import { isLocalLiveVideoAccepted } from '@server/lib/moderation' | ||
16 | import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' | ||
17 | import { CONSTRAINTS_FIELDS } from '@server/initializers/constants' | ||
18 | 17 | ||
19 | const videoLiveGetValidator = [ | 18 | const 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 { | |||
25 | import { isVideoImage } from '../../../helpers/custom-validators/videos' | 25 | import { isVideoImage } from '../../../helpers/custom-validators/videos' |
26 | import { cleanUpReqFiles } from '../../../helpers/express-utils' | 26 | import { cleanUpReqFiles } from '../../../helpers/express-utils' |
27 | import { logger } from '../../../helpers/logger' | 27 | import { logger } from '../../../helpers/logger' |
28 | import { doesVideoChannelIdExist, doesVideoExist, doesVideoPlaylistExist, VideoPlaylistFetchType } from '../../../helpers/middlewares' | ||
29 | import { CONSTRAINTS_FIELDS } from '../../../initializers/constants' | 28 | import { CONSTRAINTS_FIELDS } from '../../../initializers/constants' |
30 | import { VideoPlaylistElementModel } from '../../../models/video/video-playlist-element' | 29 | import { VideoPlaylistElementModel } from '../../../models/video/video-playlist-element' |
31 | import { MVideoPlaylist } from '../../../types/models/video/video-playlist' | 30 | import { MVideoPlaylist } from '../../../types/models/video/video-playlist' |
32 | import { authenticatePromiseIfNeeded } from '../../auth' | 31 | import { authenticatePromiseIfNeeded } from '../../auth' |
33 | import { areValidationErrors } from '../utils' | 32 | import { areValidationErrors, doesVideoChannelIdExist, doesVideoExist, doesVideoPlaylistExist, VideoPlaylistFetchType } from '../shared' |
34 | 33 | ||
35 | const videoPlaylistsAddValidator = getCommonPlaylistEditAttributes().concat([ | 34 | const 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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body, param, query } from 'express-validator' | 2 | import { body, param, query } from 'express-validator' |
3 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
4 | import { VideoRateType } from '../../../../shared/models/videos' | ||
5 | import { isAccountNameValid } from '../../../helpers/custom-validators/accounts' | ||
3 | import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' | 6 | import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' |
4 | import { isRatingValid } from '../../../helpers/custom-validators/video-rates' | 7 | import { isRatingValid } from '../../../helpers/custom-validators/video-rates' |
5 | import { isVideoRatingTypeValid } from '../../../helpers/custom-validators/videos' | 8 | import { isVideoRatingTypeValid } from '../../../helpers/custom-validators/videos' |
6 | import { logger } from '../../../helpers/logger' | 9 | import { logger } from '../../../helpers/logger' |
7 | import { areValidationErrors } from '../utils' | ||
8 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' | 10 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' |
9 | import { VideoRateType } from '../../../../shared/models/videos' | 11 | import { areValidationErrors, doesVideoExist } from '../shared' |
10 | import { isAccountNameValid } from '../../../helpers/custom-validators/accounts' | ||
11 | import { doesVideoExist } from '../../../helpers/middlewares' | ||
12 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
13 | 12 | ||
14 | const videoUpdateRateValidator = [ | 13 | const 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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { param } from 'express-validator' | 2 | import { param } from 'express-validator' |
3 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
3 | import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' | 4 | import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' |
4 | import { logger } from '../../../helpers/logger' | 5 | import { logger } from '../../../helpers/logger' |
5 | import { VideoShareModel } from '../../../models/video/video-share' | 6 | import { VideoShareModel } from '../../../models/video/video-share' |
6 | import { areValidationErrors } from '../utils' | 7 | import { areValidationErrors, doesVideoExist } from '../shared' |
7 | import { doesVideoExist } from '../../../helpers/middlewares' | ||
8 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
9 | 8 | ||
10 | const videosShareValidator = [ | 9 | const 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 @@ | |||
1 | import { body, param } from 'express-validator' | ||
2 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body, param } from 'express-validator' | ||
3 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
3 | import { isIdOrUUIDValid, toIntOrNull } from '../../../helpers/custom-validators/misc' | 4 | import { isIdOrUUIDValid, toIntOrNull } from '../../../helpers/custom-validators/misc' |
4 | import { areValidationErrors } from '../utils' | ||
5 | import { logger } from '../../../helpers/logger' | 5 | import { logger } from '../../../helpers/logger' |
6 | import { doesVideoExist } from '../../../helpers/middlewares' | 6 | import { areValidationErrors, doesVideoExist } from '../shared' |
7 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
8 | 7 | ||
9 | const videoWatchingValidator = [ | 8 | const 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' |
24 | import { isBooleanBothQueryValid, isNumberArray, isStringArray } from '../../../helpers/custom-validators/search' | 24 | import { isBooleanBothQueryValid, isNumberArray, isStringArray } from '../../../helpers/custom-validators/search' |
25 | import { checkUserCanTerminateOwnershipChange, doesChangeVideoOwnershipExist } from '../../../helpers/custom-validators/video-ownership' | 25 | import { checkUserCanTerminateOwnershipChange } from '../../../helpers/custom-validators/video-ownership' |
26 | import { | 26 | import { |
27 | isScheduleVideoUpdatePrivacyValid, | 27 | isScheduleVideoUpdatePrivacyValid, |
28 | isVideoCategoryValid, | 28 | isVideoCategoryValid, |
@@ -42,12 +42,6 @@ import { | |||
42 | import { cleanUpReqFiles } from '../../../helpers/express-utils' | 42 | import { cleanUpReqFiles } from '../../../helpers/express-utils' |
43 | import { getDurationFromVideoFile } from '../../../helpers/ffprobe-utils' | 43 | import { getDurationFromVideoFile } from '../../../helpers/ffprobe-utils' |
44 | import { logger } from '../../../helpers/logger' | 44 | import { logger } from '../../../helpers/logger' |
45 | import { | ||
46 | checkUserCanManageVideo, | ||
47 | doesVideoChannelOfAccountExist, | ||
48 | doesVideoExist, | ||
49 | doesVideoFileOfVideoExist | ||
50 | } from '../../../helpers/middlewares' | ||
51 | import { deleteFileAndCatch } from '../../../helpers/utils' | 45 | import { deleteFileAndCatch } from '../../../helpers/utils' |
52 | import { getVideoWithAttributes } from '../../../helpers/video' | 46 | import { getVideoWithAttributes } from '../../../helpers/video' |
53 | import { CONFIG } from '../../../initializers/config' | 47 | import { CONFIG } from '../../../initializers/config' |
@@ -57,7 +51,14 @@ import { Hooks } from '../../../lib/plugins/hooks' | |||
57 | import { AccountModel } from '../../../models/account/account' | 51 | import { AccountModel } from '../../../models/account/account' |
58 | import { VideoModel } from '../../../models/video/video' | 52 | import { VideoModel } from '../../../models/video/video' |
59 | import { authenticatePromiseIfNeeded } from '../../auth' | 53 | import { authenticatePromiseIfNeeded } from '../../auth' |
60 | import { areValidationErrors } from '../utils' | 54 | import { |
55 | areValidationErrors, | ||
56 | checkUserCanManageVideo, | ||
57 | doesChangeVideoOwnershipExist, | ||
58 | doesVideoChannelOfAccountExist, | ||
59 | doesVideoExist, | ||
60 | doesVideoFileOfVideoExist | ||
61 | } from '../shared' | ||
61 | 62 | ||
62 | const videosAddLegacyValidator = getCommonVideoEditAttributes().concat([ | 63 | const 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 | |||
5 | import { getHostWithPort } from '../../helpers/express-utils' | 5 | import { getHostWithPort } from '../../helpers/express-utils' |
6 | import { logger } from '../../helpers/logger' | 6 | import { logger } from '../../helpers/logger' |
7 | import { ActorModel } from '../../models/actor/actor' | 7 | import { ActorModel } from '../../models/actor/actor' |
8 | import { areValidationErrors } from './utils' | 8 | import { areValidationErrors } from './shared' |
9 | 9 | ||
10 | const webfingerValidator = [ | 10 | const 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'), |