diff options
Diffstat (limited to 'server/controllers/api')
-rw-r--r-- | server/controllers/api/videos/abuse.ts | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/server/controllers/api/videos/abuse.ts b/server/controllers/api/videos/abuse.ts index bce50aefb..ec28fce67 100644 --- a/server/controllers/api/videos/abuse.ts +++ b/server/controllers/api/videos/abuse.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { UserRight, VideoAbuseCreate, VideoAbuseState } from '../../../../shared' | 2 | import { UserRight, VideoAbuseCreate, VideoAbuseState, VideoAbuse } from '../../../../shared' |
3 | import { logger } from '../../../helpers/logger' | 3 | import { logger } from '../../../helpers/logger' |
4 | import { getFormattedObjects } from '../../../helpers/utils' | 4 | import { getFormattedObjects } from '../../../helpers/utils' |
5 | import { sequelizeTypescript } from '../../../initializers/database' | 5 | import { sequelizeTypescript } from '../../../initializers/database' |
@@ -24,6 +24,7 @@ import { Notifier } from '../../../lib/notifier' | |||
24 | import { sendVideoAbuse } from '../../../lib/activitypub/send/send-flag' | 24 | import { sendVideoAbuse } from '../../../lib/activitypub/send/send-flag' |
25 | import { MVideoAbuseAccountVideo } from '../../../typings/models/video' | 25 | import { MVideoAbuseAccountVideo } from '../../../typings/models/video' |
26 | import { getServerActor } from '@server/models/application/application' | 26 | import { getServerActor } from '@server/models/application/application' |
27 | import { MAccountDefault } from '@server/typings/models' | ||
27 | 28 | ||
28 | const auditLogger = auditLoggerFactory('abuse') | 29 | const auditLogger = auditLoggerFactory('abuse') |
29 | const abuseVideoRouter = express.Router() | 30 | const abuseVideoRouter = express.Router() |
@@ -117,9 +118,11 @@ async function deleteVideoAbuse (req: express.Request, res: express.Response) { | |||
117 | async function reportVideoAbuse (req: express.Request, res: express.Response) { | 118 | async function reportVideoAbuse (req: express.Request, res: express.Response) { |
118 | const videoInstance = res.locals.videoAll | 119 | const videoInstance = res.locals.videoAll |
119 | const body: VideoAbuseCreate = req.body | 120 | const body: VideoAbuseCreate = req.body |
121 | let reporterAccount: MAccountDefault | ||
122 | let videoAbuseJSON: VideoAbuse | ||
120 | 123 | ||
121 | const videoAbuse = await sequelizeTypescript.transaction(async t => { | 124 | const videoAbuseInstance = await sequelizeTypescript.transaction(async t => { |
122 | const reporterAccount = await AccountModel.load(res.locals.oauth.token.User.Account.id, t) | 125 | reporterAccount = await AccountModel.load(res.locals.oauth.token.User.Account.id, t) |
123 | 126 | ||
124 | const abuseToCreate = { | 127 | const abuseToCreate = { |
125 | reporterAccountId: reporterAccount.id, | 128 | reporterAccountId: reporterAccount.id, |
@@ -137,14 +140,19 @@ async function reportVideoAbuse (req: express.Request, res: express.Response) { | |||
137 | await sendVideoAbuse(reporterAccount.Actor, videoAbuseInstance, videoInstance, t) | 140 | await sendVideoAbuse(reporterAccount.Actor, videoAbuseInstance, videoInstance, t) |
138 | } | 141 | } |
139 | 142 | ||
140 | auditLogger.create(reporterAccount.Actor.getIdentifier(), new VideoAbuseAuditView(videoAbuseInstance.toFormattedJSON())) | 143 | videoAbuseJSON = videoAbuseInstance.toFormattedJSON() |
144 | auditLogger.create(reporterAccount.Actor.getIdentifier(), new VideoAbuseAuditView(videoAbuseJSON)) | ||
141 | 145 | ||
142 | return videoAbuseInstance | 146 | return videoAbuseInstance |
143 | }) | 147 | }) |
144 | 148 | ||
145 | Notifier.Instance.notifyOnNewVideoAbuse(videoAbuse) | 149 | Notifier.Instance.notifyOnNewVideoAbuse({ |
150 | videoAbuse: videoAbuseJSON, | ||
151 | videoAbuseInstance, | ||
152 | reporter: reporterAccount.Actor.getIdentifier() | ||
153 | }) | ||
146 | 154 | ||
147 | logger.info('Abuse report for video %s created.', videoInstance.name) | 155 | logger.info('Abuse report for video %s created.', videoInstance.name) |
148 | 156 | ||
149 | return res.json({ videoAbuse: videoAbuse.toFormattedJSON() }).end() | 157 | return res.json({ videoAbuseJSON }).end() |
150 | } | 158 | } |