From c0e8b12e7fd554ba4d2ceb0c4900804c6a4c63ea Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Jul 2021 10:42:24 +0200 Subject: Refactor requests --- server/middlewares/activitypub.ts | 2 +- server/middlewares/auth.ts | 2 +- server/middlewares/cache.ts | 2 +- server/middlewares/error.ts | 2 +- server/middlewares/servers.ts | 2 +- server/middlewares/user-right.ts | 2 +- server/middlewares/validators/abuse.ts | 2 +- server/middlewares/validators/activitypub/activity.ts | 2 +- server/middlewares/validators/blocklist.ts | 2 +- server/middlewares/validators/bulk.ts | 2 +- server/middlewares/validators/feeds.ts | 2 +- server/middlewares/validators/follows.ts | 2 +- server/middlewares/validators/oembed.ts | 2 +- server/middlewares/validators/plugins.ts | 2 +- server/middlewares/validators/redundancy.ts | 2 +- server/middlewares/validators/server.ts | 2 +- server/middlewares/validators/shared/abuses.ts | 2 +- server/middlewares/validators/shared/accounts.ts | 2 +- server/middlewares/validators/shared/video-blacklists.ts | 2 +- server/middlewares/validators/shared/video-captions.ts | 2 +- server/middlewares/validators/shared/video-channels.ts | 2 +- server/middlewares/validators/shared/video-comments.ts | 2 +- server/middlewares/validators/shared/video-imports.ts | 2 +- server/middlewares/validators/shared/video-ownerships.ts | 2 +- server/middlewares/validators/shared/video-playlists.ts | 2 +- server/middlewares/validators/shared/videos.ts | 2 +- server/middlewares/validators/themes.ts | 2 +- server/middlewares/validators/user-subscriptions.ts | 2 +- server/middlewares/validators/users.ts | 2 +- server/middlewares/validators/videos/video-blacklist.ts | 2 +- server/middlewares/validators/videos/video-channels.ts | 2 +- server/middlewares/validators/videos/video-comments.ts | 2 +- server/middlewares/validators/videos/video-imports.ts | 2 +- server/middlewares/validators/videos/video-live.ts | 2 +- server/middlewares/validators/videos/video-ownership-changes.ts | 2 +- server/middlewares/validators/videos/video-playlists.ts | 2 +- server/middlewares/validators/videos/video-rates.ts | 2 +- server/middlewares/validators/videos/video-shares.ts | 2 +- server/middlewares/validators/videos/video-watch.ts | 2 +- server/middlewares/validators/videos/videos.ts | 2 +- server/middlewares/validators/webfinger.ts | 2 +- 41 files changed, 41 insertions(+), 41 deletions(-) (limited to 'server/middlewares') diff --git a/server/middlewares/activitypub.ts b/server/middlewares/activitypub.ts index 6b43b7764..6ef90b275 100644 --- a/server/middlewares/activitypub.ts +++ b/server/middlewares/activitypub.ts @@ -2,7 +2,7 @@ import { NextFunction, Request, Response } from 'express' import { getAPId } from '@server/helpers/activitypub' import { isActorDeleteActivityValid } from '@server/helpers/custom-validators/activitypub/actor' import { ActivityDelete, ActivityPubSignature } from '../../shared' -import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '../../shared/models/http/http-error-codes' import { logger } from '../helpers/logger' import { isHTTPSignatureVerified, isJsonLDSignatureVerified, parseHTTPSignature } from '../helpers/peertube-crypto' import { ACCEPT_HEADERS, ACTIVITY_PUB, HTTP_SIGNATURE } from '../initializers/constants' diff --git a/server/middlewares/auth.ts b/server/middlewares/auth.ts index 176461cc2..9e6327b23 100644 --- a/server/middlewares/auth.ts +++ b/server/middlewares/auth.ts @@ -1,7 +1,7 @@ import * as express from 'express' import { Socket } from 'socket.io' import { getAccessToken } from '@server/lib/auth/oauth-model' -import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '../../shared/models/http/http-error-codes' import { logger } from '../helpers/logger' import { handleOAuthAuthenticate } from '../lib/auth/oauth' diff --git a/server/middlewares/cache.ts b/server/middlewares/cache.ts index 0708ee8e8..1ced06042 100644 --- a/server/middlewares/cache.ts +++ b/server/middlewares/cache.ts @@ -1,6 +1,6 @@ import { Redis } from '../lib/redis' import * as apicache from 'apicache' -import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '../../shared/models/http/http-error-codes' // Ensure Redis is initialized Redis.Instance.init() diff --git a/server/middlewares/error.ts b/server/middlewares/error.ts index e3eb1c8f5..af5a9c29a 100644 --- a/server/middlewares/error.ts +++ b/server/middlewares/error.ts @@ -1,6 +1,6 @@ import * as express from 'express' import { ProblemDocument, ProblemDocumentExtension } from 'http-problem-details' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' function apiFailMiddleware (req: express.Request, res: express.Response, next: express.NextFunction) { res.fail = options => { diff --git a/server/middlewares/servers.ts b/server/middlewares/servers.ts index 9aa56bc93..49a2241b3 100644 --- a/server/middlewares/servers.ts +++ b/server/middlewares/servers.ts @@ -1,6 +1,6 @@ import * as express from 'express' import { getHostWithPort } from '../helpers/express-utils' -import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '../../shared/models/http/http-error-codes' function setBodyHostsPort (req: express.Request, res: express.Response, next: express.NextFunction) { if (!req.body.hosts) return next() diff --git a/server/middlewares/user-right.ts b/server/middlewares/user-right.ts index d1888c2d3..87a1766cf 100644 --- a/server/middlewares/user-right.ts +++ b/server/middlewares/user-right.ts @@ -1,7 +1,7 @@ import * as express from 'express' import { UserRight } from '../../shared' import { logger } from '../helpers/logger' -import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '../../shared/models/http/http-error-codes' function ensureUserHasRight (userRight: UserRight) { return function (req: express.Request, res: express.Response, next: express.NextFunction) { diff --git a/server/middlewares/validators/abuse.ts b/server/middlewares/validators/abuse.ts index c048bc6af..f4d9c3af2 100644 --- a/server/middlewares/validators/abuse.ts +++ b/server/middlewares/validators/abuse.ts @@ -16,7 +16,7 @@ import { exists, isIdOrUUIDValid, isIdValid, toCompleteUUID, toIntOrNull } from import { logger } from '@server/helpers/logger' import { AbuseMessageModel } from '@server/models/abuse/abuse-message' import { AbuseCreate, UserRight } from '@shared/models' -import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '../../../shared/models/http/http-error-codes' import { areValidationErrors, doesAbuseExist, doesAccountIdExist, doesCommentIdExist, doesVideoExist } from './shared' const abuseReportValidator = [ diff --git a/server/middlewares/validators/activitypub/activity.ts b/server/middlewares/validators/activitypub/activity.ts index cc6acd4b1..d65a8e455 100644 --- a/server/middlewares/validators/activitypub/activity.ts +++ b/server/middlewares/validators/activitypub/activity.ts @@ -2,7 +2,7 @@ import * as express from 'express' import { isRootActivityValid } from '../../../helpers/custom-validators/activitypub/activity' import { logger } from '../../../helpers/logger' import { getServerActor } from '@server/models/application/application' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' async function activityPubValidator (req: express.Request, res: express.Response, next: express.NextFunction) { logger.debug('Checking activity pub parameters') diff --git a/server/middlewares/validators/blocklist.ts b/server/middlewares/validators/blocklist.ts index 826b16fc8..f15b293e9 100644 --- a/server/middlewares/validators/blocklist.ts +++ b/server/middlewares/validators/blocklist.ts @@ -1,7 +1,7 @@ import * as express from 'express' import { body, param } from 'express-validator' import { getServerActor } from '@server/models/application/application' -import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '../../../shared/models/http/http-error-codes' import { isHostValid } from '../../helpers/custom-validators/servers' import { logger } from '../../helpers/logger' import { WEBSERVER } from '../../initializers/constants' diff --git a/server/middlewares/validators/bulk.ts b/server/middlewares/validators/bulk.ts index 9bb95f5b7..4057b1e01 100644 --- a/server/middlewares/validators/bulk.ts +++ b/server/middlewares/validators/bulk.ts @@ -1,7 +1,7 @@ import * as express from 'express' import { body } from 'express-validator' import { isBulkRemoveCommentsOfScopeValid } from '@server/helpers/custom-validators/bulk' -import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '@shared/models' import { UserRight } from '@shared/models' import { BulkRemoveCommentsOfBody } from '@shared/models/bulk/bulk-remove-comments-of-body.model' import { logger } from '../../helpers/logger' diff --git a/server/middlewares/validators/feeds.ts b/server/middlewares/validators/feeds.ts index 51b8fdd19..1a5a8ffa0 100644 --- a/server/middlewares/validators/feeds.ts +++ b/server/middlewares/validators/feeds.ts @@ -1,7 +1,7 @@ import * as express from 'express' import { param, query } from 'express-validator' -import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '../../../shared/models/http/http-error-codes' import { isValidRSSFeed } from '../../helpers/custom-validators/feeds' import { exists, isIdOrUUIDValid, isIdValid, toCompleteUUID } from '../../helpers/custom-validators/misc' import { logger } from '../../helpers/logger' diff --git a/server/middlewares/validators/follows.ts b/server/middlewares/validators/follows.ts index 205baca48..05cc66c38 100644 --- a/server/middlewares/validators/follows.ts +++ b/server/middlewares/validators/follows.ts @@ -4,7 +4,7 @@ import { isFollowStateValid } from '@server/helpers/custom-validators/follows' import { loadActorUrlOrGetFromWebfinger } from '@server/lib/activitypub/actors' import { getServerActor } from '@server/models/application/application' import { MActorFollowActorsDefault } from '@server/types/models' -import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '../../../shared/models/http/http-error-codes' import { isTestInstance } from '../../helpers/core-utils' import { isActorTypeValid, isValidActorHandle } from '../../helpers/custom-validators/activitypub/actor' import { isEachUniqueHostValid, isHostValid } from '../../helpers/custom-validators/servers' diff --git a/server/middlewares/validators/oembed.ts b/server/middlewares/validators/oembed.ts index 0a82e6932..e5fc0c277 100644 --- a/server/middlewares/validators/oembed.ts +++ b/server/middlewares/validators/oembed.ts @@ -4,7 +4,7 @@ import { join } from 'path' import { loadVideo } from '@server/lib/model-loaders' import { VideoPlaylistModel } from '@server/models/video/video-playlist' import { VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models' -import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '../../../shared/models/http/http-error-codes' import { isTestInstance } from '../../helpers/core-utils' import { isIdOrUUIDValid, toCompleteUUID } from '../../helpers/custom-validators/misc' import { logger } from '../../helpers/logger' diff --git a/server/middlewares/validators/plugins.ts b/server/middlewares/validators/plugins.ts index 8c76d2e36..3fb2176b9 100644 --- a/server/middlewares/validators/plugins.ts +++ b/server/middlewares/validators/plugins.ts @@ -1,6 +1,6 @@ import * as express from 'express' import { body, param, query, ValidationChain } from 'express-validator' -import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '../../../shared/models/http/http-error-codes' import { PluginType } from '../../../shared/models/plugins/plugin.type' import { InstallOrUpdatePlugin } from '../../../shared/models/plugins/server/api/install-plugin.model' import { exists, isBooleanValid, isSafePath, toBooleanOrNull, toIntOrNull } from '../../helpers/custom-validators/misc' diff --git a/server/middlewares/validators/redundancy.ts b/server/middlewares/validators/redundancy.ts index 116c8c611..f1b2ff5cd 100644 --- a/server/middlewares/validators/redundancy.ts +++ b/server/middlewares/validators/redundancy.ts @@ -1,7 +1,7 @@ import * as express from 'express' import { body, param, query } from 'express-validator' import { isVideoRedundancyTarget } from '@server/helpers/custom-validators/video-redundancies' -import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '../../../shared/models/http/http-error-codes' import { exists, isBooleanValid, diff --git a/server/middlewares/validators/server.ts b/server/middlewares/validators/server.ts index fc7239b25..29fdc13d2 100644 --- a/server/middlewares/validators/server.ts +++ b/server/middlewares/validators/server.ts @@ -1,6 +1,6 @@ import * as express from 'express' import { body } from 'express-validator' -import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '../../../shared/models/http/http-error-codes' import { isHostValid, isValidContactBody } from '../../helpers/custom-validators/servers' import { isUserDisplayNameValid } from '../../helpers/custom-validators/users' import { logger } from '../../helpers/logger' diff --git a/server/middlewares/validators/shared/abuses.ts b/server/middlewares/validators/shared/abuses.ts index 4a20a55fa..2b8d86ba5 100644 --- a/server/middlewares/validators/shared/abuses.ts +++ b/server/middlewares/validators/shared/abuses.ts @@ -1,6 +1,6 @@ import { Response } from 'express' import { AbuseModel } from '@server/models/abuse/abuse' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' async function doesAbuseExist (abuseId: number | string, res: Response) { const abuse = await AbuseModel.loadByIdWithReporter(parseInt(abuseId + '', 10)) diff --git a/server/middlewares/validators/shared/accounts.ts b/server/middlewares/validators/shared/accounts.ts index 04da15441..fe4f83aa0 100644 --- a/server/middlewares/validators/shared/accounts.ts +++ b/server/middlewares/validators/shared/accounts.ts @@ -2,7 +2,7 @@ import { Response } from 'express' import { AccountModel } from '@server/models/account/account' import { UserModel } from '@server/models/user/user' import { MAccountDefault } from '@server/types/models' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' function doesAccountIdExist (id: number | string, res: Response, sendNotFound = true) { const promise = AccountModel.load(parseInt(id + '', 10)) diff --git a/server/middlewares/validators/shared/video-blacklists.ts b/server/middlewares/validators/shared/video-blacklists.ts index 01491c10f..f85b39b23 100644 --- a/server/middlewares/validators/shared/video-blacklists.ts +++ b/server/middlewares/validators/shared/video-blacklists.ts @@ -1,6 +1,6 @@ import { Response } from 'express' import { VideoBlacklistModel } from '@server/models/video/video-blacklist' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' async function doesVideoBlacklistExist (videoId: number, res: Response) { const videoBlacklist = await VideoBlacklistModel.loadByVideoId(videoId) diff --git a/server/middlewares/validators/shared/video-captions.ts b/server/middlewares/validators/shared/video-captions.ts index 80f6c5a52..831b366ea 100644 --- a/server/middlewares/validators/shared/video-captions.ts +++ b/server/middlewares/validators/shared/video-captions.ts @@ -1,7 +1,7 @@ import { Response } from 'express' import { VideoCaptionModel } from '@server/models/video/video-caption' import { MVideoId } from '@server/types/models' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' async function doesVideoCaptionExist (video: MVideoId, language: string, res: Response) { const videoCaption = await VideoCaptionModel.loadByVideoIdAndLanguage(video.id, language) diff --git a/server/middlewares/validators/shared/video-channels.ts b/server/middlewares/validators/shared/video-channels.ts index fe2e663b7..3fc3d012a 100644 --- a/server/middlewares/validators/shared/video-channels.ts +++ b/server/middlewares/validators/shared/video-channels.ts @@ -1,7 +1,7 @@ import * as express from 'express' import { VideoChannelModel } from '@server/models/video/video-channel' import { MChannelBannerAccountDefault } from '@server/types/models' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' async function doesLocalVideoChannelNameExist (name: string, res: express.Response) { const videoChannel = await VideoChannelModel.loadLocalByNameAndPopulateAccount(name) diff --git a/server/middlewares/validators/shared/video-comments.ts b/server/middlewares/validators/shared/video-comments.ts index 83ea15c98..60132fb6e 100644 --- a/server/middlewares/validators/shared/video-comments.ts +++ b/server/middlewares/validators/shared/video-comments.ts @@ -1,7 +1,7 @@ import * as express from 'express' import { VideoCommentModel } from '@server/models/video/video-comment' import { MVideoId } from '@server/types/models' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' async function doesVideoCommentThreadExist (idArg: number | string, video: MVideoId, res: express.Response) { const id = parseInt(idArg + '', 10) diff --git a/server/middlewares/validators/shared/video-imports.ts b/server/middlewares/validators/shared/video-imports.ts index 0f984bc17..50b49ffcb 100644 --- a/server/middlewares/validators/shared/video-imports.ts +++ b/server/middlewares/validators/shared/video-imports.ts @@ -1,6 +1,6 @@ import * as express from 'express' import { VideoImportModel } from '@server/models/video/video-import' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' async function doesVideoImportExist (id: number, res: express.Response) { const videoImport = await VideoImportModel.loadAndPopulateVideo(id) diff --git a/server/middlewares/validators/shared/video-ownerships.ts b/server/middlewares/validators/shared/video-ownerships.ts index fc27006ce..93a23ef40 100644 --- a/server/middlewares/validators/shared/video-ownerships.ts +++ b/server/middlewares/validators/shared/video-ownerships.ts @@ -1,6 +1,6 @@ import * as express from 'express' import { VideoChangeOwnershipModel } from '@server/models/video/video-change-ownership' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' async function doesChangeVideoOwnershipExist (idArg: number | string, res: express.Response) { const id = parseInt(idArg + '', 10) diff --git a/server/middlewares/validators/shared/video-playlists.ts b/server/middlewares/validators/shared/video-playlists.ts index d762859a8..3f6768179 100644 --- a/server/middlewares/validators/shared/video-playlists.ts +++ b/server/middlewares/validators/shared/video-playlists.ts @@ -1,7 +1,7 @@ import * as express from 'express' import { VideoPlaylistModel } from '@server/models/video/video-playlist' import { MVideoPlaylist } from '@server/types/models' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' export type VideoPlaylistFetchType = 'summary' | 'all' async function doesVideoPlaylistExist (id: number | string, res: express.Response, fetchType: VideoPlaylistFetchType = 'summary') { diff --git a/server/middlewares/validators/shared/videos.ts b/server/middlewares/validators/shared/videos.ts index 2c66c1a3a..7f42a4893 100644 --- a/server/middlewares/validators/shared/videos.ts +++ b/server/middlewares/validators/shared/videos.ts @@ -12,7 +12,7 @@ import { MVideoImmutable, MVideoThumbnail } from '@server/types/models' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { UserRight } from '@shared/models' async function doesVideoExist (id: number | string, res: Response, fetchType: VideoLoadType = 'all') { diff --git a/server/middlewares/validators/themes.ts b/server/middlewares/validators/themes.ts index d4716257f..2953b9505 100644 --- a/server/middlewares/validators/themes.ts +++ b/server/middlewares/validators/themes.ts @@ -1,6 +1,6 @@ import * as express from 'express' import { param } from 'express-validator' -import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '../../../shared/models/http/http-error-codes' import { isSafePath } from '../../helpers/custom-validators/misc' import { isPluginNameValid, isPluginVersionValid } from '../../helpers/custom-validators/plugins' import { logger } from '../../helpers/logger' diff --git a/server/middlewares/validators/user-subscriptions.ts b/server/middlewares/validators/user-subscriptions.ts index ab7962923..df5777771 100644 --- a/server/middlewares/validators/user-subscriptions.ts +++ b/server/middlewares/validators/user-subscriptions.ts @@ -1,6 +1,6 @@ import * as express from 'express' import { body, param, query } from 'express-validator' -import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '../../../shared/models/http/http-error-codes' import { areValidActorHandles, isValidActorHandle } from '../../helpers/custom-validators/activitypub/actor' import { toArray } from '../../helpers/custom-validators/misc' import { logger } from '../../helpers/logger' diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts index 698d7d814..748b89f8f 100644 --- a/server/middlewares/validators/users.ts +++ b/server/middlewares/validators/users.ts @@ -3,7 +3,7 @@ import { body, param, query } from 'express-validator' import { omit } from 'lodash' import { Hooks } from '@server/lib/plugins/hooks' import { MUserDefault } from '@server/types/models' -import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '../../../shared/models/http/http-error-codes' import { UserRole } from '../../../shared/models/users' import { UserRegister } from '../../../shared/models/users/user-register.model' import { isActorPreferredUsernameValid } from '../../helpers/custom-validators/activitypub/actor' diff --git a/server/middlewares/validators/videos/video-blacklist.ts b/server/middlewares/validators/videos/video-blacklist.ts index 21141d84d..3a4937b7b 100644 --- a/server/middlewares/validators/videos/video-blacklist.ts +++ b/server/middlewares/validators/videos/video-blacklist.ts @@ -1,6 +1,6 @@ import * as express from 'express' import { body, query } from 'express-validator' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' import { isBooleanValid, toBooleanOrNull, toIntOrNull } from '../../../helpers/custom-validators/misc' import { isVideoBlacklistReasonValid, isVideoBlacklistTypeValid } from '../../../helpers/custom-validators/video-blacklist' import { logger } from '../../../helpers/logger' diff --git a/server/middlewares/validators/videos/video-channels.ts b/server/middlewares/validators/videos/video-channels.ts index e7df185e4..ea10fe425 100644 --- a/server/middlewares/validators/videos/video-channels.ts +++ b/server/middlewares/validators/videos/video-channels.ts @@ -3,7 +3,7 @@ import { body, param, query } from 'express-validator' import { VIDEO_CHANNELS } from '@server/initializers/constants' import { MChannelAccountDefault, MUser } from '@server/types/models' import { UserRight } from '../../../../shared' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' import { isActorPreferredUsernameValid } from '../../../helpers/custom-validators/activitypub/actor' import { isBooleanValid, toBooleanOrNull } from '../../../helpers/custom-validators/misc' import { diff --git a/server/middlewares/validators/videos/video-comments.ts b/server/middlewares/validators/videos/video-comments.ts index 885506ebe..61c2ed92f 100644 --- a/server/middlewares/validators/videos/video-comments.ts +++ b/server/middlewares/validators/videos/video-comments.ts @@ -2,7 +2,7 @@ import * as express from 'express' import { body, param, query } from 'express-validator' import { MUserAccountUrl } from '@server/types/models' import { UserRight } from '../../../../shared' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' import { exists, isBooleanValid, isIdValid, toBooleanOrNull } from '../../../helpers/custom-validators/misc' import { isValidVideoCommentText } from '../../../helpers/custom-validators/video-comments' import { logger } from '../../../helpers/logger' diff --git a/server/middlewares/validators/videos/video-imports.ts b/server/middlewares/validators/videos/video-imports.ts index 85dc647ce..52b839e56 100644 --- a/server/middlewares/validators/videos/video-imports.ts +++ b/server/middlewares/validators/videos/video-imports.ts @@ -2,7 +2,7 @@ import * as express from 'express' import { body } from 'express-validator' import { isPreImportVideoAccepted } from '@server/lib/moderation' import { Hooks } from '@server/lib/plugins/hooks' -import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '@shared/models' import { VideoImportCreate } from '@shared/models/videos/import/video-import-create.model' import { isIdValid, toIntOrNull } from '../../../helpers/custom-validators/misc' import { isVideoImportTargetUrlValid, isVideoImportTorrentFile } from '../../../helpers/custom-validators/video-imports' diff --git a/server/middlewares/validators/videos/video-live.ts b/server/middlewares/validators/videos/video-live.ts index 7cfb935e3..5c8a4269d 100644 --- a/server/middlewares/validators/videos/video-live.ts +++ b/server/middlewares/validators/videos/video-live.ts @@ -5,7 +5,7 @@ import { isLocalLiveVideoAccepted } from '@server/lib/moderation' import { Hooks } from '@server/lib/plugins/hooks' import { VideoModel } from '@server/models/video/video' import { VideoLiveModel } from '@server/models/video/video-live' -import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '@shared/models' import { ServerErrorCode, UserRight, VideoState } from '@shared/models' import { isBooleanValid, isIdValid, toBooleanOrNull, toIntOrNull } from '../../../helpers/custom-validators/misc' import { isVideoNameValid } from '../../../helpers/custom-validators/videos' diff --git a/server/middlewares/validators/videos/video-ownership-changes.ts b/server/middlewares/validators/videos/video-ownership-changes.ts index 54ac46c99..06f86a4c8 100644 --- a/server/middlewares/validators/videos/video-ownership-changes.ts +++ b/server/middlewares/validators/videos/video-ownership-changes.ts @@ -6,7 +6,7 @@ import { logger } from '@server/helpers/logger' import { isAbleToUploadVideo } from '@server/lib/user' import { AccountModel } from '@server/models/account/account' import { MVideoWithAllFiles } from '@server/types/models' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { ServerErrorCode, UserRight, VideoChangeOwnershipAccept, VideoChangeOwnershipStatus, VideoState } from '@shared/models' import { areValidationErrors, diff --git a/server/middlewares/validators/videos/video-playlists.ts b/server/middlewares/validators/videos/video-playlists.ts index 5ee7ee0ce..ab84b4814 100644 --- a/server/middlewares/validators/videos/video-playlists.ts +++ b/server/middlewares/validators/videos/video-playlists.ts @@ -3,7 +3,7 @@ import { body, param, query, ValidationChain } from 'express-validator' import { ExpressPromiseHandler } from '@server/types/express' import { MUserAccountId } from '@server/types/models' import { UserRight, VideoPlaylistCreate, VideoPlaylistUpdate } from '../../../../shared' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model' import { VideoPlaylistType } from '../../../../shared/models/videos/playlist/video-playlist-type.model' import { diff --git a/server/middlewares/validators/videos/video-rates.ts b/server/middlewares/validators/videos/video-rates.ts index 5d5dfb222..5fe78b39e 100644 --- a/server/middlewares/validators/videos/video-rates.ts +++ b/server/middlewares/validators/videos/video-rates.ts @@ -1,6 +1,6 @@ import * as express from 'express' import { body, param, query } from 'express-validator' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' import { VideoRateType } from '../../../../shared/models/videos' import { isAccountNameValid } from '../../../helpers/custom-validators/accounts' import { isIdValid } from '../../../helpers/custom-validators/misc' diff --git a/server/middlewares/validators/videos/video-shares.ts b/server/middlewares/validators/videos/video-shares.ts index 7e54b6fc0..3b8d61768 100644 --- a/server/middlewares/validators/videos/video-shares.ts +++ b/server/middlewares/validators/videos/video-shares.ts @@ -1,6 +1,6 @@ import * as express from 'express' import { param } from 'express-validator' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' import { isIdValid } from '../../../helpers/custom-validators/misc' import { logger } from '../../../helpers/logger' import { VideoShareModel } from '../../../models/video/video-share' diff --git a/server/middlewares/validators/videos/video-watch.ts b/server/middlewares/validators/videos/video-watch.ts index 43306f7cd..431515eb1 100644 --- a/server/middlewares/validators/videos/video-watch.ts +++ b/server/middlewares/validators/videos/video-watch.ts @@ -1,6 +1,6 @@ import * as express from 'express' import { body } from 'express-validator' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' import { toIntOrNull } from '../../../helpers/custom-validators/misc' import { logger } from '../../../helpers/logger' import { areValidationErrors, doesVideoExist, isValidVideoIdParam } from '../shared' diff --git a/server/middlewares/validators/videos/videos.ts b/server/middlewares/validators/videos/videos.ts index 49e10e2b5..374a59c50 100644 --- a/server/middlewares/validators/videos/videos.ts +++ b/server/middlewares/validators/videos/videos.ts @@ -6,7 +6,7 @@ import { getServerActor } from '@server/models/application/application' import { ExpressPromiseHandler } from '@server/types/express' import { MUserAccountId, MVideoFullLight } from '@server/types/models' import { ServerErrorCode, UserRight, VideoPrivacy } from '../../../../shared' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' import { exists, isBooleanValid, diff --git a/server/middlewares/validators/webfinger.ts b/server/middlewares/validators/webfinger.ts index bcdd136c6..131360820 100644 --- a/server/middlewares/validators/webfinger.ts +++ b/server/middlewares/validators/webfinger.ts @@ -1,6 +1,6 @@ import * as express from 'express' import { query } from 'express-validator' -import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '../../../shared/models/http/http-error-codes' import { isWebfingerLocalResourceValid } from '../../helpers/custom-validators/webfinger' import { getHostWithPort } from '../../helpers/express-utils' import { logger } from '../../helpers/logger' -- cgit v1.2.3 From 4c7e60bc17ee5830399bac4aa273356903421b4c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Jul 2021 14:27:30 +0200 Subject: Reorganize imports --- server/middlewares/cache.ts | 2 +- server/middlewares/servers.ts | 2 +- server/middlewares/user-right.ts | 2 +- server/middlewares/validators/activitypub/activity.ts | 4 ++-- server/middlewares/validators/bulk.ts | 3 +-- server/middlewares/validators/feeds.ts | 1 - server/middlewares/validators/shared/videos.ts | 3 +-- server/middlewares/validators/videos/video-live.ts | 3 +-- .../middlewares/validators/videos/video-ownership-changes.ts | 10 ++++++++-- 9 files changed, 16 insertions(+), 14 deletions(-) (limited to 'server/middlewares') diff --git a/server/middlewares/cache.ts b/server/middlewares/cache.ts index 1ced06042..e508b22a6 100644 --- a/server/middlewares/cache.ts +++ b/server/middlewares/cache.ts @@ -1,6 +1,6 @@ -import { Redis } from '../lib/redis' import * as apicache from 'apicache' import { HttpStatusCode } from '../../shared/models/http/http-error-codes' +import { Redis } from '../lib/redis' // Ensure Redis is initialized Redis.Instance.init() diff --git a/server/middlewares/servers.ts b/server/middlewares/servers.ts index 49a2241b3..cf70d901e 100644 --- a/server/middlewares/servers.ts +++ b/server/middlewares/servers.ts @@ -1,6 +1,6 @@ import * as express from 'express' -import { getHostWithPort } from '../helpers/express-utils' import { HttpStatusCode } from '../../shared/models/http/http-error-codes' +import { getHostWithPort } from '../helpers/express-utils' function setBodyHostsPort (req: express.Request, res: express.Response, next: express.NextFunction) { if (!req.body.hosts) return next() diff --git a/server/middlewares/user-right.ts b/server/middlewares/user-right.ts index 87a1766cf..c8c694f05 100644 --- a/server/middlewares/user-right.ts +++ b/server/middlewares/user-right.ts @@ -1,7 +1,7 @@ import * as express from 'express' import { UserRight } from '../../shared' -import { logger } from '../helpers/logger' import { HttpStatusCode } from '../../shared/models/http/http-error-codes' +import { logger } from '../helpers/logger' function ensureUserHasRight (userRight: UserRight) { return function (req: express.Request, res: express.Response, next: express.NextFunction) { diff --git a/server/middlewares/validators/activitypub/activity.ts b/server/middlewares/validators/activitypub/activity.ts index d65a8e455..d24e4427b 100644 --- a/server/middlewares/validators/activitypub/activity.ts +++ b/server/middlewares/validators/activitypub/activity.ts @@ -1,8 +1,8 @@ import * as express from 'express' -import { isRootActivityValid } from '../../../helpers/custom-validators/activitypub/activity' -import { logger } from '../../../helpers/logger' import { getServerActor } from '@server/models/application/application' import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' +import { isRootActivityValid } from '../../../helpers/custom-validators/activitypub/activity' +import { logger } from '../../../helpers/logger' async function activityPubValidator (req: express.Request, res: express.Response, next: express.NextFunction) { logger.debug('Checking activity pub parameters') diff --git a/server/middlewares/validators/bulk.ts b/server/middlewares/validators/bulk.ts index 4057b1e01..6fec58149 100644 --- a/server/middlewares/validators/bulk.ts +++ b/server/middlewares/validators/bulk.ts @@ -1,8 +1,7 @@ import * as express from 'express' import { body } from 'express-validator' import { isBulkRemoveCommentsOfScopeValid } from '@server/helpers/custom-validators/bulk' -import { HttpStatusCode } from '@shared/models' -import { UserRight } from '@shared/models' +import { HttpStatusCode, UserRight } from '@shared/models' import { BulkRemoveCommentsOfBody } from '@shared/models/bulk/bulk-remove-comments-of-body.model' import { logger } from '../../helpers/logger' import { areValidationErrors, doesAccountNameWithHostExist } from './shared' diff --git a/server/middlewares/validators/feeds.ts b/server/middlewares/validators/feeds.ts index 1a5a8ffa0..d29bebf64 100644 --- a/server/middlewares/validators/feeds.ts +++ b/server/middlewares/validators/feeds.ts @@ -1,6 +1,5 @@ import * as express from 'express' import { param, query } from 'express-validator' - import { HttpStatusCode } from '../../../shared/models/http/http-error-codes' import { isValidRSSFeed } from '../../helpers/custom-validators/feeds' import { exists, isIdOrUUIDValid, isIdValid, toCompleteUUID } from '../../helpers/custom-validators/misc' diff --git a/server/middlewares/validators/shared/videos.ts b/server/middlewares/validators/shared/videos.ts index 7f42a4893..71b81654f 100644 --- a/server/middlewares/validators/shared/videos.ts +++ b/server/middlewares/validators/shared/videos.ts @@ -12,8 +12,7 @@ import { MVideoImmutable, MVideoThumbnail } from '@server/types/models' -import { HttpStatusCode } from '@shared/models' -import { UserRight } from '@shared/models' +import { HttpStatusCode, UserRight } from '@shared/models' async function doesVideoExist (id: number | string, res: Response, fetchType: VideoLoadType = 'all') { const userId = res.locals.oauth ? res.locals.oauth.token.User.id : undefined diff --git a/server/middlewares/validators/videos/video-live.ts b/server/middlewares/validators/videos/video-live.ts index 5c8a4269d..97e8b4510 100644 --- a/server/middlewares/validators/videos/video-live.ts +++ b/server/middlewares/validators/videos/video-live.ts @@ -5,8 +5,7 @@ import { isLocalLiveVideoAccepted } from '@server/lib/moderation' import { Hooks } from '@server/lib/plugins/hooks' import { VideoModel } from '@server/models/video/video' import { VideoLiveModel } from '@server/models/video/video-live' -import { HttpStatusCode } from '@shared/models' -import { ServerErrorCode, UserRight, VideoState } from '@shared/models' +import { HttpStatusCode, ServerErrorCode, UserRight, VideoState } from '@shared/models' import { isBooleanValid, isIdValid, toBooleanOrNull, toIntOrNull } from '../../../helpers/custom-validators/misc' import { isVideoNameValid } from '../../../helpers/custom-validators/videos' import { cleanUpReqFiles } from '../../../helpers/express-utils' diff --git a/server/middlewares/validators/videos/video-ownership-changes.ts b/server/middlewares/validators/videos/video-ownership-changes.ts index 06f86a4c8..a7f0b72c3 100644 --- a/server/middlewares/validators/videos/video-ownership-changes.ts +++ b/server/middlewares/validators/videos/video-ownership-changes.ts @@ -6,8 +6,14 @@ import { logger } from '@server/helpers/logger' import { isAbleToUploadVideo } from '@server/lib/user' import { AccountModel } from '@server/models/account/account' import { MVideoWithAllFiles } from '@server/types/models' -import { HttpStatusCode } from '@shared/models' -import { ServerErrorCode, UserRight, VideoChangeOwnershipAccept, VideoChangeOwnershipStatus, VideoState } from '@shared/models' +import { + HttpStatusCode, + ServerErrorCode, + UserRight, + VideoChangeOwnershipAccept, + VideoChangeOwnershipStatus, + VideoState +} from '@shared/models' import { areValidationErrors, checkUserCanManageVideo, -- cgit v1.2.3 From 4d029ef8ec3d5274eeaa3ee6d808eb7035e7faef Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 20 Jul 2021 14:15:15 +0200 Subject: Add ability for instances to follow any actor --- server/middlewares/validators/follows.ts | 37 +++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 8 deletions(-) (limited to 'server/middlewares') diff --git a/server/middlewares/validators/follows.ts b/server/middlewares/validators/follows.ts index 05cc66c38..16abdd096 100644 --- a/server/middlewares/validators/follows.ts +++ b/server/middlewares/validators/follows.ts @@ -1,7 +1,8 @@ import * as express from 'express' import { body, param, query } from 'express-validator' -import { isFollowStateValid } from '@server/helpers/custom-validators/follows' +import { isEachUniqueHandleValid, isFollowStateValid, isRemoteHandleValid } from '@server/helpers/custom-validators/follows' import { loadActorUrlOrGetFromWebfinger } from '@server/lib/activitypub/actors' +import { getRemoteNameAndHost } from '@server/lib/activitypub/follow' import { getServerActor } from '@server/models/application/application' import { MActorFollowActorsDefault } from '@server/types/models' import { HttpStatusCode } from '../../../shared/models/http/http-error-codes' @@ -9,10 +10,11 @@ import { isTestInstance } from '../../helpers/core-utils' import { isActorTypeValid, isValidActorHandle } from '../../helpers/custom-validators/activitypub/actor' import { isEachUniqueHostValid, isHostValid } from '../../helpers/custom-validators/servers' import { logger } from '../../helpers/logger' -import { SERVER_ACTOR_NAME, WEBSERVER } from '../../initializers/constants' +import { WEBSERVER } from '../../initializers/constants' import { ActorModel } from '../../models/actor/actor' import { ActorFollowModel } from '../../models/actor/actor-follow' import { areValidationErrors } from './shared' +import { ServerFollowCreate } from '@shared/models' const listFollowsValidator = [ query('state') @@ -30,29 +32,46 @@ const listFollowsValidator = [ ] const followValidator = [ - body('hosts').custom(isEachUniqueHostValid).withMessage('Should have an array of unique hosts'), + body('hosts') + .toArray() + .custom(isEachUniqueHostValid).withMessage('Should have an array of unique hosts'), + + body('handles') + .toArray() + .custom(isEachUniqueHandleValid).withMessage('Should have an array of handles'), (req: express.Request, res: express.Response, next: express.NextFunction) => { - // Force https if the administrator wants to make friends + // Force https if the administrator wants to follow remote actors if (isTestInstance() === false && WEBSERVER.SCHEME === 'http') { return res .status(HttpStatusCode.INTERNAL_SERVER_ERROR_500) .json({ error: 'Cannot follow on a non HTTPS web server.' }) - .end() } logger.debug('Checking follow parameters', { parameters: req.body }) if (areValidationErrors(req, res)) return + const body: ServerFollowCreate = req.body + if (body.hosts.length === 0 && body.handles.length === 0) { + + return res + .status(HttpStatusCode.BAD_REQUEST_400) + .json({ + error: 'You must provide at least one handle or one host.' + }) + } + return next() } ] const removeFollowingValidator = [ - param('host').custom(isHostValid).withMessage('Should have a valid host'), + param('hostOrHandle') + .custom(value => isHostValid(value) || isRemoteHandleValid(value)) + .withMessage('Should have a valid host/handle'), async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking unfollowing parameters', { parameters: req.params }) @@ -60,12 +79,14 @@ const removeFollowingValidator = [ if (areValidationErrors(req, res)) return const serverActor = await getServerActor() - const follow = await ActorFollowModel.loadByActorAndTargetNameAndHostForAPI(serverActor.id, SERVER_ACTOR_NAME, req.params.host) + + const { name, host } = getRemoteNameAndHost(req.params.hostOrHandle) + const follow = await ActorFollowModel.loadByActorAndTargetNameAndHostForAPI(serverActor.id, name, host) if (!follow) { return res.fail({ status: HttpStatusCode.NOT_FOUND_404, - message: `Following ${req.params.host} not found.` + message: `Follow ${req.params.hostOrHandle} not found.` }) } -- cgit v1.2.3