-import * as express from 'express'
-import { VideoChannelModel } from '../../models/video/video-channel'
+import { Response } from 'express'
+import { VideoAbuseModel } from '../../models/video/video-abuse'
+import { fetchVideo } from '../video'
-async function doesLocalVideoChannelNameExist (name: string, res: express.Response) {
- const videoChannel = await VideoChannelModel.loadLocalByNameAndPopulateAccount(name)
+async function doesVideoAbuseExist (abuseIdArg: number | string, videoUUID: string, res: Response) {
+ const abuseId = parseInt(abuseIdArg + '', 10)
+ let videoAbuse = await VideoAbuseModel.loadByIdAndVideoId(abuseId, null, videoUUID)
- return processVideoChannelExist(videoChannel, res)
-}
-
-async function doesVideoChannelIdExist (id: number, res: express.Response) {
- const videoChannel = await VideoChannelModel.loadAndPopulateAccount(+id)
-
- return processVideoChannelExist(videoChannel, res)
-}
-
-async function doesVideoChannelNameWithHostExist (nameWithDomain: string, res: express.Response) {
- const videoChannel = await VideoChannelModel.loadByNameWithHostAndPopulateAccount(nameWithDomain)
-
- return processVideoChannelExist(videoChannel, res)
-}
-
-// ---------------------------------------------------------------------------
+ if (!videoAbuse) {
+ const userId = res.locals.oauth?.token.User.id
+ const video = await fetchVideo(videoUUID, 'all', userId)
-export {
- doesLocalVideoChannelNameExist,
- doesVideoChannelIdExist,
- doesVideoChannelNameWithHostExist
-}
+ if (video) videoAbuse = await VideoAbuseModel.loadByIdAndVideoId(abuseId, video.id)
+ }
-function processVideoChannelExist (videoChannel: VideoChannelModel, res: express.Response) {
- if (!videoChannel) {
+ if (videoAbuse === null) {
res.status(404)
- .json({ error: 'Video channel not found' })
+ .json({ error: 'Video abuse not found' })
.end()
return false
}
- res.locals.videoChannel = videoChannel
+ res.locals.videoAbuse = videoAbuse
return true
}
+
+// ---------------------------------------------------------------------------
+
+export {
+ doesVideoAbuseExist
+}