From dae86118ed5d4026d04acb9d0e36829b9ad8eb4e Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 19 Mar 2019 10:35:15 +0100 Subject: Cleanup express locals typings --- server/controllers/activitypub/client.ts | 36 +++++++++++----------- server/controllers/activitypub/inbox.ts | 9 +----- server/controllers/activitypub/outbox.ts | 2 +- server/controllers/api/accounts.ts | 7 ++--- server/controllers/api/index.ts | 2 +- server/controllers/api/server/follows.ts | 10 +++--- server/controllers/api/server/redundancy.ts | 5 ++- server/controllers/api/server/server-blocklist.ts | 10 +++--- server/controllers/api/users/index.ts | 30 +++++++++--------- server/controllers/api/users/me.ts | 20 ++++++------ server/controllers/api/users/my-blocklist.ts | 17 +++++----- server/controllers/api/users/my-history.ts | 4 +-- server/controllers/api/users/my-notifications.ts | 11 +++---- server/controllers/api/users/my-subscriptions.ts | 15 +++++---- server/controllers/api/users/my-video-playlists.ts | 3 +- server/controllers/api/video-channel.ts | 19 ++++++------ server/controllers/api/video-playlist.ts | 30 +++++++++--------- server/controllers/api/videos/abuse.ts | 10 +++--- server/controllers/api/videos/blacklist.ts | 7 ++--- server/controllers/api/videos/captions.ts | 7 ++--- server/controllers/api/videos/comment.ts | 23 +++++++------- server/controllers/api/videos/import.ts | 4 +-- server/controllers/api/videos/index.ts | 6 ++-- server/controllers/api/videos/ownership.ts | 16 +++++----- server/controllers/api/videos/rate.ts | 5 ++- server/controllers/api/videos/watching.ts | 2 +- server/controllers/feeds.ts | 12 +++----- server/controllers/services.ts | 4 +-- server/controllers/static.ts | 2 +- server/controllers/webfinger.ts | 5 ++- 30 files changed, 152 insertions(+), 181 deletions(-) (limited to 'server/controllers') diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts index cc2671fc1..e06aa35f4 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.account return activityPubResponse(activityPubContextify(account.toActivityPubObject()), res) } async function accountFollowersController (req: express.Request, res: express.Response) { - const account: AccountModel = res.locals.account + const account = res.locals.account const 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.account const 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.account const activityPubResult = await actorPlaylists(req, account) return activityPubResponse(activityPubContextify(activityPubResult), res) @@ -197,7 +197,7 @@ async function accountPlaylistsController (req: express.Request, res: express.Re function getAccountVideoRate (rateType: VideoRateType) { return (req: express.Request, res: express.Response) => { - const accountVideoRate: AccountVideoRateModel = res.locals.accountVideoRate + const accountVideoRate = res.locals.accountVideoRate const byActor = accountVideoRate.Account.Actor const 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.videoShare if (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.video const 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.video const 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.video const 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.video const 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.videoChannel return activityPubResponse(activityPubContextify(videoChannel.toActivityPubObject()), res) } async function videoChannelFollowersController (req: express.Request, res: express.Response) { - const videoChannel: VideoChannelModel = res.locals.videoChannel + const videoChannel = res.locals.videoChannel const 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.videoChannel const 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.videoComment if (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.videoRedundancy if (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 attributes playlist.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.videoPlaylistElement const json = videoPlaylistElement.toActivityPubObject() return activityPubResponse(activityPubContextify(json), res) diff --git a/server/controllers/activitypub/inbox.ts b/server/controllers/activitypub/inbox.ts index f0e65015b..38d5c51df 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.videoChannel logger.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.ts index e060affb2..38b6ec976 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.videoChannel const actor = accountOrVideoChannel.Actor const actorOutboxUrl = actor.url + '/outbox' diff --git a/server/controllers/api/accounts.ts b/server/controllers/api/accounts.ts index e24545de8..adbf69781 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.account if (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 playlists let 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.account const followerActorId = isUserAbleToSearchRemoteURI(res) ? null : undefined const resultList = await VideoModel.listForApi({ diff --git a/server/controllers/api/index.ts b/server/controllers/api/index.ts index ed4b33dea..60a84036e 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.ts index 9fa6c34ba..99d211bfc 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, next return 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.follow await 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.ts index 4140c4991..f8109070d 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.server server.redundancyAllowed = req.body.redundancyAllowed diff --git a/server/controllers/api/server/server-blocklist.ts b/server/controllers/api/server/server-blocklist.ts index 3cb3a96e2..d165db191 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.account await 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.accountBlock await 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.server await 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.serverBlock await removeServerFromBlocklist(serverBlock) diff --git a/server/controllers/api/users/index.ts b/server/controllers/api/users/index.ts index f7edbddf3..2117bdfeb 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.user await 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.user const reason = req.body.reason await 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.user await 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.user const 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.user const 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.Response return 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.user user.password = req.body.password await 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.user await 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.user user.emailVerified = true await user.save() @@ -332,7 +332,7 @@ async function verifyUserEmail (req: express.Request, res: express.Response, nex return 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.ts index d5e154869..3533499be 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.User const 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.User const 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.user const 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.user const 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.Respons return 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.id const 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.User await 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.user const 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.user const 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.ts index 9575eab46..481e75139 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.User const 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.account await 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.accountBlock await 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.User const 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.server await 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.serverBlock await removeServerFromBlocklist(serverBlock) diff --git a/server/controllers/api/users/my-history.ts b/server/controllers/api/users/my-history.ts index 6cd782c47..b30d3aec2 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.User const 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.User const beforeDate = req.body.beforeDate || null await sequelizeTypescript.transaction(t => { diff --git a/server/controllers/api/users/my-notifications.ts b/server/controllers/api/users/my-notifications.ts index 76cf97587..bbafda5a6 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 UserNotificationSetting const 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.User const 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.User await 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.User await UserNotificationModel.markAllAsRead(user.id) diff --git a/server/controllers/api/users/my-subscriptions.ts b/server/controllers/api/users/my-subscriptions.ts index accca6d52..a173adfd0 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.User const 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.User const [ 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.subscription return 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.subscription await 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.User const actorId = user.Account.Actor.id const 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.Response return 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.User const 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.ts index 42da02bff..15e92f4f3 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.User const results = await VideoPlaylistModel.listPlaylistIdsOf(user.Account.id, videoIds) diff --git a/server/controllers/api/video-channel.ts b/server/controllers/api/video-channel.ts index c13aed4dc..5881cab41 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.videoChannel const 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.body const 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.videoChannel const 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.videoChannel await 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.Res return 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.videoChannel const followerActorId = isUserAbleToSearchRemoteURI(res) ? null : undefined const resultList = await VideoModel.listForApi({ diff --git a/server/controllers/api/video-playlist.ts b/server/controllers/api/video-playlist.ts index c7dfc583b..5b1601c4e 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/vide import { 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.videoPlaylist return 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.User const 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 object if (videoPlaylistInfo.videoChannelId) { - const videoChannel = res.locals.videoChannel as VideoChannelModel + const videoChannel = res.locals.videoChannel videoPlaylist.videoChannelId = videoChannel.id videoPlaylist.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.videoPlaylist const videoPlaylistFieldsSave = videoPlaylistInstance.toJSON() const videoPlaylistInfoToUpdate = req.body as VideoPlaylistUpdate const 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.videoChannel videoPlaylistInstance.videoChannelId = videoChannel.id videoPlaylistInstance.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.videoPlaylist await 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.video const 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.videoPlaylistElement const 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.videoPlaylist const positionToDelete = videoPlaylistElement.position await 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.videoPlaylist const body: VideoPlaylistReorder = req.body const 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.videoPlaylist const followerActorId = isUserAbleToSearchRemoteURI(res) ? null : undefined const resultList = await VideoModel.listForApi({ diff --git a/server/controllers/api/videos/abuse.ts b/server/controllers/api/videos/abuse.ts index 32f9c4793..ca70230a2 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.videoAbuse if (req.body.moderationComment !== undefined) videoAbuse.moderationComment = req.body.moderationComment if (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.videoAbuse await 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.video const body: VideoAbuseCreate = req.body const 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.ts index b01296200..d0728eb59 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.videoBlacklist if (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.video await sequelizeTypescript.transaction(async t => { const unfederated = videoBlacklist.unfederated diff --git a/server/controllers/api/videos/captions.ts b/server/controllers/api/videos/captions.ts index 9b3661368..2694577d8 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.video const 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.videoCaption await sequelizeTypescript.transaction(async t => { await videoCaption.destroy({ transaction: t }) diff --git a/server/controllers/api/videos/comment.ts b/server/controllers/api/videos/comment.ts index 70c1148ba..176ee8bd4 100644 --- a/server/controllers/api/videos/comment.ts +++ b/server/controllers/api/videos/comment.ts @@ -8,7 +8,8 @@ import { buildFormattedCommentTree, createVideoComment } from '../../../lib/vide import { 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 : undefined let resultList: ResultList @@ -88,9 +87,9 @@ async function listVideoThreads (req: express.Request, res: express.Response, ne return 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 : undefined let resultList: ResultList @@ -110,7 +109,7 @@ async function addVideoCommentThread (req: express.Request, res: express.Respons const videoCommentInfo: VideoCommentCreate = req.body const 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.Response const videoCommentInfo: VideoCommentCreate = req.body const 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.videoComment await sequelizeTypescript.transaction(async t => { await videoCommentInstance.destroy({ transaction: t }) diff --git a/server/controllers/api/videos/import.ts b/server/controllers/api/videos/import.ts index 626c81eca..cbd2e8514 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, to 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 video const 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 video const payload = { diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index 27f67895e..db4f4c96f 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.video const 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 attributes const 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.video await sequelizeTypescript.transaction(async t => { await videoInstance.destroy({ transaction: t }) diff --git a/server/controllers/api/videos/ownership.ts b/server/controllers/api/videos/ownership.ts index 5ea7d7c6a..fc73856c9 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.nextOwner await 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.id const 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.videoChangeOwnership const targetVideo = videoChangeOwnership.Video - const channel = res.locals.videoChannel as VideoChannelModel + const channel = res.locals.videoChannel const 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.videoChangeOwnership videoChangeOwnership.set('status', VideoChangeOwnershipStatus.REFUSED) await videoChangeOwnership.save({ transaction: t }) diff --git a/server/controllers/api/videos/rate.ts b/server/controllers/api/videos/rate.ts index 53952a0a2..914c596c3 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.body const 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.Account await sequelizeTypescript.transaction(async t => { const sequelizeOptions = { transaction: t } diff --git a/server/controllers/api/videos/watching.ts b/server/controllers/api/videos/watching.ts index e8876b47a..6bc60e045 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.User const body: UserWatchingVideo = req.body const { id: videoId } = res.locals.video as { id: number } diff --git a/server/controllers/feeds.ts b/server/controllers/feeds.ts index 960085af1..cd46b6e0f 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.video const videoId: number = video ? video.id : undefined const comments = await VideoCommentModel.listForFeed(start, FEEDS.COUNT, videoId) @@ -77,11 +75,11 @@ async function generateVideoCommentsFeed (req: express.Request, res: express.Res return 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.videoChannel const nsfw = buildNSFWFilter(res, req.query.nsfw) let name: string diff --git a/server/controllers/services.ts b/server/controllers/services.ts index 680c3c37f..cf7a513af 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.video const webserverUrl = CONFIG.WEBSERVER.URL const maxHeight = parseInt(req.query.maxheight, 10) const maxWidth = parseInt(req.query.maxwidth, 10) diff --git a/server/controllers/static.ts b/server/controllers/static.ts index 639445b74..7b14320e4 100644 --- a/server/controllers/static.ts +++ b/server/controllers/static.ts @@ -245,7 +245,7 @@ async function downloadVideoFile (req: express.Request, res: express.Response, n function getVideoAndFile (req: express.Request, res: express.Response) { const resolution = parseInt(req.params.resolution, 10) - const video: VideoModel = res.locals.video + const video = res.locals.video const videoFile = video.VideoFiles.find(f => f.resolution === resolution) diff --git a/server/controllers/webfinger.ts b/server/controllers/webfinger.ts index ed781c21b..f2ba3c826 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.actor const json = { subject: req.query.resource, -- cgit v1.2.3