aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos/abuse.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-09-20 10:13:13 +0200
committerChocobozzz <me@florianbigard.com>2018-09-20 11:45:59 +0200
commit91411dba928678c15a5e99d9795ae061909e397d (patch)
tree7ba6e340cc9eb6f993051fcac74eefd652cb0ffd /server/controllers/api/videos/abuse.ts
parentfcc7c060374c3a547257d96af847352c14d6144b (diff)
downloadPeerTube-91411dba928678c15a5e99d9795ae061909e397d.tar.gz
PeerTube-91411dba928678c15a5e99d9795ae061909e397d.tar.zst
PeerTube-91411dba928678c15a5e99d9795ae061909e397d.zip
Limit associations fetch when loading token
Diffstat (limited to 'server/controllers/api/videos/abuse.ts')
-rw-r--r--server/controllers/api/videos/abuse.ts23
1 files changed, 12 insertions, 11 deletions
diff --git a/server/controllers/api/videos/abuse.ts b/server/controllers/api/videos/abuse.ts
index 08e11b00b..d0c81804b 100644
--- a/server/controllers/api/videos/abuse.ts
+++ b/server/controllers/api/videos/abuse.ts
@@ -21,6 +21,7 @@ import { AccountModel } from '../../../models/account/account'
21import { VideoModel } from '../../../models/video/video' 21import { VideoModel } from '../../../models/video/video'
22import { VideoAbuseModel } from '../../../models/video/video-abuse' 22import { VideoAbuseModel } from '../../../models/video/video-abuse'
23import { auditLoggerFactory, VideoAbuseAuditView } from '../../../helpers/audit-logger' 23import { auditLoggerFactory, VideoAbuseAuditView } from '../../../helpers/audit-logger'
24import { UserModel } from '../../../models/account/user'
24 25
25const auditLogger = auditLoggerFactory('abuse') 26const auditLogger = auditLoggerFactory('abuse')
26const abuseVideoRouter = express.Router() 27const abuseVideoRouter = express.Router()
@@ -95,17 +96,18 @@ async function deleteVideoAbuse (req: express.Request, res: express.Response) {
95 96
96async function reportVideoAbuse (req: express.Request, res: express.Response) { 97async function reportVideoAbuse (req: express.Request, res: express.Response) {
97 const videoInstance = res.locals.video as VideoModel 98 const videoInstance = res.locals.video as VideoModel
98 const reporterAccount = res.locals.oauth.token.User.Account as AccountModel
99 const body: VideoAbuseCreate = req.body 99 const body: VideoAbuseCreate = req.body
100 100
101 const abuseToCreate = {
102 reporterAccountId: reporterAccount.id,
103 reason: body.reason,
104 videoId: videoInstance.id,
105 state: VideoAbuseState.PENDING
106 }
107
108 const videoAbuse: VideoAbuseModel = await sequelizeTypescript.transaction(async t => { 101 const videoAbuse: VideoAbuseModel = await sequelizeTypescript.transaction(async t => {
102 const reporterAccount = await AccountModel.load((res.locals.oauth.token.User as UserModel).Account.id, t)
103
104 const abuseToCreate = {
105 reporterAccountId: reporterAccount.id,
106 reason: body.reason,
107 videoId: videoInstance.id,
108 state: VideoAbuseState.PENDING
109 }
110
109 const videoAbuseInstance = await VideoAbuseModel.create(abuseToCreate, { transaction: t }) 111 const videoAbuseInstance = await VideoAbuseModel.create(abuseToCreate, { transaction: t })
110 videoAbuseInstance.Video = videoInstance 112 videoAbuseInstance.Video = videoInstance
111 videoAbuseInstance.Account = reporterAccount 113 videoAbuseInstance.Account = reporterAccount
@@ -121,7 +123,6 @@ async function reportVideoAbuse (req: express.Request, res: express.Response) {
121 }) 123 })
122 124
123 logger.info('Abuse report for video %s created.', videoInstance.name) 125 logger.info('Abuse report for video %s created.', videoInstance.name)
124 return res.json({ 126
125 videoAbuse: videoAbuse.toFormattedJSON() 127 return res.json({ videoAbuse: videoAbuse.toFormattedJSON() }).end()
126 }).end()
127} 128}