aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api/videos')
-rw-r--r--server/controllers/api/videos/abuse.ts4
-rw-r--r--server/controllers/api/videos/index.ts5
-rw-r--r--server/controllers/api/videos/rate.ts23
3 files changed, 24 insertions, 8 deletions
diff --git a/server/controllers/api/videos/abuse.ts b/server/controllers/api/videos/abuse.ts
index 3b1b7f58e..7d2e3bcfb 100644
--- a/server/controllers/api/videos/abuse.ts
+++ b/server/controllers/api/videos/abuse.ts
@@ -17,6 +17,7 @@ import {
17 setPagination 17 setPagination
18} from '../../../middlewares' 18} from '../../../middlewares'
19import { VideoInstance } from '../../../models' 19import { VideoInstance } from '../../../models'
20import { VideoAbuseCreate } from '../../../../shared'
20 21
21const abuseVideoRouter = express.Router() 22const abuseVideoRouter = express.Router()
22 23
@@ -63,10 +64,11 @@ function reportVideoAbuseRetryWrapper (req: express.Request, res: express.Respon
63function reportVideoAbuse (req: express.Request, res: express.Response) { 64function reportVideoAbuse (req: express.Request, res: express.Response) {
64 const videoInstance = res.locals.video 65 const videoInstance = res.locals.video
65 const reporterUsername = res.locals.oauth.token.User.username 66 const reporterUsername = res.locals.oauth.token.User.username
67 const body: VideoAbuseCreate = req.body
66 68
67 const abuse = { 69 const abuse = {
68 reporterUsername, 70 reporterUsername,
69 reason: req.body.reason, 71 reason: body.reason,
70 videoId: videoInstance.id, 72 videoId: videoInstance.id,
71 reporterPodId: null // This is our pod that reported this abuse 73 reporterPodId: null // This is our pod that reported this abuse
72 } 74 }
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts
index 3532c753e..4ae7ea2ed 100644
--- a/server/controllers/api/videos/index.ts
+++ b/server/controllers/api/videos/index.ts
@@ -39,6 +39,7 @@ import {
39 renamePromise 39 renamePromise
40} from '../../../helpers' 40} from '../../../helpers'
41import { TagInstance } from '../../../models' 41import { TagInstance } from '../../../models'
42import { VideoCreate, VideoUpdate } from '../../../../shared'
42 43
43import { abuseVideoRouter } from './abuse' 44import { abuseVideoRouter } from './abuse'
44import { blacklistRouter } from './blacklist' 45import { blacklistRouter } from './blacklist'
@@ -155,7 +156,7 @@ function addVideoRetryWrapper (req: express.Request, res: express.Response, next
155} 156}
156 157
157function addVideo (req: express.Request, res: express.Response, videoFile: Express.Multer.File) { 158function addVideo (req: express.Request, res: express.Response, videoFile: Express.Multer.File) {
158 const videoInfos = req.body 159 const videoInfos: VideoCreate = req.body
159 160
160 return db.sequelize.transaction(t => { 161 return db.sequelize.transaction(t => {
161 const user = res.locals.oauth.token.User 162 const user = res.locals.oauth.token.User
@@ -257,7 +258,7 @@ function updateVideoRetryWrapper (req: express.Request, res: express.Response, n
257function updateVideo (req: express.Request, res: express.Response) { 258function updateVideo (req: express.Request, res: express.Response) {
258 const videoInstance = res.locals.video 259 const videoInstance = res.locals.video
259 const videoFieldsSave = videoInstance.toJSON() 260 const videoFieldsSave = videoInstance.toJSON()
260 const videoInfosToUpdate = req.body 261 const videoInfosToUpdate: VideoUpdate = req.body
261 262
262 return db.sequelize.transaction(t => { 263 return db.sequelize.transaction(t => {
263 let tagsPromise: Promise<TagInstance[]> 264 let tagsPromise: Promise<TagInstance[]>
diff --git a/server/controllers/api/videos/rate.ts b/server/controllers/api/videos/rate.ts
index dfb5a450f..8456cbaf2 100644
--- a/server/controllers/api/videos/rate.ts
+++ b/server/controllers/api/videos/rate.ts
@@ -1,4 +1,5 @@
1import * as express from 'express' 1import * as express from 'express'
2import * as Promise from 'bluebird'
2 3
3import { database as db } from '../../../initializers/database' 4import { database as db } from '../../../initializers/database'
4import { 5import {
@@ -18,6 +19,7 @@ import {
18 authenticate, 19 authenticate,
19 videoRateValidator 20 videoRateValidator
20} from '../../../middlewares' 21} from '../../../middlewares'
22import { UserVideoRateUpdate, VideoRateType } from '../../../../shared'
21 23
22const rateVideoRouter = express.Router() 24const rateVideoRouter = express.Router()
23 25
@@ -47,7 +49,8 @@ function rateVideoRetryWrapper (req: express.Request, res: express.Response, nex
47} 49}
48 50
49function rateVideo (req: express.Request, res: express.Response) { 51function rateVideo (req: express.Request, res: express.Response) {
50 const rateType = req.body.rating 52 const body: UserVideoRateUpdate = req.body
53 const rateType = body.rating
51 const videoInstance = res.locals.video 54 const videoInstance = res.locals.video
52 const userInstance = res.locals.oauth.token.User 55 const userInstance = res.locals.oauth.token.User
53 56
@@ -62,24 +65,34 @@ function rateVideo (req: express.Request, res: express.Response) {
62 if (rateType === VIDEO_RATE_TYPES.LIKE) likesToIncrement++ 65 if (rateType === VIDEO_RATE_TYPES.LIKE) likesToIncrement++
63 else if (rateType === VIDEO_RATE_TYPES.DISLIKE) dislikesToIncrement++ 66 else if (rateType === VIDEO_RATE_TYPES.DISLIKE) dislikesToIncrement++
64 67
68 let promise: Promise<any>
69
65 // There was a previous rate, update it 70 // There was a previous rate, update it
66 if (previousRate) { 71 if (previousRate) {
67 // We will remove the previous rate, so we will need to remove it from the video attribute 72 // We will remove the previous rate, so we will need to remove it from the video attribute
68 if (previousRate.type === VIDEO_RATE_TYPES.LIKE) likesToIncrement-- 73 if (previousRate.type === VIDEO_RATE_TYPES.LIKE) likesToIncrement--
69 else if (previousRate.type === VIDEO_RATE_TYPES.DISLIKE) dislikesToIncrement-- 74 else if (previousRate.type === VIDEO_RATE_TYPES.DISLIKE) dislikesToIncrement--
70 75
71 previousRate.type = rateType 76 if (rateType === 'none') { // Destroy previous rate
77 promise = previousRate.destroy()
78 } else { // Update previous rate
79 previousRate.type = rateType as VideoRateType
72 80
73 return previousRate.save(options).then(() => ({ t, likesToIncrement, dislikesToIncrement })) 81 promise = previousRate.save()
74 } else { // There was not a previous rate, insert a new one 82 }
83 } else if (rateType !== 'none') { // There was not a previous rate, insert a new one if there is a rate
75 const query = { 84 const query = {
76 userId: userInstance.id, 85 userId: userInstance.id,
77 videoId: videoInstance.id, 86 videoId: videoInstance.id,
78 type: rateType 87 type: rateType
79 } 88 }
80 89
81 return db.UserVideoRate.create(query, options).then(() => ({ likesToIncrement, dislikesToIncrement })) 90 promise = db.UserVideoRate.create(query, options)
91 } else {
92 promise = Promise.resolve()
82 } 93 }
94
95 return promise.then(() => ({ likesToIncrement, dislikesToIncrement }))
83 }) 96 })
84 .then(({ likesToIncrement, dislikesToIncrement }) => { 97 .then(({ likesToIncrement, dislikesToIncrement }) => {
85 const options = { transaction: t } 98 const options = { transaction: t }