From 69818c9394366b954b6ba3bd697bd9d2b09f2a16 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Sat, 10 Jun 2017 22:15:25 +0200 Subject: Type functions --- server/controllers/api/videos/abuse.ts | 9 +++++---- server/controllers/api/videos/blacklist.ts | 2 +- server/controllers/api/videos/index.ts | 29 +++++++++++++++-------------- server/controllers/api/videos/rate.ts | 7 ++++--- 4 files changed, 25 insertions(+), 22 deletions(-) (limited to 'server/controllers/api/videos') diff --git a/server/controllers/api/videos/abuse.ts b/server/controllers/api/videos/abuse.ts index 68db025b7..78e8e8b3d 100644 --- a/server/controllers/api/videos/abuse.ts +++ b/server/controllers/api/videos/abuse.ts @@ -1,4 +1,5 @@ import * as express from 'express' +import * as Sequelize from 'sequelize' import { waterfall } from 'async' import { database as db } from '../../../initializers/database' @@ -46,7 +47,7 @@ export { // --------------------------------------------------------------------------- -function listVideoAbuses (req, res, next) { +function listVideoAbuses (req: express.Request, res: express.Response, next: express.NextFunction) { db.VideoAbuse.listForApi(req.query.start, req.query.count, req.query.sort, function (err, abusesList, abusesTotal) { if (err) return next(err) @@ -54,7 +55,7 @@ function listVideoAbuses (req, res, next) { }) } -function reportVideoAbuseRetryWrapper (req, res, next) { +function reportVideoAbuseRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) { const options = { arguments: [ req, res ], errorMessage: 'Cannot report abuse to the video with many retries.' @@ -67,7 +68,7 @@ function reportVideoAbuseRetryWrapper (req, res, next) { }) } -function reportVideoAbuse (req, res, finalCallback) { +function reportVideoAbuse (req: express.Request, res: express.Response, finalCallback: (err: Error) => void) { const videoInstance = res.locals.video const reporterUsername = res.locals.oauth.token.User.username @@ -105,7 +106,7 @@ function reportVideoAbuse (req, res, finalCallback) { commitTransaction - ], function andFinally (err, t) { + ], function andFinally (err: Error, t: Sequelize.Transaction) { if (err) { logger.debug('Cannot update the video.', { error: err }) return rollbackTransaction(err, t, finalCallback) diff --git a/server/controllers/api/videos/blacklist.ts b/server/controllers/api/videos/blacklist.ts index 58960798b..4b42fc2d7 100644 --- a/server/controllers/api/videos/blacklist.ts +++ b/server/controllers/api/videos/blacklist.ts @@ -25,7 +25,7 @@ export { // --------------------------------------------------------------------------- -function addVideoToBlacklist (req, res, next) { +function addVideoToBlacklist (req: express.Request, res: express.Response, next: express.NextFunction) { const videoInstance = res.locals.video const toCreate = { diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index b82b0936f..bfa018031 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts @@ -1,4 +1,5 @@ import * as express from 'express' +import * as Sequelize from 'sequelize' import * as fs from 'fs' import * as multer from 'multer' import * as path from 'path' @@ -124,21 +125,21 @@ export { // --------------------------------------------------------------------------- -function listVideoCategories (req, res, next) { +function listVideoCategories (req: express.Request, res: express.Response, next: express.NextFunction) { res.json(VIDEO_CATEGORIES) } -function listVideoLicences (req, res, next) { +function listVideoLicences (req: express.Request, res: express.Response, next: express.NextFunction) { res.json(VIDEO_LICENCES) } -function listVideoLanguages (req, res, next) { +function listVideoLanguages (req: express.Request, res: express.Response, next: express.NextFunction) { res.json(VIDEO_LANGUAGES) } // Wrapper to video add that retry the function if there is a database error // We need this because we run the transaction in SERIALIZABLE isolation that can fail -function addVideoRetryWrapper (req, res, next) { +function addVideoRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) { const options = { arguments: [ req, res, req.files.videofile[0] ], errorMessage: 'Cannot insert the video with many retries.' @@ -152,7 +153,7 @@ function addVideoRetryWrapper (req, res, next) { }) } -function addVideo (req, res, videoFile, finalCallback) { +function addVideo (req: express.Request, res: express.Response, videoFile: Express.Multer.File, finalCallback: (err: Error) => void) { const videoInfos = req.body waterfall([ @@ -190,7 +191,7 @@ function addVideo (req, res, videoFile, finalCallback) { language: videoInfos.language, nsfw: videoInfos.nsfw, description: videoInfos.description, - duration: videoFile.duration, + duration: videoFile['duration'], // duration was added by a previous middleware authorId: author.id } @@ -254,7 +255,7 @@ function addVideo (req, res, videoFile, finalCallback) { commitTransaction - ], function andFinally (err, t) { + ], function andFinally (err: Error, t: Sequelize.Transaction) { if (err) { // This is just a debug because we will retry the insert logger.debug('Cannot insert the video.', { error: err }) @@ -266,7 +267,7 @@ function addVideo (req, res, videoFile, finalCallback) { }) } -function updateVideoRetryWrapper (req, res, next) { +function updateVideoRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) { const options = { arguments: [ req, res ], errorMessage: 'Cannot update the video with many retries.' @@ -280,7 +281,7 @@ function updateVideoRetryWrapper (req, res, next) { }) } -function updateVideo (req, res, finalCallback) { +function updateVideo (req: express.Request, res: express.Response, finalCallback: (err: Error) => void) { const videoInstance = res.locals.video const videoFieldsSave = videoInstance.toJSON() const videoInfosToUpdate = req.body @@ -341,7 +342,7 @@ function updateVideo (req, res, finalCallback) { commitTransaction - ], function andFinally (err, t) { + ], function andFinally (err: Error, t: Sequelize.Transaction) { if (err) { logger.debug('Cannot update the video.', { error: err }) @@ -361,7 +362,7 @@ function updateVideo (req, res, finalCallback) { }) } -function getVideo (req, res, next) { +function getVideo (req: express.Request, res: express.Response, next: express.NextFunction) { const videoInstance = res.locals.video if (videoInstance.isOwned()) { @@ -393,7 +394,7 @@ function getVideo (req, res, next) { res.json(videoInstance.toFormatedJSON()) } -function listVideos (req, res, next) { +function listVideos (req: express.Request, res: express.Response, next: express.NextFunction) { db.Video.listForApi(req.query.start, req.query.count, req.query.sort, function (err, videosList, videosTotal) { if (err) return next(err) @@ -401,7 +402,7 @@ function listVideos (req, res, next) { }) } -function removeVideo (req, res, next) { +function removeVideo (req: express.Request, res: express.Response, next: express.NextFunction) { const videoInstance = res.locals.video videoInstance.destroy().asCallback(function (err) { @@ -414,7 +415,7 @@ function removeVideo (req, res, next) { }) } -function searchVideos (req, res, next) { +function searchVideos (req: express.Request, res: express.Response, next: express.NextFunction) { db.Video.searchAndPopulateAuthorAndPodAndTags( req.params.value, req.query.field, req.query.start, req.query.count, req.query.sort, function (err, videosList, videosTotal) { diff --git a/server/controllers/api/videos/rate.ts b/server/controllers/api/videos/rate.ts index 1bc575675..afdd099f8 100644 --- a/server/controllers/api/videos/rate.ts +++ b/server/controllers/api/videos/rate.ts @@ -1,4 +1,5 @@ import * as express from 'express' +import * as Sequelize from 'sequelize' import { waterfall } from 'async' import { database as db } from '../../../initializers/database' @@ -39,7 +40,7 @@ export { // --------------------------------------------------------------------------- -function rateVideoRetryWrapper (req, res, next) { +function rateVideoRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) { const options = { arguments: [ req, res ], errorMessage: 'Cannot update the user video rate.' @@ -52,7 +53,7 @@ function rateVideoRetryWrapper (req, res, next) { }) } -function rateVideo (req, res, finalCallback) { +function rateVideo (req: express.Request, res: express.Response, finalCallback: (err: Error) => void) { const rateType = req.body.rating const videoInstance = res.locals.video const userInstance = res.locals.oauth.token.User @@ -168,7 +169,7 @@ function rateVideo (req, res, finalCallback) { commitTransaction - ], function (err, t) { + ], function (err: Error, t: Sequelize.Transaction) { if (err) { // This is just a debug because we will retry the insert logger.debug('Cannot add the user video rate.', { error: err }) -- cgit v1.2.3