2019-08-15 04:53:26 -05:00
|
|
|
import { Response } from 'express'
|
2020-07-01 09:05:30 -05:00
|
|
|
import { AbuseModel } from '../../models/abuse/abuse'
|
2020-04-16 07:22:27 -05:00
|
|
|
import { fetchVideo } from '../video'
|
2019-07-23 03:40:39 -05:00
|
|
|
|
2020-07-01 09:05:30 -05:00
|
|
|
// FIXME: deprecated in 2.3. Remove this function
|
2020-04-16 07:22:27 -05:00
|
|
|
async function doesVideoAbuseExist (abuseIdArg: number | string, videoUUID: string, res: Response) {
|
2019-10-21 07:50:55 -05:00
|
|
|
const abuseId = parseInt(abuseIdArg + '', 10)
|
2020-07-01 09:05:30 -05:00
|
|
|
let abuse = await AbuseModel.loadByIdAndVideoId(abuseId, null, videoUUID)
|
2020-04-16 07:22:27 -05:00
|
|
|
|
2020-07-01 09:05:30 -05:00
|
|
|
if (!abuse) {
|
2020-04-20 04:20:12 -05:00
|
|
|
const userId = res.locals.oauth?.token.User.id
|
2020-04-16 07:22:27 -05:00
|
|
|
const video = await fetchVideo(videoUUID, 'all', userId)
|
|
|
|
|
2020-07-01 09:05:30 -05:00
|
|
|
if (video) abuse = await AbuseModel.loadByIdAndVideoId(abuseId, video.id)
|
2020-04-16 07:22:27 -05:00
|
|
|
}
|
2019-07-23 03:40:39 -05:00
|
|
|
|
2020-07-01 09:05:30 -05:00
|
|
|
if (abuse === null) {
|
2019-07-23 03:40:39 -05:00
|
|
|
res.status(404)
|
2019-08-15 04:53:26 -05:00
|
|
|
.json({ error: 'Video abuse not found' })
|
2019-07-23 03:40:39 -05:00
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-07-01 09:05:30 -05:00
|
|
|
res.locals.abuse = abuse
|
2019-07-23 03:40:39 -05:00
|
|
|
return true
|
|
|
|
}
|
2019-08-15 04:53:26 -05:00
|
|
|
|
2020-07-07 03:57:04 -05:00
|
|
|
async function doesAbuseExist (abuseId: number | string, res: Response) {
|
|
|
|
const abuse = await AbuseModel.loadById(parseInt(abuseId + '', 10))
|
2020-07-01 09:05:30 -05:00
|
|
|
|
2020-07-07 03:57:04 -05:00
|
|
|
if (!abuse) {
|
|
|
|
res.status(404)
|
|
|
|
.json({ error: 'Video abuse not found' })
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
res.locals.abuse = abuse
|
|
|
|
return true
|
2020-07-01 09:05:30 -05:00
|
|
|
}
|
|
|
|
|
2019-08-15 04:53:26 -05:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
2020-07-01 09:05:30 -05:00
|
|
|
doesAbuseExist,
|
2019-08-15 04:53:26 -05:00
|
|
|
doesVideoAbuseExist
|
|
|
|
}
|