2019-08-15 11:53:26 +02:00
|
|
|
import { Response } from 'express'
|
|
|
|
import { VideoAbuseModel } from '../../models/video/video-abuse'
|
2020-04-16 14:22:27 +02:00
|
|
|
import { fetchVideo } from '../video'
|
2019-07-23 10:40:39 +02:00
|
|
|
|
2020-04-16 14:22:27 +02:00
|
|
|
async function doesVideoAbuseExist (abuseIdArg: number | string, videoUUID: string, res: Response) {
|
2019-10-21 14:50:55 +02:00
|
|
|
const abuseId = parseInt(abuseIdArg + '', 10)
|
2020-04-16 14:22:27 +02:00
|
|
|
let videoAbuse = await VideoAbuseModel.loadByIdAndVideoId(abuseId, null, videoUUID)
|
|
|
|
|
|
|
|
if (!videoAbuse) {
|
2020-04-20 11:20:12 +02:00
|
|
|
const userId = res.locals.oauth?.token.User.id
|
2020-04-16 14:22:27 +02:00
|
|
|
const video = await fetchVideo(videoUUID, 'all', userId)
|
|
|
|
|
|
|
|
if (video) videoAbuse = await VideoAbuseModel.loadByIdAndVideoId(abuseId, video.id)
|
|
|
|
}
|
2019-07-23 10:40:39 +02:00
|
|
|
|
2019-08-15 11:53:26 +02:00
|
|
|
if (videoAbuse === null) {
|
2019-07-23 10:40:39 +02:00
|
|
|
res.status(404)
|
2019-08-15 11:53:26 +02:00
|
|
|
.json({ error: 'Video abuse not found' })
|
2019-07-23 10:40:39 +02:00
|
|
|
.end()
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2019-08-15 11:53:26 +02:00
|
|
|
res.locals.videoAbuse = videoAbuse
|
2019-07-23 10:40:39 +02:00
|
|
|
return true
|
|
|
|
}
|
2019-08-15 11:53:26 +02:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
doesVideoAbuseExist
|
|
|
|
}
|