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
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)
}
}
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) {