X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fcontrollers%2Fapi%2Fremote.js;h=2d0db51c02e47435a10f8bdbacf718c10bfd26b8;hb=a078c1556fa81e14f4e0b2239c5000c02ac0717f;hp=94808693d4558e1be922fe66790597b9a2cbad82;hpb=558d7c2385d8a152a94140eed753f511e90986d7;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/controllers/api/remote.js b/server/controllers/api/remote.js index 94808693d..2d0db51c0 100644 --- a/server/controllers/api/remote.js +++ b/server/controllers/api/remote.js @@ -30,7 +30,7 @@ module.exports = router function remoteVideos (req, res, next) { const requests = req.body.data - const fromUrl = req.body.signature.url + const fromHost = req.body.signature.host // We need to process in the same order to keep consistency // TODO: optimization @@ -40,7 +40,7 @@ function remoteVideos (req, res, next) { if (request.type === 'add') { addRemoteVideo(videoData, callbackEach) } else if (request.type === 'remove') { - removeRemoteVideo(videoData, fromUrl, callbackEach) + removeRemoteVideo(videoData, fromHost, callbackEach) } else { logger.error('Unkown remote request type %s.', request.type) } @@ -53,25 +53,29 @@ function remoteVideos (req, res, next) { } function addRemoteVideo (videoToCreateData, callback) { - logger.debug('Adding remote video %s.', videoToCreateData.magnetUri) - - // Mongoose pre hook will automatically create the thumbnail on disk - videoToCreateData.thumbnail = videoToCreateData.thumbnailBase64 + logger.debug('Adding remote video "%s".', videoToCreateData.name) const video = new Video(videoToCreateData) - video.save(callback) + Video.generateThumbnailFromBase64(video, videoToCreateData.thumbnailBase64, function (err) { + if (err) { + logger.error('Cannot generate thumbnail from base 64 data.', { error: err }) + return callback(err) + } + + video.save(callback) + }) } -function removeRemoteVideo (videoToRemoveData, fromUrl, callback) { +function removeRemoteVideo (videoToRemoveData, fromHost, callback) { // We need the list because we have to remove some other stuffs (thumbnail etc) - Video.listByUrlAndRemoteId(fromUrl, videoToRemoveData.remoteId, function (err, videosList) { + Video.listByHostAndRemoteId(fromHost, videoToRemoveData.remoteId, function (err, videosList) { if (err) { - logger.error('Cannot list videos from url and magnets.', { error: err }) + logger.error('Cannot list videos from host and magnets.', { error: err }) return callback(err) } if (videosList.length === 0) { - logger.error('No remote video was found for this pod.', { magnetUri: videoToRemoveData.magnetUri, podUrl: fromUrl }) + logger.error('No remote video was found for this pod.', { magnetUri: videoToRemoveData.magnetUri, podHost: fromHost }) } each(videosList, function (video, callbackEach) {