]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/controllers/api/videos.js
Server: Fix video propagation with transcoding enabled
[github/Chocobozzz/PeerTube.git] / server / controllers / api / videos.js
index 8c69ff4e5b9dd31ded315e5b9d35c013d20c8abf..4a4c5e162c0f7b21d7586b015073db6f27812c15 100644 (file)
@@ -46,6 +46,8 @@ 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,
@@ -91,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,
@@ -106,6 +110,13 @@ router.get('/search/:value',
   searchVideos
 )
 
+router.post('/:id/blacklist',
+  oAuth.authenticate,
+  admin.ensureIsAdmin,
+  validatorsVideos.videosBlacklist,
+  addVideoToBlacklist
+)
+
 // ---------------------------------------------------------------------------
 
 module.exports = router
@@ -116,6 +127,14 @@ 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 ],
@@ -307,6 +326,9 @@ function addVideo (req, res, videoFile, finalCallback) {
         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
@@ -357,6 +379,9 @@ function addVideo (req, res, videoFile, finalCallback) {
     },
 
     function sendToFriends (t, video, callback) {
+      // Let transcoding job send the video to friends because the videofile extension might change
+      if (constants.CONFIG.TRANSCODING.ENABLED === true) return callback(null, t)
+
       video.toAddRemoteJSON(function (err, remoteVideo) {
         if (err) return callback(err)
 
@@ -421,6 +446,9 @@ 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) {
@@ -606,3 +634,20 @@ function reportVideoAbuse (req, res, finalCallback) {
     return finalCallback(null)
   })
 }
+
+function addVideoToBlacklist (req, res, next) {
+  const videoInstance = res.locals.video
+
+  const toCreate = {
+    videoId: videoInstance.id
+  }
+
+  db.BlacklistedVideo.create(toCreate).asCallback(function (err) {
+    if (err) {
+      logger.error('Errors when blacklisting video ', { error: err })
+      return next(err)
+    }
+
+    return res.type('json').status(204).end()
+  })
+}