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/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 +- 9 files changed, 36 insertions(+), 44 deletions(-) (limited to 'server/controllers/api/videos') 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 } -- cgit v1.2.3