]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/controllers/api/videos.js
Add ability for an administrator to remove any video (#61)
[github/Chocobozzz/PeerTube.git] / server / controllers / api / videos.js
index 9acdb8fd26ff7e9f48ab9768937eb5549211af40..1f7d30eef2ee628be093c4cc4b25b7d7187a7831 100644 (file)
@@ -45,6 +45,10 @@ const storage = multer.diskStorage({
 
 const reqFiles = multer({ storage: storage }).fields([{ name: 'videofile', maxCount: 1 }])
 
+router.get('/categories', listVideoCategories)
+router.get('/licences', listVideoLicences)
+router.get('/languages', listVideoLanguages)
+
 router.get('/abuse',
   oAuth.authenticate,
   admin.ensureIsAdmin,
@@ -89,11 +93,13 @@ router.get('/:id',
   validatorsVideos.videosGet,
   getVideo
 )
+
 router.delete('/:id',
   oAuth.authenticate,
   validatorsVideos.videosRemove,
   removeVideo
 )
+
 router.get('/search/:value',
   validatorsVideos.videosSearch,
   validatorsPagination.pagination,
@@ -104,12 +110,31 @@ router.get('/search/:value',
   searchVideos
 )
 
+router.post('/:id/blacklist',
+  oAuth.authenticate,
+  admin.ensureIsAdmin,
+  validatorsVideos.videosBlacklist,
+  addVideoToBlacklist
+)
+
 // ---------------------------------------------------------------------------
 
 module.exports = router
 
 // ---------------------------------------------------------------------------
 
+function listVideoCategories (req, res, next) {
+  res.json(constants.VIDEO_CATEGORIES)
+}
+
+function listVideoLicences (req, res, next) {
+  res.json(constants.VIDEO_LICENCES)
+}
+
+function listVideoLanguages (req, res, next) {
+  res.json(constants.VIDEO_LANGUAGES)
+}
+
 function rateVideoRetryWrapper (req, res, next) {
   const options = {
     arguments: [ req, res ],
@@ -300,6 +325,10 @@ function addVideo (req, res, videoFile, finalCallback) {
         name: videoInfos.name,
         remoteId: null,
         extname: path.extname(videoFile.filename),
+        category: videoInfos.category,
+        licence: videoInfos.licence,
+        language: videoInfos.language,
+        nsfw: videoInfos.nsfw,
         description: videoInfos.description,
         duration: videoFile.duration,
         authorId: author.id
@@ -413,6 +442,10 @@ function updateVideo (req, res, finalCallback) {
       }
 
       if (videoInfosToUpdate.name) videoInstance.set('name', videoInfosToUpdate.name)
+      if (videoInfosToUpdate.category) videoInstance.set('category', videoInfosToUpdate.category)
+      if (videoInfosToUpdate.licence) videoInstance.set('licence', videoInfosToUpdate.licence)
+      if (videoInfosToUpdate.language) videoInstance.set('language', videoInfosToUpdate.language)
+      if (videoInfosToUpdate.nsfw) videoInstance.set('nsfw', videoInfosToUpdate.nsfw)
       if (videoInfosToUpdate.description) videoInstance.set('description', videoInfosToUpdate.description)
 
       videoInstance.save(options).asCallback(function (err) {
@@ -598,3 +631,19 @@ function reportVideoAbuse (req, res, finalCallback) {
     return finalCallback(null)
   })
 }
+
+function addVideoToBlacklist (req, res, next) {
+  const videoInstance = res.locals.video
+
+  db.BlacklistedVideo.create({
+    videoId: videoInstance.id
+  })
+  .asCallback(function (err) {
+    if (err) {
+      logger.error('Errors when blacklisting video ', { error: err })
+      return next(err)
+    }
+
+    return res.type('json').status(204).end()
+  })
+}