ActivityPub-federated video streaming platform using P2P directly in your web browser
Cleanup express locals typings
Chocobozzzdae86118ed5d
diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.tsindex cc2671fc13..e06aa35f4c 100644--- a/server/controllers/activitypub/client.ts+++ b/server/controllers/activitypub/client.ts@@ -169,27 +169,27 @@ export {// ---------------------------------------------------------------------------function accountController (req: express.Request, res: express.Response) {- const account: AccountModel = res.locals.account+ const account = res.locals.accountreturn activityPubResponse(activityPubContextify(account.toActivityPubObject()), res)}async function accountFollowersController (req: express.Request, res: express.Response) {- const account: AccountModel = res.locals.account+ const account = res.locals.accountconst activityPubResult = await actorFollowers(req, account.Actor)return activityPubResponse(activityPubContextify(activityPubResult), res)}async function accountFollowingController (req: express.Request, res: express.Response) {- const account: AccountModel = res.locals.account+ const account = res.locals.accountconst activityPubResult = await actorFollowing(req, account.Actor)return activityPubResponse(activityPubContextify(activityPubResult), res)}async function accountPlaylistsController (req: express.Request, res: express.Response) {- const account: AccountModel = res.locals.account+ const account = res.locals.accountconst activityPubResult = await actorPlaylists(req, account)return activityPubResponse(activityPubContextify(activityPubResult), res)@@ -197,7 +197,7 @@ async function accountPlaylistsController (req: express.Request, res: express.Refunction getAccountVideoRate (rateType: VideoRateType) {return (req: express.Request, res: express.Response) => {- const accountVideoRate: AccountVideoRateModel = res.locals.accountVideoRate+ const accountVideoRate = res.locals.accountVideoRateconst byActor = accountVideoRate.Account.Actorconst url = getRateUrl(rateType, byActor, accountVideoRate.Video)@@ -211,7 +211,7 @@ function getAccountVideoRate (rateType: VideoRateType) {async function videoController (req: express.Request, res: express.Response) {// We need more attributes- const video: VideoModel = await VideoModel.loadForGetAPI(res.locals.video.id)+ const video = await VideoModel.loadForGetAPI(res.locals.video.id)if (video.url.startsWith(CONFIG.WEBSERVER.URL) === false) return res.redirect(video.url)@@ -230,7 +230,7 @@ async function videoController (req: express.Request, res: express.Response) {}async function videoAnnounceController (req: express.Request, res: express.Response) {- const share = res.locals.videoShare as VideoShareModel+ const share = res.locals.videoShareif (share.url.startsWith(CONFIG.WEBSERVER.URL) === false) return res.redirect(share.url)@@ -240,7 +240,7 @@ async function videoAnnounceController (req: express.Request, res: express.Respo}async function videoAnnouncesController (req: express.Request, res: express.Response) {- const video: VideoModel = res.locals.video+ const video = res.locals.videoconst handler = async (start: number, count: number) => {const result = await VideoShareModel.listAndCountByVideoId(video.id, start, count)@@ -255,21 +255,21 @@ async function videoAnnouncesController (req: express.Request, res: express.Resp}async function videoLikesController (req: express.Request, res: express.Response) {- const video: VideoModel = res.locals.video+ const video = res.locals.videoconst json = await videoRates(req, 'like', video, getVideoLikesActivityPubUrl(video))return activityPubResponse(activityPubContextify(json), res)}async function videoDislikesController (req: express.Request, res: express.Response) {- const video: VideoModel = res.locals.video+ const video = res.locals.videoconst json = await videoRates(req, 'dislike', video, getVideoDislikesActivityPubUrl(video))return activityPubResponse(activityPubContextify(json), res)}async function videoCommentsController (req: express.Request, res: express.Response) {- const video: VideoModel = res.locals.video+ const video = res.locals.videoconst handler = async (start: number, count: number) => {const result = await VideoCommentModel.listAndCountByVideoId(video.id, start, count)@@ -284,27 +284,27 @@ async function videoCommentsController (req: express.Request, res: express.Respo}async function videoChannelController (req: express.Request, res: express.Response) {- const videoChannel: VideoChannelModel = res.locals.videoChannel+ const videoChannel = res.locals.videoChannelreturn activityPubResponse(activityPubContextify(videoChannel.toActivityPubObject()), res)}async function videoChannelFollowersController (req: express.Request, res: express.Response) {- const videoChannel: VideoChannelModel = res.locals.videoChannel+ const videoChannel = res.locals.videoChannelconst activityPubResult = await actorFollowers(req, videoChannel.Actor)return activityPubResponse(activityPubContextify(activityPubResult), res)}async function videoChannelFollowingController (req: express.Request, res: express.Response) {- const videoChannel: VideoChannelModel = res.locals.videoChannel+ const videoChannel = res.locals.videoChannelconst activityPubResult = await actorFollowing(req, videoChannel.Actor)return activityPubResponse(activityPubContextify(activityPubResult), res)}async function videoCommentController (req: express.Request, res: express.Response) {- const videoComment: VideoCommentModel = res.locals.videoComment+ const videoComment = res.locals.videoCommentif (videoComment.url.startsWith(CONFIG.WEBSERVER.URL) === false) return res.redirect(videoComment.url)@@ -323,7 +323,7 @@ async function videoCommentController (req: express.Request, res: express.Respon}async function videoRedundancyController (req: express.Request, res: express.Response) {- const videoRedundancy: VideoRedundancyModel = res.locals.videoRedundancy+ const videoRedundancy = res.locals.videoRedundancyif (videoRedundancy.url.startsWith(CONFIG.WEBSERVER.URL) === false) return res.redirect(videoRedundancy.url)const serverActor = await getServerActor()@@ -340,7 +340,7 @@ async function videoRedundancyController (req: express.Request, res: express.Res}async function videoPlaylistController (req: express.Request, res: express.Response) {- const playlist: VideoPlaylistModel = res.locals.videoPlaylist+ const playlist = res.locals.videoPlaylist// We need more attributesplaylist.OwnerAccount = await AccountModel.load(playlist.ownerAccountId)@@ -353,7 +353,7 @@ async function videoPlaylistController (req: express.Request, res: express.Respo}async function videoPlaylistElementController (req: express.Request, res: express.Response) {- const videoPlaylistElement: VideoPlaylistElementModel = res.locals.videoPlaylistElement+ const videoPlaylistElement = res.locals.videoPlaylistElementconst json = videoPlaylistElement.toActivityPubObject()return activityPubResponse(activityPubContextify(json), res)diff --git a/server/controllers/activitypub/inbox.ts b/server/controllers/activitypub/inbox.tsindex f0e65015bb..38d5c51dfb 100644--- a/server/controllers/activitypub/inbox.ts+++ b/server/controllers/activitypub/inbox.ts@@ -5,8 +5,6 @@ import { logger } from '../../helpers/logger'import { processActivities } from '../../lib/activitypub/process/process'import { asyncMiddleware, checkSignature, localAccountValidator, localVideoChannelValidator, signatureValidator } from '../../middlewares'import { activityPubValidator } from '../../middlewares/validators/activitypub/activity'-import { VideoChannelModel } from '../../models/video/video-channel'-import { AccountModel } from '../../models/account/account'import { queue } from 'async'import { ActorModel } from '../../models/activitypub/actor'@@ -66,12 +64,7 @@ function inboxController (req: express.Request, res: express.Response) {activities = activities.filter(a => isActivityValid(a))logger.debug('We keep %d activities.', activities.length, { activities })- let accountOrChannel: VideoChannelModel | AccountModel- if (res.locals.account) {- accountOrChannel = res.locals.account- } else if (res.locals.videoChannel) {- accountOrChannel = res.locals.videoChannel- }+ const accountOrChannel = res.locals.account || res.locals.videoChannellogger.info('Receiving inbox requests for %d activities by %s.', activities.length, res.locals.signature.actor.url)diff --git a/server/controllers/activitypub/outbox.ts b/server/controllers/activitypub/outbox.tsindex e060affb2a..38b6ec9764 100644--- a/server/controllers/activitypub/outbox.ts+++ b/server/controllers/activitypub/outbox.ts@@ -33,7 +33,7 @@ export {// ---------------------------------------------------------------------------async function outboxController (req: express.Request, res: express.Response) {- const accountOrVideoChannel: AccountModel | VideoChannelModel = res.locals.account || res.locals.videoChannel+ const accountOrVideoChannel = res.locals.account || res.locals.videoChannelconst actor = accountOrVideoChannel.Actorconst actorOutboxUrl = actor.url + '/outbox'diff --git a/server/controllers/api/accounts.ts b/server/controllers/api/accounts.tsindex e24545de83..adbf69781d 100644--- a/server/controllers/api/accounts.ts+++ b/server/controllers/api/accounts.ts@@ -17,7 +17,6 @@ import { VideoChannelModel } from '../../models/video/video-channel'import { JobQueue } from '../../lib/job-queue'import { logger } from '../../helpers/logger'import { VideoPlaylistModel } from '../../models/video/video-playlist'-import { UserModel } from '../../models/account/user'import { commonVideoPlaylistFiltersValidator } from '../../middlewares/validators/videos/video-playlists'const accountsRouter = express.Router()@@ -71,7 +70,7 @@ export {// ---------------------------------------------------------------------------function getAccount (req: express.Request, res: express.Response) {- const account: AccountModel = res.locals.account+ const account = res.locals.accountif (account.isOutdated()) {JobQueue.Instance.createJob({ type: 'activitypub-refresher', payload: { type: 'actor', url: account.Actor.url } })@@ -98,7 +97,7 @@ async function listAccountPlaylists (req: express.Request, res: express.Response// Allow users to see their private/unlisted video playlistslet privateAndUnlisted = false- if (res.locals.oauth && (res.locals.oauth.token.User as UserModel).Account.id === res.locals.account.id) {+ if (res.locals.oauth && res.locals.oauth.token.User.Account.id === res.locals.account.id) {privateAndUnlisted = true}@@ -116,7 +115,7 @@ async function listAccountPlaylists (req: express.Request, res: express.Response}async function listAccountVideos (req: express.Request, res: express.Response) {- const account: AccountModel = res.locals.account+ const account = res.locals.accountconst followerActorId = isUserAbleToSearchRemoteURI(res) ? null : undefinedconst resultList = await VideoModel.listForApi({diff --git a/server/controllers/api/index.ts b/server/controllers/api/index.tsindex ed4b33deaa..60a84036ec 100644--- a/server/controllers/api/index.ts+++ b/server/controllers/api/index.ts@@ -41,6 +41,6 @@ export { apiRouter }// ----------------------------------------------------------------------------function pong (req: express.Request, res: express.Response, next: express.NextFunction) {+function pong (req: express.Request, res: express.Response) {return res.send('pong').status(200).end()}diff --git a/server/controllers/api/server/follows.ts b/server/controllers/api/server/follows.tsindex 9fa6c34ba3..99d211bfc2 100644--- a/server/controllers/api/server/follows.ts+++ b/server/controllers/api/server/follows.ts@@ -59,7 +59,7 @@ export {// ----------------------------------------------------------------------------async function listFollowing (req: express.Request, res: express.Response, next: express.NextFunction) {+async function listFollowing (req: express.Request, res: express.Response) {const serverActor = await getServerActor()const resultList = await ActorFollowModel.listFollowingForApi(serverActor.id,@@ -72,7 +72,7 @@ async function listFollowing (req: express.Request, res: express.Response, next:return res.json(getFormattedObjects(resultList.data, resultList.total))}-async function listFollowers (req: express.Request, res: express.Response, next: express.NextFunction) {+async function listFollowers (req: express.Request, res: express.Response) {const serverActor = await getServerActor()const resultList = await ActorFollowModel.listFollowersForApi(serverActor.id,@@ -85,7 +85,7 @@ async function listFollowers (req: express.Request, res: express.Response, next:return res.json(getFormattedObjects(resultList.data, resultList.total))}-async function followInstance (req: express.Request, res: express.Response, next: express.NextFunction) {+async function followInstance (req: express.Request, res: express.Response) {const hosts = req.body.hosts as string[]const follower = await getServerActor()@@ -103,8 +103,8 @@ async function followInstance (req: express.Request, res: express.Response, nextreturn res.status(204).end()}-async function removeFollow (req: express.Request, res: express.Response, next: express.NextFunction) {- const follow: ActorFollowModel = res.locals.follow+async function removeFollow (req: express.Request, res: express.Response) {+ const follow = res.locals.followawait sequelizeTypescript.transaction(async t => {if (follow.state === 'accepted') await sendUndoFollow(follow, t)diff --git a/server/controllers/api/server/redundancy.ts b/server/controllers/api/server/redundancy.tsindex 4140c49912..f8109070d5 100644--- a/server/controllers/api/server/redundancy.ts+++ b/server/controllers/api/server/redundancy.ts@@ -2,7 +2,6 @@ import * as express from 'express'import { UserRight } from '../../../../shared/models/users'import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../../middlewares'import { updateServerRedundancyValidator } from '../../../middlewares/validators/redundancy'-import { ServerModel } from '../../../models/server/server'import { removeRedundancyOf } from '../../../lib/redundancy'import { logger } from '../../../helpers/logger'@@ -23,8 +22,8 @@ export {// ----------------------------------------------------------------------------async function updateRedundancy (req: express.Request, res: express.Response, next: express.NextFunction) {- const server = res.locals.server as ServerModel+async function updateRedundancy (req: express.Request, res: express.Response) {+ const server = res.locals.serverserver.redundancyAllowed = req.body.redundancyAlloweddiff --git a/server/controllers/api/server/server-blocklist.ts b/server/controllers/api/server/server-blocklist.tsindex 3cb3a96e24..d165db1916 100644--- a/server/controllers/api/server/server-blocklist.ts+++ b/server/controllers/api/server/server-blocklist.ts@@ -18,11 +18,9 @@ import {unblockAccountByServerValidator,unblockServerByServerValidator} from '../../../middlewares/validators'-import { AccountModel } from '../../../models/account/account'import { AccountBlocklistModel } from '../../../models/account/account-blocklist'import { addAccountInBlocklist, addServerInBlocklist, removeAccountFromBlocklist, removeServerFromBlocklist } from '../../../lib/blocklist'import { ServerBlocklistModel } from '../../../models/server/server-blocklist'-import { ServerModel } from '../../../models/server/server'import { UserRight } from '../../../../shared/models/users'const serverBlocklistRouter = express.Router()@@ -91,7 +89,7 @@ async function listBlockedAccounts (req: express.Request, res: express.Response)async function blockAccount (req: express.Request, res: express.Response) {const serverActor = await getServerActor()- const accountToBlock: AccountModel = res.locals.account+ const accountToBlock = res.locals.accountawait addAccountInBlocklist(serverActor.Account.id, accountToBlock.id)@@ -99,7 +97,7 @@ async function blockAccount (req: express.Request, res: express.Response) {}async function unblockAccount (req: express.Request, res: express.Response) {- const accountBlock: AccountBlocklistModel = res.locals.accountBlock+ const accountBlock = res.locals.accountBlockawait removeAccountFromBlocklist(accountBlock)@@ -116,7 +114,7 @@ async function listBlockedServers (req: express.Request, res: express.Response)async function blockServer (req: express.Request, res: express.Response) {const serverActor = await getServerActor()- const serverToBlock: ServerModel = res.locals.server+ const serverToBlock = res.locals.serverawait addServerInBlocklist(serverActor.Account.id, serverToBlock.id)@@ -124,7 +122,7 @@ async function blockServer (req: express.Request, res: express.Response) {}async function unblockServer (req: express.Request, res: express.Response) {- const serverBlock: ServerBlocklistModel = res.locals.serverBlock+ const serverBlock = res.locals.serverBlockawait removeServerFromBlocklist(serverBlock)diff --git a/server/controllers/api/users/index.ts b/server/controllers/api/users/index.tsindex f7edbddf3f..2117bdfebc 100644--- a/server/controllers/api/users/index.ts+++ b/server/controllers/api/users/index.ts@@ -221,8 +221,8 @@ async function registerUser (req: express.Request, res: express.Response) {return res.type('json').status(204).end()}-async function unblockUser (req: express.Request, res: express.Response, next: express.NextFunction) {- const user: UserModel = res.locals.user+async function unblockUser (req: express.Request, res: express.Response) {+ const user = res.locals.userawait changeUserBlock(res, user, false)@@ -230,7 +230,7 @@ async function unblockUser (req: express.Request, res: express.Response, next: e}async function blockUser (req: express.Request, res: express.Response) {- const user: UserModel = res.locals.user+ const user = res.locals.userconst reason = req.body.reasonawait changeUserBlock(res, user, true, reason)@@ -239,7 +239,7 @@ async function blockUser (req: express.Request, res: express.Response) {}function getUser (req: express.Request, res: express.Response) {- return res.json((res.locals.user as UserModel).toFormattedJSON())+ return res.json(res.locals.user.toFormattedJSON())}async function autocompleteUsers (req: express.Request, res: express.Response) {@@ -255,7 +255,7 @@ async function listUsers (req: express.Request, res: express.Response) {}async function removeUser (req: express.Request, res: express.Response) {- const user: UserModel = res.locals.user+ const user = res.locals.userawait user.destroy()@@ -266,7 +266,7 @@ async function removeUser (req: express.Request, res: express.Response) {async function updateUser (req: express.Request, res: express.Response) {const body: UserUpdate = req.body- const userToUpdate = res.locals.user as UserModel+ const userToUpdate = res.locals.userconst oldUserAuditView = new UserAuditView(userToUpdate.toFormattedJSON())const roleChanged = body.role !== undefined && body.role !== userToUpdate.role@@ -289,8 +289,8 @@ async function updateUser (req: express.Request, res: express.Response) {return res.sendStatus(204)}-async function askResetUserPassword (req: express.Request, res: express.Response, next: express.NextFunction) {- const user = res.locals.user as UserModel+async function askResetUserPassword (req: express.Request, res: express.Response) {+ const user = res.locals.userconst verificationString = await Redis.Instance.setResetPasswordVerificationString(user.id)const url = CONFIG.WEBSERVER.URL + '/reset-password?userId=' + user.id + '&verificationString=' + verificationString@@ -299,8 +299,8 @@ async function askResetUserPassword (req: express.Request, res: express.Responsereturn res.status(204).end()}-async function resetUserPassword (req: express.Request, res: express.Response, next: express.NextFunction) {- const user = res.locals.user as UserModel+async function resetUserPassword (req: express.Request, res: express.Response) {+ const user = res.locals.useruser.password = req.body.passwordawait user.save()@@ -315,16 +315,16 @@ async function sendVerifyUserEmail (user: UserModel) {return}-async function askSendVerifyUserEmail (req: express.Request, res: express.Response, next: express.NextFunction) {- const user = res.locals.user as UserModel+async function askSendVerifyUserEmail (req: express.Request, res: express.Response) {+ const user = res.locals.userawait sendVerifyUserEmail(user)return res.status(204).end()}-async function verifyUserEmail (req: express.Request, res: express.Response, next: express.NextFunction) {- const user = res.locals.user as UserModel+async function verifyUserEmail (req: express.Request, res: express.Response) {+ const user = res.locals.useruser.emailVerified = trueawait user.save()@@ -332,7 +332,7 @@ async function verifyUserEmail (req: express.Request, res: express.Response, nexreturn res.status(204).end()}-function success (req: express.Request, res: express.Response, next: express.NextFunction) {+function success (req: express.Request, res: express.Response) {res.end()}diff --git a/server/controllers/api/users/me.ts b/server/controllers/api/users/me.tsindex d5e154869d..3533499be5 100644--- a/server/controllers/api/users/me.ts+++ b/server/controllers/api/users/me.ts@@ -93,8 +93,8 @@ export {// ----------------------------------------------------------------------------async function getUserVideos (req: express.Request, res: express.Response, next: express.NextFunction) {- const user = res.locals.oauth.token.User as UserModel+async function getUserVideos (req: express.Request, res: express.Response) {+ const user = res.locals.oauth.token.Userconst resultList = await VideoModel.listUserVideosForApi(user.Account.id,req.query.start as number,@@ -111,8 +111,8 @@ async function getUserVideos (req: express.Request, res: express.Response, next:return res.json(getFormattedObjects(resultList.data, resultList.total, { additionalAttributes }))}-async function getUserVideoImports (req: express.Request, res: express.Response, next: express.NextFunction) {- const user = res.locals.oauth.token.User as UserModel+async function getUserVideoImports (req: express.Request, res: express.Response) {+ const user = res.locals.oauth.token.Userconst resultList = await VideoImportModel.listUserVideoImportsForApi(user.id,req.query.start as number,@@ -123,14 +123,14 @@ async function getUserVideoImports (req: express.Request, res: express.Response,return res.json(getFormattedObjects(resultList.data, resultList.total))}-async function getUserInformation (req: express.Request, res: express.Response, next: express.NextFunction) {+async function getUserInformation (req: express.Request, res: express.Response) {// We did not load channels in res.locals.userconst user = await UserModel.loadByUsernameAndPopulateChannels(res.locals.oauth.token.user.username)return res.json(user.toFormattedJSON())}-async function getUserVideoQuotaUsed (req: express.Request, res: express.Response, next: express.NextFunction) {+async function getUserVideoQuotaUsed (req: express.Request, res: express.Response) {// We did not load channels in res.locals.userconst user = await UserModel.loadByUsernameAndPopulateChannels(res.locals.oauth.token.user.username)const videoQuotaUsed = await UserModel.getOriginalVideoFileTotalFromUser(user)@@ -143,7 +143,7 @@ async function getUserVideoQuotaUsed (req: express.Request, res: express.Responsreturn res.json(data)}-async function getUserVideoRating (req: express.Request, res: express.Response, next: express.NextFunction) {+async function getUserVideoRating (req: express.Request, res: express.Response) {const videoId = res.locals.video.idconst accountId = +res.locals.oauth.token.User.Account.id@@ -158,7 +158,7 @@ async function getUserVideoRating (req: express.Request, res: express.Response,}async function deleteMe (req: express.Request, res: express.Response) {- const user: UserModel = res.locals.oauth.token.User+ const user = res.locals.oauth.token.Userawait user.destroy()@@ -170,7 +170,7 @@ async function deleteMe (req: express.Request, res: express.Response) {async function updateMe (req: express.Request, res: express.Response) {const body: UserUpdateMe = req.body- const user: UserModel = res.locals.oauth.token.user+ const user = res.locals.oauth.token.userconst oldUserAuditView = new UserAuditView(user.toFormattedJSON())if (body.password !== undefined) user.password = body.password@@ -199,7 +199,7 @@ async function updateMe (req: express.Request, res: express.Response) {async function updateMyAvatar (req: express.Request, res: express.Response) {const avatarPhysicalFile = req.files[ 'avatarfile' ][ 0 ]- const user: UserModel = res.locals.oauth.token.user+ const user = res.locals.oauth.token.userconst oldUserAuditView = new UserAuditView(user.toFormattedJSON())const userAccount = await AccountModel.load(user.Account.id)diff --git a/server/controllers/api/users/my-blocklist.ts b/server/controllers/api/users/my-blocklist.tsindex 9575eab462..481e751397 100644--- a/server/controllers/api/users/my-blocklist.ts+++ b/server/controllers/api/users/my-blocklist.ts@@ -17,7 +17,6 @@ import {serversBlocklistSortValidator,unblockServerByAccountValidator} from '../../../middlewares/validators'-import { UserModel } from '../../../models/account/user'import { AccountModel } from '../../../models/account/account'import { AccountBlocklistModel } from '../../../models/account/account-blocklist'import { addAccountInBlocklist, addServerInBlocklist, removeAccountFromBlocklist, removeServerFromBlocklist } from '../../../lib/blocklist'@@ -75,7 +74,7 @@ export {// ---------------------------------------------------------------------------async function listBlockedAccounts (req: express.Request, res: express.Response) {- const user: UserModel = res.locals.oauth.token.User+ const user = res.locals.oauth.token.Userconst resultList = await AccountBlocklistModel.listForApi(user.Account.id, req.query.start, req.query.count, req.query.sort)@@ -83,8 +82,8 @@ async function listBlockedAccounts (req: express.Request, res: express.Response)}async function blockAccount (req: express.Request, res: express.Response) {- const user: UserModel = res.locals.oauth.token.User- const accountToBlock: AccountModel = res.locals.account+ const user = res.locals.oauth.token.User+ const accountToBlock = res.locals.accountawait addAccountInBlocklist(user.Account.id, accountToBlock.id)@@ -92,7 +91,7 @@ async function blockAccount (req: express.Request, res: express.Response) {}async function unblockAccount (req: express.Request, res: express.Response) {- const accountBlock: AccountBlocklistModel = res.locals.accountBlock+ const accountBlock = res.locals.accountBlockawait removeAccountFromBlocklist(accountBlock)@@ -100,7 +99,7 @@ async function unblockAccount (req: express.Request, res: express.Response) {}async function listBlockedServers (req: express.Request, res: express.Response) {- const user: UserModel = res.locals.oauth.token.User+ const user = res.locals.oauth.token.Userconst resultList = await ServerBlocklistModel.listForApi(user.Account.id, req.query.start, req.query.count, req.query.sort)@@ -108,8 +107,8 @@ async function listBlockedServers (req: express.Request, res: express.Response)}async function blockServer (req: express.Request, res: express.Response) {- const user: UserModel = res.locals.oauth.token.User- const serverToBlock: ServerModel = res.locals.server+ const user = res.locals.oauth.token.User+ const serverToBlock = res.locals.serverawait addServerInBlocklist(user.Account.id, serverToBlock.id)@@ -117,7 +116,7 @@ async function blockServer (req: express.Request, res: express.Response) {}async function unblockServer (req: express.Request, res: express.Response) {- const serverBlock: ServerBlocklistModel = res.locals.serverBlock+ const serverBlock = res.locals.serverBlockawait removeServerFromBlocklist(serverBlock)diff --git a/server/controllers/api/users/my-history.ts b/server/controllers/api/users/my-history.tsindex 6cd782c479..b30d3aec2b 100644--- a/server/controllers/api/users/my-history.ts+++ b/server/controllers/api/users/my-history.ts@@ -36,7 +36,7 @@ export {// ---------------------------------------------------------------------------async function listMyVideosHistory (req: express.Request, res: express.Response) {- const user: UserModel = res.locals.oauth.token.User+ const user = res.locals.oauth.token.Userconst resultList = await UserVideoHistoryModel.listForApi(user, req.query.start, req.query.count)@@ -44,7 +44,7 @@ async function listMyVideosHistory (req: express.Request, res: express.Response)}async function removeUserHistory (req: express.Request, res: express.Response) {- const user: UserModel = res.locals.oauth.token.User+ const user = res.locals.oauth.token.Userconst beforeDate = req.body.beforeDate || nullawait sequelizeTypescript.transaction(t => {diff --git a/server/controllers/api/users/my-notifications.ts b/server/controllers/api/users/my-notifications.tsindex 76cf975879..bbafda5a6e 100644--- a/server/controllers/api/users/my-notifications.ts+++ b/server/controllers/api/users/my-notifications.ts@@ -9,7 +9,6 @@ import {setDefaultSort,userNotificationsSortValidator} from '../../../middlewares'-import { UserModel } from '../../../models/account/user'import { getFormattedObjects } from '../../../helpers/utils'import { UserNotificationModel } from '../../../models/account/user-notification'import { meRouter } from './me'@@ -57,8 +56,8 @@ export {// ---------------------------------------------------------------------------async function updateNotificationSettings (req: express.Request, res: express.Response) {- const user: UserModel = res.locals.oauth.token.User- const body = req.body+ const user = res.locals.oauth.token.User+ const body = req.body as UserNotificationSettingconst query = {where: {@@ -84,7 +83,7 @@ async function updateNotificationSettings (req: express.Request, res: express.Re}async function listUserNotifications (req: express.Request, res: express.Response) {- const user: UserModel = res.locals.oauth.token.User+ const user = res.locals.oauth.token.Userconst resultList = await UserNotificationModel.listForApi(user.id, req.query.start, req.query.count, req.query.sort, req.query.unread)@@ -92,7 +91,7 @@ async function listUserNotifications (req: express.Request, res: express.Respons}async function markAsReadUserNotifications (req: express.Request, res: express.Response) {- const user: UserModel = res.locals.oauth.token.User+ const user = res.locals.oauth.token.Userawait UserNotificationModel.markAsRead(user.id, req.body.ids)@@ -100,7 +99,7 @@ async function markAsReadUserNotifications (req: express.Request, res: express.R}async function markAsReadAllUserNotifications (req: express.Request, res: express.Response) {- const user: UserModel = res.locals.oauth.token.User+ const user = res.locals.oauth.token.Userawait UserNotificationModel.markAllAsRead(user.id)diff --git a/server/controllers/api/users/my-subscriptions.ts b/server/controllers/api/users/my-subscriptions.tsindex accca6d520..a173adfd0b 100644--- a/server/controllers/api/users/my-subscriptions.ts+++ b/server/controllers/api/users/my-subscriptions.ts@@ -14,7 +14,6 @@ import {userSubscriptionGetValidator} from '../../../middlewares'import { areSubscriptionsExistValidator, userSubscriptionsSortValidator, videosSortValidator } from '../../../middlewares/validators'-import { UserModel } from '../../../models/account/user'import { VideoModel } from '../../../models/video/video'import { buildNSFWFilter } from '../../../helpers/express-utils'import { VideoFilter } from '../../../../shared/models/videos/video-query.type'@@ -77,7 +76,7 @@ export {async function areSubscriptionsExist (req: express.Request, res: express.Response) {const uris = req.query.uris as string[]- const user = res.locals.oauth.token.User as UserModel+ const user = res.locals.oauth.token.Userconst handles = uris.map(u => {let [ name, host ] = u.split('@')@@ -107,7 +106,7 @@ async function areSubscriptionsExist (req: express.Request, res: express.Respons}async function addUserSubscription (req: express.Request, res: express.Response) {- const user = res.locals.oauth.token.User as UserModel+ const user = res.locals.oauth.token.Userconst [ name, host ] = req.body.uri.split('@')const payload = {@@ -123,13 +122,13 @@ async function addUserSubscription (req: express.Request, res: express.Response)}function getUserSubscription (req: express.Request, res: express.Response) {- const subscription: ActorFollowModel = res.locals.subscription+ const subscription = res.locals.subscriptionreturn res.json(subscription.ActorFollowing.VideoChannel.toFormattedJSON())}async function deleteUserSubscription (req: express.Request, res: express.Response) {- const subscription: ActorFollowModel = res.locals.subscription+ const subscription = res.locals.subscriptionawait sequelizeTypescript.transaction(async t => {return subscription.destroy({ transaction: t })@@ -139,7 +138,7 @@ async function deleteUserSubscription (req: express.Request, res: express.Respon}async function getUserSubscriptions (req: express.Request, res: express.Response) {- const user = res.locals.oauth.token.User as UserModel+ const user = res.locals.oauth.token.Userconst actorId = user.Account.Actor.idconst resultList = await ActorFollowModel.listSubscriptionsForApi(actorId, req.query.start, req.query.count, req.query.sort)@@ -147,8 +146,8 @@ async function getUserSubscriptions (req: express.Request, res: express.Responsereturn res.json(getFormattedObjects(resultList.data, resultList.total))}-async function getUserSubscriptionVideos (req: express.Request, res: express.Response, next: express.NextFunction) {- const user = res.locals.oauth.token.User as UserModel+async function getUserSubscriptionVideos (req: express.Request, res: express.Response) {+ const user = res.locals.oauth.token.Userconst resultList = await VideoModel.listForApi({start: req.query.start,count: req.query.count,diff --git a/server/controllers/api/users/my-video-playlists.ts b/server/controllers/api/users/my-video-playlists.tsindex 42da02bff9..15e92f4f3f 100644--- a/server/controllers/api/users/my-video-playlists.ts+++ b/server/controllers/api/users/my-video-playlists.ts@@ -1,6 +1,5 @@import * as express from 'express'import { asyncMiddleware, authenticate } from '../../../middlewares'-import { UserModel } from '../../../models/account/user'import { doVideosInPlaylistExistValidator } from '../../../middlewares/validators/videos/video-playlists'import { VideoPlaylistModel } from '../../../models/video/video-playlist'import { VideoExistInPlaylist } from '../../../../shared/models/videos/playlist/video-exist-in-playlist.model'@@ -23,7 +22,7 @@ export {async function doVideosInPlaylistExist (req: express.Request, res: express.Response) {const videoIds = req.query.videoIds.map(i => parseInt(i + '', 10))- const user = res.locals.oauth.token.User as UserModel+ const user = res.locals.oauth.token.Userconst results = await VideoPlaylistModel.listPlaylistIdsOf(user.Account.id, videoIds)diff --git a/server/controllers/api/video-channel.ts b/server/controllers/api/video-channel.tsindex c13aed4dc8..5881cab41d 100644--- a/server/controllers/api/video-channel.ts+++ b/server/controllers/api/video-channel.ts@@ -30,7 +30,6 @@ import { updateAvatarValidator } from '../../middlewares/validators/avatar'import { updateActorAvatarFile } from '../../lib/avatar'import { auditLoggerFactory, getAuditIdFromRes, VideoChannelAuditView } from '../../helpers/audit-logger'import { resetSequelizeInstance } from '../../helpers/database-utils'-import { UserModel } from '../../models/account/user'import { JobQueue } from '../../lib/job-queue'import { VideoPlaylistModel } from '../../models/video/video-playlist'import { commonVideoPlaylistFiltersValidator } from '../../middlewares/validators/videos/video-playlists'@@ -109,16 +108,16 @@ export {// ----------------------------------------------------------------------------async function listVideoChannels (req: express.Request, res: express.Response, next: express.NextFunction) {+async function listVideoChannels (req: express.Request, res: express.Response) {const serverActor = await getServerActor()const resultList = await VideoChannelModel.listForApi(serverActor.id, req.query.start, req.query.count, req.query.sort)return res.json(getFormattedObjects(resultList.data, resultList.total))}-async function updateVideoChannelAvatar (req: express.Request, res: express.Response, next: express.NextFunction) {+async function updateVideoChannelAvatar (req: express.Request, res: express.Response) {const avatarPhysicalFile = req.files[ 'avatarfile' ][ 0 ]- const videoChannel = res.locals.videoChannel as VideoChannelModel+ const videoChannel = res.locals.videoChannelconst oldVideoChannelAuditKeys = new VideoChannelAuditView(videoChannel.toFormattedJSON())const avatar = await updateActorAvatarFile(avatarPhysicalFile, videoChannel)@@ -136,7 +135,7 @@ async function addVideoChannel (req: express.Request, res: express.Response) {const videoChannelInfo: VideoChannelCreate = req.bodyconst videoChannelCreated: VideoChannelModel = await sequelizeTypescript.transaction(async t => {- const account = await AccountModel.load((res.locals.oauth.token.User as UserModel).Account.id, t)+ const account = await AccountModel.load(res.locals.oauth.token.User.Account.id, t)return createVideoChannel(videoChannelInfo, account, t)})@@ -156,7 +155,7 @@ async function addVideoChannel (req: express.Request, res: express.Response) {}async function updateVideoChannel (req: express.Request, res: express.Response) {- const videoChannelInstance = res.locals.videoChannel as VideoChannelModel+ const videoChannelInstance = res.locals.videoChannelconst videoChannelFieldsSave = videoChannelInstance.toJSON()const oldVideoChannelAuditKeys = new VideoChannelAuditView(videoChannelInstance.toFormattedJSON())const videoChannelInfoToUpdate = req.body as VideoChannelUpdate@@ -196,7 +195,7 @@ async function updateVideoChannel (req: express.Request, res: express.Response)}async function removeVideoChannel (req: express.Request, res: express.Response) {- const videoChannelInstance: VideoChannelModel = res.locals.videoChannel+ const videoChannelInstance = res.locals.videoChannelawait sequelizeTypescript.transaction(async t => {await VideoPlaylistModel.resetPlaylistsOfChannel(videoChannelInstance.id, t)@@ -210,7 +209,7 @@ async function removeVideoChannel (req: express.Request, res: express.Response)return res.type('json').status(204).end()}-async function getVideoChannel (req: express.Request, res: express.Response, next: express.NextFunction) {+async function getVideoChannel (req: express.Request, res: express.Response) {const videoChannelWithVideos = await VideoChannelModel.loadAndPopulateAccountAndVideos(res.locals.videoChannel.id)if (videoChannelWithVideos.isOutdated()) {@@ -236,8 +235,8 @@ async function listVideoChannelPlaylists (req: express.Request, res: express.Resreturn res.json(getFormattedObjects(resultList.data, resultList.total))}-async function listVideoChannelVideos (req: express.Request, res: express.Response, next: express.NextFunction) {- const videoChannelInstance: VideoChannelModel = res.locals.videoChannel+async function listVideoChannelVideos (req: express.Request, res: express.Response) {+ const videoChannelInstance = res.locals.videoChannelconst followerActorId = isUserAbleToSearchRemoteURI(res) ? null : undefinedconst resultList = await VideoModel.listForApi({diff --git a/server/controllers/api/video-playlist.ts b/server/controllers/api/video-playlist.tsindex c7dfc583b2..5b1601c4eb 100644--- a/server/controllers/api/video-playlist.ts+++ b/server/controllers/api/video-playlist.ts@@ -10,7 +10,6 @@ import {setDefaultPagination,setDefaultSort} from '../../middlewares'-import { VideoChannelModel } from '../../models/video/video-channel'import { videoPlaylistsSortValidator } from '../../middlewares/validators'import { buildNSFWFilter, createReqFiles, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils'import { CONFIG, MIMETYPES, sequelizeTypescript, THUMBNAILS_SIZE, VIDEO_PLAYLIST_PRIVACIES } from '../../initializers'@@ -31,7 +30,6 @@ import { VideoPlaylistCreate } from '../../../shared/models/videos/playlist/videimport { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model'import { processImage } from '../../helpers/image-utils'import { join } from 'path'-import { UserModel } from '../../models/account/user'import { sendCreateVideoPlaylist, sendDeleteVideoPlaylist, sendUpdateVideoPlaylist } from '../../lib/activitypub/send'import { getVideoPlaylistActivityPubUrl, getVideoPlaylistElementActivityPubUrl } from '../../lib/activitypub/url'import { VideoPlaylistUpdate } from '../../../shared/models/videos/playlist/video-playlist-update.model'@@ -142,14 +140,14 @@ async function listVideoPlaylists (req: express.Request, res: express.Response)}function getVideoPlaylist (req: express.Request, res: express.Response) {- const videoPlaylist = res.locals.videoPlaylist as VideoPlaylistModel+ const videoPlaylist = res.locals.videoPlaylistreturn res.json(videoPlaylist.toFormattedJSON())}async function addVideoPlaylist (req: express.Request, res: express.Response) {const videoPlaylistInfo: VideoPlaylistCreate = req.body- const user: UserModel = res.locals.oauth.token.User+ const user = res.locals.oauth.token.Userconst videoPlaylist = new VideoPlaylistModel({name: videoPlaylistInfo.displayName,@@ -161,7 +159,7 @@ async function addVideoPlaylist (req: express.Request, res: express.Response) {videoPlaylist.url = getVideoPlaylistActivityPubUrl(videoPlaylist) // We use the UUID, so set the URL after building the objectif (videoPlaylistInfo.videoChannelId) {- const videoChannel = res.locals.videoChannel as VideoChannelModel+ const videoChannel = res.locals.videoChannelvideoPlaylist.videoChannelId = videoChannel.idvideoPlaylist.VideoChannel = videoChannel@@ -194,7 +192,7 @@ async function addVideoPlaylist (req: express.Request, res: express.Response) {}async function updateVideoPlaylist (req: express.Request, res: express.Response) {- const videoPlaylistInstance = res.locals.videoPlaylist as VideoPlaylistModel+ const videoPlaylistInstance = res.locals.videoPlaylistconst videoPlaylistFieldsSave = videoPlaylistInstance.toJSON()const videoPlaylistInfoToUpdate = req.body as VideoPlaylistUpdateconst wasPrivatePlaylist = videoPlaylistInstance.privacy === VideoPlaylistPrivacy.PRIVATE@@ -219,7 +217,7 @@ async function updateVideoPlaylist (req: express.Request, res: express.Response)if (videoPlaylistInfoToUpdate.videoChannelId === null) {videoPlaylistInstance.videoChannelId = null} else {- const videoChannel = res.locals.videoChannel as VideoChannelModel+ const videoChannel = res.locals.videoChannelvideoPlaylistInstance.videoChannelId = videoChannel.idvideoPlaylistInstance.VideoChannel = videoChannel@@ -262,7 +260,7 @@ async function updateVideoPlaylist (req: express.Request, res: express.Response)}async function removeVideoPlaylist (req: express.Request, res: express.Response) {- const videoPlaylistInstance: VideoPlaylistModel = res.locals.videoPlaylist+ const videoPlaylistInstance = res.locals.videoPlaylistawait sequelizeTypescript.transaction(async t => {await videoPlaylistInstance.destroy({ transaction: t })@@ -277,8 +275,8 @@ async function removeVideoPlaylist (req: express.Request, res: express.Response)async function addVideoInPlaylist (req: express.Request, res: express.Response) {const body: VideoPlaylistElementCreate = req.body- const videoPlaylist: VideoPlaylistModel = res.locals.videoPlaylist- const video: VideoModel = res.locals.video+ const videoPlaylist = res.locals.videoPlaylist+ const video = res.locals.videoconst playlistElement: VideoPlaylistElementModel = await sequelizeTypescript.transaction(async t => {const position = await VideoPlaylistElementModel.getNextPositionOf(videoPlaylist.id, t)@@ -323,8 +321,8 @@ async function addVideoInPlaylist (req: express.Request, res: express.Response)async function updateVideoPlaylistElement (req: express.Request, res: express.Response) {const body: VideoPlaylistElementUpdate = req.body- const videoPlaylist: VideoPlaylistModel = res.locals.videoPlaylist- const videoPlaylistElement: VideoPlaylistElementModel = res.locals.videoPlaylistElement+ const videoPlaylist = res.locals.videoPlaylist+ const videoPlaylistElement = res.locals.videoPlaylistElementconst playlistElement: VideoPlaylistElementModel = await sequelizeTypescript.transaction(async t => {if (body.startTimestamp !== undefined) videoPlaylistElement.startTimestamp = body.startTimestamp@@ -346,8 +344,8 @@ async function updateVideoPlaylistElement (req: express.Request, res: express.Re}async function removeVideoFromPlaylist (req: express.Request, res: express.Response) {- const videoPlaylistElement: VideoPlaylistElementModel = res.locals.videoPlaylistElement- const videoPlaylist: VideoPlaylistModel = res.locals.videoPlaylist+ const videoPlaylistElement = res.locals.videoPlaylistElement+ const videoPlaylist = res.locals.videoPlaylistconst positionToDelete = videoPlaylistElement.positionawait sequelizeTypescript.transaction(async t => {@@ -368,7 +366,7 @@ async function removeVideoFromPlaylist (req: express.Request, res: express.Respo}async function reorderVideosPlaylist (req: express.Request, res: express.Response) {- const videoPlaylist: VideoPlaylistModel = res.locals.videoPlaylist+ const videoPlaylist = res.locals.videoPlaylistconst body: VideoPlaylistReorder = req.bodyconst start: number = body.startPosition@@ -416,7 +414,7 @@ async function reorderVideosPlaylist (req: express.Request, res: express.Respons}async function getVideoPlaylistVideos (req: express.Request, res: express.Response) {- const videoPlaylistInstance: VideoPlaylistModel = res.locals.videoPlaylist+ const videoPlaylistInstance = res.locals.videoPlaylistconst followerActorId = isUserAbleToSearchRemoteURI(res) ? null : undefinedconst resultList = await VideoModel.listForApi({diff --git a/server/controllers/api/videos/abuse.ts b/server/controllers/api/videos/abuse.tsindex 32f9c47937..ca70230a2f 100644--- a/server/controllers/api/videos/abuse.ts+++ b/server/controllers/api/videos/abuse.ts@@ -17,10 +17,8 @@ import {videoAbuseUpdateValidator} from '../../../middlewares'import { AccountModel } from '../../../models/account/account'-import { VideoModel } from '../../../models/video/video'import { VideoAbuseModel } from '../../../models/video/video-abuse'import { auditLoggerFactory, VideoAbuseAuditView } from '../../../helpers/audit-logger'-import { UserModel } from '../../../models/account/user'import { Notifier } from '../../../lib/notifier'import { sendVideoAbuse } from '../../../lib/activitypub/send/send-flag'@@ -69,7 +67,7 @@ async function listVideoAbuses (req: express.Request, res: express.Response) {}async function updateVideoAbuse (req: express.Request, res: express.Response) {- const videoAbuse: VideoAbuseModel = res.locals.videoAbuse+ const videoAbuse = res.locals.videoAbuseif (req.body.moderationComment !== undefined) videoAbuse.moderationComment = req.body.moderationCommentif (req.body.state !== undefined) videoAbuse.state = req.body.state@@ -84,7 +82,7 @@ async function updateVideoAbuse (req: express.Request, res: express.Response) {}async function deleteVideoAbuse (req: express.Request, res: express.Response) {- const videoAbuse: VideoAbuseModel = res.locals.videoAbuse+ const videoAbuse = res.locals.videoAbuseawait sequelizeTypescript.transaction(t => {return videoAbuse.destroy({ transaction: t })@@ -96,11 +94,11 @@ async function deleteVideoAbuse (req: express.Request, res: express.Response) {}async function reportVideoAbuse (req: express.Request, res: express.Response) {- const videoInstance = res.locals.video as VideoModel+ const videoInstance = res.locals.videoconst body: VideoAbuseCreate = req.bodyconst videoAbuse: VideoAbuseModel = await sequelizeTypescript.transaction(async t => {- const reporterAccount = await AccountModel.load((res.locals.oauth.token.User as UserModel).Account.id, t)+ const reporterAccount = await AccountModel.load(res.locals.oauth.token.User.Account.id, t)const abuseToCreate = {reporterAccountId: reporterAccount.id,diff --git a/server/controllers/api/videos/blacklist.ts b/server/controllers/api/videos/blacklist.tsindex b01296200c..d0728eb590 100644--- a/server/controllers/api/videos/blacklist.ts+++ b/server/controllers/api/videos/blacklist.ts@@ -17,7 +17,6 @@ import {import { VideoBlacklistModel } from '../../../models/video/video-blacklist'import { sequelizeTypescript } from '../../../initializers'import { Notifier } from '../../../lib/notifier'-import { VideoModel } from '../../../models/video/video'import { sendDeleteVideo } from '../../../lib/activitypub/send'import { federateVideoIfNeeded } from '../../../lib/activitypub'@@ -87,7 +86,7 @@ async function addVideoToBlacklist (req: express.Request, res: express.Response)}async function updateVideoBlacklistController (req: express.Request, res: express.Response) {- const videoBlacklist = res.locals.videoBlacklist as VideoBlacklistModel+ const videoBlacklist = res.locals.videoBlacklistif (req.body.reason !== undefined) videoBlacklist.reason = req.body.reason@@ -105,8 +104,8 @@ async function listBlacklist (req: express.Request, res: express.Response, next:}async function removeVideoFromBlacklistController (req: express.Request, res: express.Response, next: express.NextFunction) {- const videoBlacklist = res.locals.videoBlacklist as VideoBlacklistModel- const video: VideoModel = res.locals.video+ const videoBlacklist = res.locals.videoBlacklist+ const video = res.locals.videoawait sequelizeTypescript.transaction(async t => {const unfederated = videoBlacklist.unfederateddiff --git a/server/controllers/api/videos/captions.ts b/server/controllers/api/videos/captions.tsindex 9b36613688..2694577d8f 100644--- a/server/controllers/api/videos/captions.ts+++ b/server/controllers/api/videos/captions.ts@@ -5,7 +5,6 @@ import { createReqFiles } from '../../../helpers/express-utils'import { CONFIG, MIMETYPES, sequelizeTypescript } from '../../../initializers'import { getFormattedObjects } from '../../../helpers/utils'import { VideoCaptionModel } from '../../../models/video/video-caption'-import { VideoModel } from '../../../models/video/video'import { logger } from '../../../helpers/logger'import { federateVideoIfNeeded } from '../../../lib/activitypub'import { moveAndProcessCaptionFile } from '../../../helpers/captions-utils'@@ -52,7 +51,7 @@ async function listVideoCaptions (req: express.Request, res: express.Response) {async function addVideoCaption (req: express.Request, res: express.Response) {const videoCaptionPhysicalFile = req.files['captionfile'][0]- const video = res.locals.video as VideoModel+ const video = res.locals.videoconst videoCaption = new VideoCaptionModel({videoId: video.id,@@ -74,8 +73,8 @@ async function addVideoCaption (req: express.Request, res: express.Response) {}async function deleteVideoCaption (req: express.Request, res: express.Response) {- const video = res.locals.video as VideoModel- const videoCaption = res.locals.videoCaption as VideoCaptionModel+ const video = res.locals.video+ const videoCaption = res.locals.videoCaptionawait sequelizeTypescript.transaction(async t => {await videoCaption.destroy({ transaction: t })diff --git a/server/controllers/api/videos/comment.ts b/server/controllers/api/videos/comment.tsindex 70c1148ba3..176ee8bd4d 100644--- a/server/controllers/api/videos/comment.ts+++ b/server/controllers/api/videos/comment.ts@@ -8,7 +8,8 @@ import { buildFormattedCommentTree, createVideoComment } from '../../../lib/videimport {asyncMiddleware,asyncRetryTransactionMiddleware,- authenticate, optionalAuthenticate,+ authenticate,+ optionalAuthenticate,paginationValidator,setDefaultPagination,setDefaultSort@@ -21,11 +22,9 @@ import {removeVideoCommentValidator,videoCommentThreadsSortValidator} from '../../../middlewares/validators'-import { VideoModel } from '../../../models/video/video'import { VideoCommentModel } from '../../../models/video/video-comment'import { auditLoggerFactory, CommentAuditView, getAuditIdFromRes } from '../../../helpers/audit-logger'import { AccountModel } from '../../../models/account/account'-import { UserModel } from '../../../models/account/user'import { Notifier } from '../../../lib/notifier'const auditLogger = auditLoggerFactory('comments')@@ -70,9 +69,9 @@ export {// ----------------------------------------------------------------------------async function listVideoThreads (req: express.Request, res: express.Response, next: express.NextFunction) {- const video = res.locals.video as VideoModel- const user: UserModel = res.locals.oauth ? res.locals.oauth.token.User : undefined+async function listVideoThreads (req: express.Request, res: express.Response) {+ const video = res.locals.video+ const user = res.locals.oauth ? res.locals.oauth.token.User : undefinedlet resultList: ResultList<VideoCommentModel>@@ -88,9 +87,9 @@ async function listVideoThreads (req: express.Request, res: express.Response, nereturn res.json(getFormattedObjects(resultList.data, resultList.total))}-async function listVideoThreadComments (req: express.Request, res: express.Response, next: express.NextFunction) {- const video = res.locals.video as VideoModel- const user: UserModel = res.locals.oauth ? res.locals.oauth.token.User : undefined+async function listVideoThreadComments (req: express.Request, res: express.Response) {+ const video = res.locals.video+ const user = res.locals.oauth ? res.locals.oauth.token.User : undefinedlet resultList: ResultList<VideoCommentModel>@@ -110,7 +109,7 @@ async function addVideoCommentThread (req: express.Request, res: express.Responsconst videoCommentInfo: VideoCommentCreate = req.bodyconst comment = await sequelizeTypescript.transaction(async t => {- const account = await AccountModel.load((res.locals.oauth.token.User as UserModel).Account.id, t)+ const account = await AccountModel.load(res.locals.oauth.token.User.Account.id, t)return createVideoComment({text: videoCommentInfo.text,@@ -132,7 +131,7 @@ async function addVideoCommentReply (req: express.Request, res: express.Responseconst videoCommentInfo: VideoCommentCreate = req.bodyconst comment = await sequelizeTypescript.transaction(async t => {- const account = await AccountModel.load((res.locals.oauth.token.User as UserModel).Account.id, t)+ const account = await AccountModel.load(res.locals.oauth.token.User.Account.id, t)return createVideoComment({text: videoCommentInfo.text,@@ -149,7 +148,7 @@ async function addVideoCommentReply (req: express.Request, res: express.Response}async function removeVideoComment (req: express.Request, res: express.Response) {- const videoCommentInstance: VideoCommentModel = res.locals.videoComment+ const videoCommentInstance = res.locals.videoCommentawait sequelizeTypescript.transaction(async t => {await videoCommentInstance.destroy({ transaction: t })diff --git a/server/controllers/api/videos/import.ts b/server/controllers/api/videos/import.tsindex 626c81ecaf..cbd2e85148 100644--- a/server/controllers/api/videos/import.ts+++ b/server/controllers/api/videos/import.ts@@ -97,7 +97,7 @@ async function addTorrentImport (req: express.Request, res: express.Response, tostate: VideoImportState.PENDING,userId: user.id}- const videoImport: VideoImportModel = await insertIntoDB(video, res.locals.videoChannel, tags, videoImportAttributes)+ const videoImport = await insertIntoDB(video, res.locals.videoChannel, tags, videoImportAttributes)// Create job to import the videoconst payload = {@@ -139,7 +139,7 @@ async function addYoutubeDLImport (req: express.Request, res: express.Response)state: VideoImportState.PENDING,userId: user.id}- const videoImport: VideoImportModel = await insertIntoDB(video, res.locals.videoChannel, tags, videoImportAttributes)+ const videoImport = await insertIntoDB(video, res.locals.videoChannel, tags, videoImportAttributes)// Create job to import the videoconst payload = {diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.tsindex 27f67895e6..db4f4c96ff 100644--- a/server/controllers/api/videos/index.ts+++ b/server/controllers/api/videos/index.ts@@ -295,7 +295,7 @@ async function addVideo (req: express.Request, res: express.Response) {}async function updateVideo (req: express.Request, res: express.Response) {- const videoInstance: VideoModel = res.locals.video+ const videoInstance = res.locals.videoconst videoFieldsSave = videoInstance.toJSON()const oldVideoAuditView = new VideoAuditView(videoInstance.toFormattedDetailsJSON())const videoInfoToUpdate: VideoUpdate = req.body@@ -407,7 +407,7 @@ async function updateVideo (req: express.Request, res: express.Response) {async function getVideo (req: express.Request, res: express.Response) {// We need more attributesconst userId: number = res.locals.oauth ? res.locals.oauth.token.User.id : null- const video: VideoModel = await VideoModel.loadForGetAPI(res.locals.video.id, undefined, userId)+ const video = await VideoModel.loadForGetAPI(res.locals.video.id, undefined, userId)if (video.isOutdated()) {JobQueue.Instance.createJob({ type: 'activitypub-refresher', payload: { type: 'video', url: video.url } })@@ -472,7 +472,7 @@ async function listVideos (req: express.Request, res: express.Response) {}async function removeVideo (req: express.Request, res: express.Response) {- const videoInstance: VideoModel = res.locals.video+ const videoInstance = res.locals.videoawait sequelizeTypescript.transaction(async t => {await videoInstance.destroy({ transaction: t })diff --git a/server/controllers/api/videos/ownership.ts b/server/controllers/api/videos/ownership.tsindex 5ea7d7c6a3..fc73856c9e 100644--- a/server/controllers/api/videos/ownership.ts+++ b/server/controllers/api/videos/ownership.ts@@ -11,8 +11,6 @@ import {videosChangeOwnershipValidator,videosTerminateChangeOwnershipValidator} from '../../../middlewares'-import { AccountModel } from '../../../models/account/account'-import { VideoModel } from '../../../models/video/video'import { VideoChangeOwnershipModel } from '../../../models/video/video-change-ownership'import { VideoChangeOwnershipStatus, VideoPrivacy, VideoState } from '../../../../shared/models/videos'import { VideoChannelModel } from '../../../models/video/video-channel'@@ -58,9 +56,9 @@ export {// ---------------------------------------------------------------------------async function giveVideoOwnership (req: express.Request, res: express.Response) {- const videoInstance = res.locals.video as VideoModel- const initiatorAccountId = (res.locals.oauth.token.User as UserModel).Account.id- const nextOwner = res.locals.nextOwner as AccountModel+ const videoInstance = res.locals.video+ const initiatorAccountId = res.locals.oauth.token.User.Account.id+ const nextOwner = res.locals.nextOwnerawait sequelizeTypescript.transaction(t => {return VideoChangeOwnershipModel.findOrCreate({@@ -85,7 +83,7 @@ async function giveVideoOwnership (req: express.Request, res: express.Response)}async function listVideoOwnership (req: express.Request, res: express.Response) {- const currentAccountId = (res.locals.oauth.token.User as UserModel).Account.id+ const currentAccountId = res.locals.oauth.token.User.Account.idconst resultList = await VideoChangeOwnershipModel.listForApi(currentAccountId,@@ -99,9 +97,9 @@ async function listVideoOwnership (req: express.Request, res: express.Response)async function acceptOwnership (req: express.Request, res: express.Response) {return sequelizeTypescript.transaction(async t => {- const videoChangeOwnership = res.locals.videoChangeOwnership as VideoChangeOwnershipModel+ const videoChangeOwnership = res.locals.videoChangeOwnershipconst targetVideo = videoChangeOwnership.Video- const channel = res.locals.videoChannel as VideoChannelModel+ const channel = res.locals.videoChannelconst oldVideoChannel = await VideoChannelModel.loadByIdAndPopulateAccount(targetVideo.channelId)@@ -123,7 +121,7 @@ async function acceptOwnership (req: express.Request, res: express.Response) {async function refuseOwnership (req: express.Request, res: express.Response) {return sequelizeTypescript.transaction(async t => {- const videoChangeOwnership = res.locals.videoChangeOwnership as VideoChangeOwnershipModel+ const videoChangeOwnership = res.locals.videoChangeOwnershipvideoChangeOwnership.set('status', VideoChangeOwnershipStatus.REFUSED)await videoChangeOwnership.save({ transaction: t })diff --git a/server/controllers/api/videos/rate.ts b/server/controllers/api/videos/rate.tsindex 53952a0a24..914c596c34 100644--- a/server/controllers/api/videos/rate.ts+++ b/server/controllers/api/videos/rate.ts@@ -6,7 +6,6 @@ import { getRateUrl, sendVideoRateChange } from '../../../lib/activitypub'import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoUpdateRateValidator } from '../../../middlewares'import { AccountModel } from '../../../models/account/account'import { AccountVideoRateModel } from '../../../models/account/account-video-rate'-import { VideoModel } from '../../../models/video/video'const rateVideoRouter = express.Router()@@ -27,8 +26,8 @@ export {async function rateVideo (req: express.Request, res: express.Response) {const body: UserVideoRateUpdate = req.bodyconst rateType = body.rating- const videoInstance: VideoModel = res.locals.video- const userAccount: AccountModel = res.locals.oauth.token.User.Account+ const videoInstance = res.locals.video+ const userAccount = res.locals.oauth.token.User.Accountawait sequelizeTypescript.transaction(async t => {const sequelizeOptions = { transaction: t }diff --git a/server/controllers/api/videos/watching.ts b/server/controllers/api/videos/watching.tsindex e8876b47a0..6bc60e045b 100644--- a/server/controllers/api/videos/watching.ts+++ b/server/controllers/api/videos/watching.ts@@ -21,7 +21,7 @@ export {// ---------------------------------------------------------------------------async function userWatchVideo (req: express.Request, res: express.Response) {- const user = res.locals.oauth.token.User as UserModel+ const user = res.locals.oauth.token.Userconst body: UserWatchingVideo = req.bodyconst { id: videoId } = res.locals.video as { id: number }diff --git a/server/controllers/feeds.ts b/server/controllers/feeds.tsindex 960085af1a..cd46b6e0f6 100644--- a/server/controllers/feeds.ts+++ b/server/controllers/feeds.ts@@ -11,9 +11,7 @@ import {} from '../middlewares'import { VideoModel } from '../models/video/video'import * as Feed from 'pfeed'-import { AccountModel } from '../models/account/account'import { cacheRoute } from '../middlewares/cache'-import { VideoChannelModel } from '../models/video/video-channel'import { VideoCommentModel } from '../models/video/video-comment'import { buildNSFWFilter } from '../helpers/express-utils'@@ -42,10 +40,10 @@ export {// ----------------------------------------------------------------------------async function generateVideoCommentsFeed (req: express.Request, res: express.Response, next: express.NextFunction) {+async function generateVideoCommentsFeed (req: express.Request, res: express.Response) {const start = 0- const video = res.locals.video as VideoModel+ const video = res.locals.videoconst videoId: number = video ? video.id : undefinedconst comments = await VideoCommentModel.listForFeed(start, FEEDS.COUNT, videoId)@@ -77,11 +75,11 @@ async function generateVideoCommentsFeed (req: express.Request, res: express.Resreturn sendFeed(feed, req, res)}-async function generateVideoFeed (req: express.Request, res: express.Response, next: express.NextFunction) {+async function generateVideoFeed (req: express.Request, res: express.Response) {const start = 0- const account: AccountModel = res.locals.account- const videoChannel: VideoChannelModel = res.locals.videoChannel+ const account = res.locals.account+ const videoChannel = res.locals.videoChannelconst nsfw = buildNSFWFilter(res, req.query.nsfw)let name: stringdiff --git a/server/controllers/services.ts b/server/controllers/services.tsindex 680c3c37f4..cf7a513af8 100644--- a/server/controllers/services.ts+++ b/server/controllers/services.ts@@ -23,8 +23,8 @@ export {// ----------------------------------------------------------------------------function generateOEmbed (req: express.Request, res: express.Response, next: express.NextFunction) {- const video = res.locals.video as VideoModel+function generateOEmbed (req: express.Request, res: express.Response) {+ const video = res.locals.videoconst webserverUrl = CONFIG.WEBSERVER.URLconst maxHeight = parseInt(req.query.maxheight, 10)const maxWidth = parseInt(req.query.maxwidth, 10)diff --git a/server/controllers/static.ts b/server/controllers/static.tsindex 639445b749..7b14320e45 100644--- a/server/controllers/static.ts+++ b/server/controllers/static.ts@@ -245,7 +245,7 @@ async function downloadVideoFile (req: express.Request, res: express.Response, nfunction getVideoAndFile (req: express.Request, res: express.Response) {const resolution = parseInt(req.params.resolution, 10)- const video: VideoModel = res.locals.video+ const video = res.locals.videoconst videoFile = video.VideoFiles.find(f => f.resolution === resolution)diff --git a/server/controllers/webfinger.ts b/server/controllers/webfinger.tsindex ed781c21b4..f2ba3c8266 100644--- a/server/controllers/webfinger.ts+++ b/server/controllers/webfinger.ts@@ -1,7 +1,6 @@import * as express from 'express'import { asyncMiddleware } from '../middlewares'import { webfingerValidator } from '../middlewares/validators'-import { ActorModel } from '../models/activitypub/actor'const webfingerRouter = express.Router()@@ -18,8 +17,8 @@ export {// ----------------------------------------------------------------------------function webfingerController (req: express.Request, res: express.Response, next: express.NextFunction) {- const actor = res.locals.actor as ActorModel+function webfingerController (req: express.Request, res: express.Response) {+ const actor = res.locals.actorconst json = {subject: req.query.resource,diff --git a/server/helpers/express-utils.ts b/server/helpers/express-utils.tsindex 9a72ee96da..fef2da313e 100644--- a/server/helpers/express-utils.ts+++ b/server/helpers/express-utils.ts@@ -5,7 +5,6 @@ import { logger } from './logger'import { deleteFileAsync, generateRandomString } from './utils'import { extname } from 'path'import { isArray } from './custom-validators/misc'-import { UserModel } from '../models/account/user'function buildNSFWFilter (res?: express.Response, paramNSFW?: string) {if (paramNSFW === 'true') return true@@ -13,7 +12,7 @@ function buildNSFWFilter (res?: express.Response, paramNSFW?: string) {if (paramNSFW === 'both') return undefinedif (res && res.locals.oauth) {- const user: UserModel = res.locals.oauth.token.User+ const user = res.locals.oauth.token.User// User does not want NSFW videosif (user.nsfwPolicy === 'do_not_list') return false@@ -100,7 +99,7 @@ function createReqFiles (}function isUserAbleToSearchRemoteURI (res: express.Response) {- const user: UserModel = res.locals.oauth ? res.locals.oauth.token.User : undefined+ const user = res.locals.oauth ? res.locals.oauth.token.User : undefinedreturn CONFIG.SEARCH.REMOTE_URI.ANONYMOUS === true ||(CONFIG.SEARCH.REMOTE_URI.USERS === true && user !== undefined)diff --git a/server/middlewares/activitypub.ts b/server/middlewares/activitypub.tsindex 5fa10cbfd0..c528ee250f 100644--- a/server/middlewares/activitypub.ts+++ b/server/middlewares/activitypub.ts@@ -4,7 +4,6 @@ import { logger } from '../helpers/logger'import { isHTTPSignatureVerified, isJsonLDSignatureVerified, parseHTTPSignature } from '../helpers/peertube-crypto'import { ACCEPT_HEADERS, ACTIVITY_PUB, HTTP_SIGNATURE } from '../initializers'import { getOrCreateActorAndServerAndModel } from '../lib/activitypub'-import { ActorModel } from '../models/activitypub/actor'import { loadActorUrlOrGetFromWebfinger } from '../helpers/webfinger'async function checkSignature (req: Request, res: Response, next: NextFunction) {@@ -12,7 +11,7 @@ async function checkSignature (req: Request, res: Response, next: NextFunction)const httpSignatureChecked = await checkHttpSignature(req, res)if (httpSignatureChecked !== true) return- const actor: ActorModel = res.locals.signature.actor+ const actor = res.locals.signature.actor// Forwarded activityconst bodyActor = req.body.actordiff --git a/server/middlewares/user-right.ts b/server/middlewares/user-right.tsindex 7cea7aa1e6..498e3d6777 100644--- a/server/middlewares/user-right.ts+++ b/server/middlewares/user-right.ts@@ -2,11 +2,10 @@ import * as express from 'express'import 'express-validator'import { UserRight } from '../../shared'import { logger } from '../helpers/logger'-import { UserModel } from '../models/account/user'function ensureUserHasRight (userRight: UserRight) {return function (req: express.Request, res: express.Response, next: express.NextFunction) {- const user = res.locals.oauth.token.user as UserModel+ const user = res.locals.oauth.token.userif (user.hasRight(userRight) === false) {const message = `User ${user.username} does not have right ${UserRight[userRight]} to access to ${req.path}.`logger.info(message)diff --git a/server/middlewares/validators/activitypub/activity.ts b/server/middlewares/validators/activitypub/activity.tsindex 3f9057c0c3..7582f65e76 100644--- a/server/middlewares/validators/activitypub/activity.ts+++ b/server/middlewares/validators/activitypub/activity.ts@@ -2,7 +2,6 @@ import * as express from 'express'import { isRootActivityValid } from '../../../helpers/custom-validators/activitypub/activity'import { logger } from '../../../helpers/logger'import { getServerActor } from '../../../helpers/utils'-import { ActorModel } from '../../../models/activitypub/actor'async function activityPubValidator (req: express.Request, res: express.Response, next: express.NextFunction) {logger.debug('Checking activity pub parameters')@@ -13,7 +12,7 @@ async function activityPubValidator (req: express.Request, res: express.Response}const serverActor = await getServerActor()- const remoteActor = res.locals.signature.actor as ActorModel+ const remoteActor = res.locals.signature.actorif (serverActor.id === remoteActor.id) {logger.error('Receiving request in INBOX by ourselves!', req.body)return res.status(409).end()diff --git a/server/middlewares/validators/blocklist.ts b/server/middlewares/validators/blocklist.tsindex d7ec649b6e..f5b295f458 100644--- a/server/middlewares/validators/blocklist.ts+++ b/server/middlewares/validators/blocklist.ts@@ -20,7 +20,7 @@ const blockAccountValidator = [if (areValidationErrors(req, res)) returnif (!await doesAccountNameWithHostExist(req.body.accountName, res)) return- const user = res.locals.oauth.token.User as UserModel+ const user = res.locals.oauth.token.Userconst accountToBlock = res.locals.accountif (user.Account.id === accountToBlock.id) {@@ -44,7 +44,7 @@ const unblockAccountByAccountValidator = [if (areValidationErrors(req, res)) returnif (!await doesAccountNameWithHostExist(req.params.accountName, res)) return- const user = res.locals.oauth.token.User as UserModel+ const user = res.locals.oauth.token.Userconst targetAccount = res.locals.accountif (!await doesUnblockAccountExist(user.Account.id, targetAccount.id, res)) return@@ -106,7 +106,7 @@ const unblockServerByAccountValidator = [if (areValidationErrors(req, res)) return- const user = res.locals.oauth.token.User as UserModel+ const user = res.locals.oauth.token.Userif (!await doesUnblockServerExist(user.Account.id, req.params.host, res)) returnreturn next()diff --git a/server/middlewares/validators/redundancy.ts b/server/middlewares/validators/redundancy.tsindex 4199219284..76cf89c409 100644--- a/server/middlewares/validators/redundancy.ts+++ b/server/middlewares/validators/redundancy.ts@@ -1,16 +1,12 @@import * as express from 'express'import 'express-validator'-import { param, body } from 'express-validator/check'+import { body, param } from 'express-validator/check'import { exists, isBooleanValid, isIdOrUUIDValid, toIntOrNull } from '../../helpers/custom-validators/misc'import { doesVideoExist } from '../../helpers/custom-validators/videos'import { logger } from '../../helpers/logger'import { areValidationErrors } from './utils'-import { VideoModel } from '../../models/video/video'import { VideoRedundancyModel } from '../../models/redundancy/video-redundancy'import { isHostValid } from '../../helpers/custom-validators/servers'-import { getServerActor } from '../../helpers/utils'-import { ActorFollowModel } from '../../models/activitypub/actor-follow'-import { SERVER_ACTOR_NAME } from '../../initializers'import { ServerModel } from '../../models/server/server'const videoFileRedundancyGetValidator = [@@ -29,7 +25,7 @@ const videoFileRedundancyGetValidator = [if (areValidationErrors(req, res)) returnif (!await doesVideoExist(req.params.videoId, res)) return- const video: VideoModel = res.locals.video+ const video = res.locals.videoconst videoFile = video.VideoFiles.find(f => {return f.resolution === req.params.resolution && (!req.params.fps || f.fps === req.params.fps)})@@ -55,7 +51,7 @@ const videoPlaylistRedundancyGetValidator = [if (areValidationErrors(req, res)) returnif (!await doesVideoExist(req.params.videoId, res)) return- const video: VideoModel = res.locals.video+ const video = res.locals.videoconst videoStreamingPlaylist = video.VideoStreamingPlaylists.find(p => p === req.params.streamingPlaylistType)if (!videoStreamingPlaylist) return res.status(404).json({ error: 'Video playlist not found.' })diff --git a/server/middlewares/validators/user-subscriptions.ts b/server/middlewares/validators/user-subscriptions.tsindex c5f8d9d4ce..fd82ed017a 100644--- a/server/middlewares/validators/user-subscriptions.ts+++ b/server/middlewares/validators/user-subscriptions.ts@@ -5,7 +5,6 @@ import { logger } from '../../helpers/logger'import { areValidationErrors } from './utils'import { ActorFollowModel } from '../../models/activitypub/actor-follow'import { areValidActorHandles, isValidActorHandle } from '../../helpers/custom-validators/activitypub/actor'-import { UserModel } from '../../models/account/user'import { CONFIG } from '../../initializers'import { toArray } from '../../helpers/custom-validators/misc'@@ -46,7 +45,7 @@ const userSubscriptionGetValidator = [let [ name, host ] = req.params.uri.split('@')if (host === CONFIG.WEBSERVER.HOST) host = null- const user: UserModel = res.locals.oauth.token.User+ const user = res.locals.oauth.token.Userconst subscription = await ActorFollowModel.loadByActorAndTargetNameAndHostForAPI(user.Account.Actor.id, name, host)if (!subscription || !subscription.ActorFollowing.VideoChannel) {diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.tsindex 5e8c8c29bc..e8ade0f971 100644--- a/server/middlewares/validators/users.ts+++ b/server/middlewares/validators/users.ts@@ -14,7 +14,8 @@ import {isUserRoleValid,isUserUsernameValid,isUserVideoQuotaDailyValid,- isUserVideoQuotaValid, isUserVideosHistoryEnabledValid+ isUserVideoQuotaValid,+ isUserVideosHistoryEnabledValid} from '../../helpers/custom-validators/users'import { doesVideoExist } from '../../helpers/custom-validators/videos'import { logger } from '../../helpers/logger'@@ -100,7 +101,7 @@ const usersBlockingValidator = [const deleteMeValidator = [async (req: express.Request, res: express.Response, next: express.NextFunction) => {- const user: UserModel = res.locals.oauth.token.User+ const user = res.locals.oauth.token.Userif (user.username === 'root') {return res.status(400).send({ error: 'You cannot delete your root account.' })@@ -159,8 +160,7 @@ const usersUpdateMeValidator = [.end()}- const user: UserModel = res.locals.oauth.token.User-+ const user= res.locals.oauth.token.Userif (await user.isPasswordMatch(req.body.currentPassword) !== true) {return res.status(401).send({ error: 'currentPassword is invalid.' })@@ -257,7 +257,7 @@ const usersResetPasswordValidator = [if (areValidationErrors(req, res)) returnif (!await checkUserIdExist(req.params.id, res)) return- const user = res.locals.user as UserModel+ const user = res.locals.userconst redisVerificationString = await Redis.Instance.getResetPasswordLink(user.id)if (redisVerificationString !== req.body.verificationString) {@@ -299,7 +299,7 @@ const usersVerifyEmailValidator = [if (areValidationErrors(req, res)) returnif (!await checkUserIdExist(req.params.id, res)) return- const user = res.locals.user as UserModel+ const user = res.locals.userconst redisVerificationString = await Redis.Instance.getVerifyEmailLink(user.id)if (redisVerificationString !== req.body.verificationString) {diff --git a/server/middlewares/validators/videos/video-blacklist.ts b/server/middlewares/validators/videos/video-blacklist.tsindex 77ad29cbbd..db318dcdbd 100644--- a/server/middlewares/validators/videos/video-blacklist.ts+++ b/server/middlewares/validators/videos/video-blacklist.ts@@ -5,7 +5,6 @@ import { doesVideoExist } from '../../../helpers/custom-validators/videos'import { logger } from '../../../helpers/logger'import { areValidationErrors } from '../utils'import { doesVideoBlacklistExist, isVideoBlacklistReasonValid } from '../../../helpers/custom-validators/video-blacklist'-import { VideoModel } from '../../../models/video/video'const videosBlacklistRemoveValidator = [param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),@@ -37,7 +36,7 @@ const videosBlacklistAddValidator = [if (areValidationErrors(req, res)) returnif (!await doesVideoExist(req.params.videoId, res)) return- const video: VideoModel = res.locals.video+ const video = res.locals.videoif (req.body.unfederate === true && video.remote === true) {return res.status(409)diff --git a/server/middlewares/validators/videos/video-playlists.ts b/server/middlewares/validators/videos/video-playlists.tsindex 4bc79f433b..55e09e354f 100644--- a/server/middlewares/validators/videos/video-playlists.ts+++ b/server/middlewares/validators/videos/video-playlists.ts@@ -103,7 +103,7 @@ const videoPlaylistsDeleteValidator = [if (!await doesVideoPlaylistExist(req.params.playlistId, res)) return- const videoPlaylist: VideoPlaylistModel = res.locals.videoPlaylist+ const videoPlaylist = res.locals.videoPlaylistif (videoPlaylist.type === VideoPlaylistType.WATCH_LATER) {return res.status(400).json({ error: 'Cannot delete a watch later playlist.' })@@ -128,7 +128,7 @@ const videoPlaylistsGetValidator = [if (!await doesVideoPlaylistExist(req.params.playlistId, res)) return- const videoPlaylist: VideoPlaylistModel = res.locals.videoPlaylist+ const videoPlaylist = res.locals.videoPlaylist// Video is unlisted, check we used the uuid to fetch itif (videoPlaylist.privacy === VideoPlaylistPrivacy.UNLISTED) {@@ -140,8 +140,7 @@ const videoPlaylistsGetValidator = [if (videoPlaylist.privacy === VideoPlaylistPrivacy.PRIVATE) {await authenticatePromiseIfNeeded(req, res)- const user: UserModel = res.locals.oauth ? res.locals.oauth.token.User : null-+ const user = res.locals.oauth ? res.locals.oauth.token.User : nullif (!user ||(videoPlaylist.OwnerAccount.userId !== user.id && !user.hasRight(UserRight.UPDATE_ANY_VIDEO_PLAYLIST))@@ -177,8 +176,8 @@ const videoPlaylistsAddVideoValidator = [if (!await doesVideoPlaylistExist(req.params.playlistId, res, 'all')) returnif (!await doesVideoExist(req.body.videoId, res, 'only-video')) return- const videoPlaylist: VideoPlaylistModel = res.locals.videoPlaylist- const video: VideoModel = res.locals.video+ const videoPlaylist = res.locals.videoPlaylist+ const video = res.locals.videoconst videoPlaylistElement = await VideoPlaylistElementModel.loadByPlaylistAndVideo(videoPlaylist.id, video.id)if (videoPlaylistElement) {@@ -217,8 +216,8 @@ const videoPlaylistsUpdateOrRemoveVideoValidator = [if (!await doesVideoPlaylistExist(req.params.playlistId, res, 'all')) returnif (!await doesVideoExist(req.params.videoId, res, 'id')) return- const videoPlaylist: VideoPlaylistModel = res.locals.videoPlaylist- const video: VideoModel = res.locals.video+ const videoPlaylist = res.locals.videoPlaylist+ const video = res.locals.videoconst videoPlaylistElement = await VideoPlaylistElementModel.loadByPlaylistAndVideo(videoPlaylist.id, video.id)if (!videoPlaylistElement) {@@ -284,7 +283,7 @@ const videoPlaylistsReorderVideosValidator = [if (!await doesVideoPlaylistExist(req.params.playlistId, res, 'all')) return- const videoPlaylist: VideoPlaylistModel = res.locals.videoPlaylist+ const videoPlaylist = res.locals.videoPlaylistif (!checkUserCanManageVideoPlaylist(res.locals.oauth.token.User, videoPlaylist, UserRight.UPDATE_ANY_VIDEO_PLAYLIST, res)) returnconst nextPosition = await VideoPlaylistElementModel.getNextPositionOf(videoPlaylist.id)diff --git a/server/middlewares/validators/videos/video-shares.ts b/server/middlewares/validators/videos/video-shares.tsindex f4514f85cb..d5cbdb03ef 100644--- a/server/middlewares/validators/videos/video-shares.ts+++ b/server/middlewares/validators/videos/video-shares.ts@@ -6,7 +6,6 @@ import { doesVideoExist } from '../../../helpers/custom-validators/videos'import { logger } from '../../../helpers/logger'import { VideoShareModel } from '../../../models/video/video-share'import { areValidationErrors } from '../utils'-import { VideoModel } from '../../../models/video/video'const videosShareValidator = [param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),@@ -18,7 +17,7 @@ const videosShareValidator = [if (areValidationErrors(req, res)) returnif (!await doesVideoExist(req.params.id, res)) return- const video: VideoModel = res.locals.video+ const video = res.locals.videoconst share = await VideoShareModel.load(req.params.actorId, video.id)if (!share) {diff --git a/server/middlewares/validators/videos/video-watch.ts b/server/middlewares/validators/videos/video-watch.tsindex a3b70c0cc1..a3a800d14f 100644--- a/server/middlewares/validators/videos/video-watch.ts+++ b/server/middlewares/validators/videos/video-watch.ts@@ -4,7 +4,6 @@ import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc'import { doesVideoExist } from '../../../helpers/custom-validators/videos'import { areValidationErrors } from '../utils'import { logger } from '../../../helpers/logger'-import { UserModel } from '../../../models/account/user'const videoWatchingValidator = [param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),@@ -18,7 +17,7 @@ const videoWatchingValidator = [if (areValidationErrors(req, res)) returnif (!await doesVideoExist(req.params.videoId, res, 'id')) return- const user = res.locals.oauth.token.User as UserModel+ const user = res.locals.oauth.token.Userif (user.videosHistoryEnabled === false) {logger.warn('Cannot set videos to watch by user %d: videos history is disabled.', user.id)return res.status(409).end()diff --git a/server/middlewares/validators/videos/videos.ts b/server/middlewares/validators/videos/videos.tsindex 92218d4b12..b70abf4294 100644--- a/server/middlewares/validators/videos/videos.ts+++ b/server/middlewares/validators/videos/videos.ts@@ -130,7 +130,7 @@ const videosUpdateValidator = getCommonVideoEditAttributes().concat([])async function checkVideoFollowConstraints (req: express.Request, res: express.Response, next: express.NextFunction) {- const video: VideoModel = res.locals.video+ const video = res.locals.video// Anybody can watch local videosif (video.isOwned() === true) return next()@@ -164,13 +164,13 @@ const videosCustomGetValidator = (fetchType: VideoFetchType) => {if (areValidationErrors(req, res)) returnif (!await doesVideoExist(req.params.id, res, fetchType)) return- const video: VideoModel = res.locals.video+ const video = res.locals.video// Video private or blacklistedif (video.privacy === VideoPrivacy.PRIVATE || video.VideoBlacklist) {await authenticatePromiseIfNeeded(req, res)- const user: UserModel = res.locals.oauth ? res.locals.oauth.token.User : null+ const user = res.locals.oauth ? res.locals.oauth.token.User : null// Only the owner or a user that have blacklist rights can see the videoif (@@ -256,7 +256,7 @@ const videosTerminateChangeOwnershipValidator = [return next()},async (req: express.Request, res: express.Response, next: express.NextFunction) => {- const videoChangeOwnership = res.locals.videoChangeOwnership as VideoChangeOwnershipModel+ const videoChangeOwnership = res.locals.videoChangeOwnershipif (videoChangeOwnership.status === VideoChangeOwnershipStatus.WAITING) {return next()@@ -275,7 +275,7 @@ const videosAcceptChangeOwnershipValidator = [if (!await doesVideoChannelOfAccountExist(body.channelId, res.locals.oauth.token.User, res)) returnconst user = res.locals.oauth.token.User- const videoChangeOwnership = res.locals.videoChangeOwnership as VideoChangeOwnershipModel+ const videoChangeOwnership = res.locals.videoChangeOwnershipconst isAble = await user.isAbleToUploadVideo(videoChangeOwnership.Video.getOriginalFile())if (isAble === false) {res.status(403)@@ -395,7 +395,7 @@ const commonVideosFiltersValidator = [if (areValidationErrors(req, res)) return- const user: UserModel = res.locals.oauth ? res.locals.oauth.token.User : undefined+ const user = res.locals.oauth ? res.locals.oauth.token.User : undefinedif (req.query.filter === 'all-local' && (!user || user.hasRight(UserRight.SEE_ALL_VIDEOS) === false)) {res.status(401).json({ error: 'You are not allowed to see all local videos.' })diff --git a/server/typings/express.ts b/server/typings/express.tsnew file mode 100644index 0000000000..324d78662c--- /dev/null+++ b/server/typings/express.ts@@ -0,0 +1,82 @@+import { VideoChannelModel } from '../models/video/video-channel'+import { VideoPlaylistModel } from '../models/video/video-playlist'+import { VideoPlaylistElementModel } from '../models/video/video-playlist-element'+import { UserModel } from '../models/account/user'+import { VideoModel } from '../models/video/video'+import { AccountModel } from '../models/account/account'+import { VideoChangeOwnershipModel } from '../models/video/video-change-ownership'+import { ActorModel } from '../models/activitypub/actor'+import { VideoCommentModel } from '../models/video/video-comment'+import { VideoShareModel } from '../models/video/video-share'+import { AccountVideoRateModel } from '../models/account/account-video-rate'+import { ActorFollowModel } from '../models/activitypub/actor-follow'+import { ServerModel } from '../models/server/server'+import { VideoFileModel } from '../models/video/video-file'+import { VideoRedundancyModel } from '../models/redundancy/video-redundancy'+import { ServerBlocklistModel } from '../models/server/server-blocklist'+import { AccountBlocklistModel } from '../models/account/account-blocklist'+import { VideoImportModel } from '../models/video/video-import'+import { VideoAbuseModel } from '../models/video/video-abuse'+import { VideoBlacklistModel } from '../models/video/video-blacklist'+import { VideoCaptionModel } from '../models/video/video-caption'+import { VideoStreamingPlaylistModel } from '../models/video/video-streaming-playlist'++declare module 'express' {++ interface Response {+ locals: {+ video?: VideoModel+ videoShare?: VideoShareModel+ videoFile?: VideoFileModel++ videoImport?: VideoImportModel++ videoBlacklist?: VideoBlacklistModel++ videoCaption?: VideoCaptionModel++ videoAbuse?: VideoAbuseModel++ videoStreamingPlaylist?: VideoStreamingPlaylistModel++ videoChannel?: VideoChannelModel++ videoPlaylist?: VideoPlaylistModel+ videoPlaylistElement?: VideoPlaylistElementModel++ accountVideoRate?: AccountVideoRateModel++ videoComment?: VideoCommentModel+ videoCommentThread?: VideoCommentModel++ follow?: ActorFollowModel+ subscription?: ActorFollowModel++ nextOwner?: AccountModel+ videoChangeOwnership?: VideoChangeOwnershipModel+ account?: AccountModel+ actor?: ActorModel+ user?: UserModel++ server?: ServerModel++ videoRedundancy?: VideoRedundancyModel++ accountBlock?: AccountBlocklistModel+ serverBlock?: ServerBlocklistModel++ oauth?: {+ token: {+ User: UserModel+ user: UserModel+ }+ }++ signature?: {+ actor: ActorModel+ }++ authenticated?: boolean+ }+ }+}diff --git a/tsconfig.json b/tsconfig.jsonindex c84b179cfe..5ad4b3e10c 100644--- a/tsconfig.json+++ b/tsconfig.json@@ -14,11 +14,7 @@"es2016","es2017"],- "types": [- "node",- "chai-xml",- "chai-json-schema"- ]+ "typeRoots": [ "node_modules/@types", "server/typings" ]},"exclude": ["client/node_modules",