]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/helpers/middlewares/video-abuses.ts
Merge branch 'master' into develop
[github/Chocobozzz/PeerTube.git] / server / helpers / middlewares / video-abuses.ts
index b23f1f021b1d46d0495ffacecefd4c28c4b3dca7..97a5724b6dd69afd69ad3c57051896ff1af310a9 100644 (file)
@@ -1,41 +1,32 @@
-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
+}