aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--package.json1
-rw-r--r--server/controllers/api/remote.js4
-rw-r--r--server/controllers/api/users.js2
-rw-r--r--server/helpers/custom-validators/videos.js9
-rw-r--r--server/initializers/constants.js2
-rw-r--r--server/models/video.js11
6 files changed, 14 insertions, 15 deletions
diff --git a/package.json b/package.json
index bff21082f..5eadcc363 100644
--- a/package.json
+++ b/package.json
@@ -66,6 +66,7 @@
66 "request": "^2.57.0", 66 "request": "^2.57.0",
67 "request-replay": "^1.0.2", 67 "request-replay": "^1.0.2",
68 "rimraf": "^2.5.4", 68 "rimraf": "^2.5.4",
69 "safe-buffer": "^5.0.1",
69 "scripty": "^1.5.0", 70 "scripty": "^1.5.0",
70 "sequelize": "^3.27.0", 71 "sequelize": "^3.27.0",
71 "ursa": "^0.9.1", 72 "ursa": "^0.9.1",
diff --git a/server/controllers/api/remote.js b/server/controllers/api/remote.js
index 94d6e740e..ac850c2d2 100644
--- a/server/controllers/api/remote.js
+++ b/server/controllers/api/remote.js
@@ -147,9 +147,9 @@ function addRemoteVideo (videoToCreateData, fromHost, finalCallback) {
147 }, 147 },
148 148
149 function generateThumbnail (t, tagInstances, video, callback) { 149 function generateThumbnail (t, tagInstances, video, callback) {
150 db.Video.generateThumbnailFromBase64(video, videoToCreateData.thumbnailBase64, function (err) { 150 db.Video.generateThumbnailFromData(video, videoToCreateData.thumbnailData, function (err) {
151 if (err) { 151 if (err) {
152 logger.error('Cannot generate thumbnail from base 64 data.', { error: err }) 152 logger.error('Cannot generate thumbnail from data.', { error: err })
153 return callback(err) 153 return callback(err)
154 } 154 }
155 155
diff --git a/server/controllers/api/users.js b/server/controllers/api/users.js
index e4423680c..53bf56790 100644
--- a/server/controllers/api/users.js
+++ b/server/controllers/api/users.js
@@ -1,12 +1,10 @@
1'use strict' 1'use strict'
2 2
3const each = require('async/each')
4const express = require('express') 3const express = require('express')
5const waterfall = require('async/waterfall') 4const waterfall = require('async/waterfall')
6 5
7const constants = require('../../initializers/constants') 6const constants = require('../../initializers/constants')
8const db = require('../../initializers/database') 7const db = require('../../initializers/database')
9const friends = require('../../lib/friends')
10const logger = require('../../helpers/logger') 8const logger = require('../../helpers/logger')
11const middlewares = require('../../middlewares') 9const middlewares = require('../../middlewares')
12const admin = middlewares.admin 10const admin = middlewares.admin
diff --git a/server/helpers/custom-validators/videos.js b/server/helpers/custom-validators/videos.js
index da857ba5f..4aaa6aaa9 100644
--- a/server/helpers/custom-validators/videos.js
+++ b/server/helpers/custom-validators/videos.js
@@ -17,7 +17,7 @@ const videosValidators = {
17 isVideoNameValid, 17 isVideoNameValid,
18 isVideoTagsValid, 18 isVideoTagsValid,
19 isVideoThumbnailValid, 19 isVideoThumbnailValid,
20 isVideoThumbnail64Valid 20 isVideoThumbnailDataValid
21} 21}
22 22
23function isEachRemoteVideosValid (requests) { 23function isEachRemoteVideosValid (requests) {
@@ -33,7 +33,7 @@ function isEachRemoteVideosValid (requests) {
33 isVideoInfoHashValid(video.infoHash) && 33 isVideoInfoHashValid(video.infoHash) &&
34 isVideoNameValid(video.name) && 34 isVideoNameValid(video.name) &&
35 isVideoTagsValid(video.tags) && 35 isVideoTagsValid(video.tags) &&
36 isVideoThumbnail64Valid(video.thumbnailBase64) && 36 isVideoThumbnailDataValid(video.thumbnailData) &&
37 isVideoRemoteIdValid(video.remoteId) && 37 isVideoRemoteIdValid(video.remoteId) &&
38 isVideoExtnameValid(video.extname) 38 isVideoExtnameValid(video.extname)
39 ) || 39 ) ||
@@ -86,9 +86,8 @@ function isVideoThumbnailValid (value) {
86 return validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.THUMBNAIL) 86 return validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.THUMBNAIL)
87} 87}
88 88
89function isVideoThumbnail64Valid (value) { 89function isVideoThumbnailDataValid (value) {
90 return validator.isBase64(value) && 90 return validator.isByteLength(value, VIDEOS_CONSTRAINTS_FIELDS.THUMBNAIL_DATA)
91 validator.isByteLength(value, VIDEOS_CONSTRAINTS_FIELDS.THUMBNAIL64)
92} 91}
93 92
94function isVideoRemoteIdValid (value) { 93function isVideoRemoteIdValid (value) {
diff --git a/server/initializers/constants.js b/server/initializers/constants.js
index 0af7aca3c..474a37277 100644
--- a/server/initializers/constants.js
+++ b/server/initializers/constants.js
@@ -74,7 +74,7 @@ const CONSTRAINTS_FIELDS = {
74 TAGS: { min: 1, max: 3 }, // Number of total tags 74 TAGS: { min: 1, max: 3 }, // Number of total tags
75 TAG: { min: 2, max: 10 }, // Length 75 TAG: { min: 2, max: 10 }, // Length
76 THUMBNAIL: { min: 2, max: 30 }, 76 THUMBNAIL: { min: 2, max: 30 },
77 THUMBNAIL64: { min: 0, max: 20000 } // Bytes 77 THUMBNAIL_DATA: { min: 0, max: 20000 } // Bytes
78 } 78 }
79} 79}
80 80
diff --git a/server/models/video.js b/server/models/video.js
index 564e362fd..0e84e8986 100644
--- a/server/models/video.js
+++ b/server/models/video.js
@@ -1,5 +1,6 @@
1'use strict' 1'use strict'
2 2
3const Buffer = require('safe-buffer').Buffer
3const createTorrent = require('create-torrent') 4const createTorrent = require('create-torrent')
4const ffmpeg = require('fluent-ffmpeg') 5const ffmpeg = require('fluent-ffmpeg')
5const fs = require('fs') 6const fs = require('fs')
@@ -106,7 +107,7 @@ module.exports = function (sequelize, DataTypes) {
106 classMethods: { 107 classMethods: {
107 associate, 108 associate,
108 109
109 generateThumbnailFromBase64, 110 generateThumbnailFromData,
110 getDurationFromFile, 111 getDurationFromFile,
111 list, 112 list,
112 listForApi, 113 listForApi,
@@ -336,7 +337,7 @@ function toFormatedJSON () {
336function toRemoteJSON (callback) { 337function toRemoteJSON (callback) {
337 const self = this 338 const self = this
338 339
339 // Convert thumbnail to base64 340 // Get thumbnail data to send to the other pod
340 const thumbnailPath = pathUtils.join(constants.CONFIG.STORAGE.THUMBNAILS_DIR, this.getThumbnailName()) 341 const thumbnailPath = pathUtils.join(constants.CONFIG.STORAGE.THUMBNAILS_DIR, this.getThumbnailName())
341 fs.readFile(thumbnailPath, function (err, thumbnailData) { 342 fs.readFile(thumbnailPath, function (err, thumbnailData) {
342 if (err) { 343 if (err) {
@@ -351,7 +352,7 @@ function toRemoteJSON (callback) {
351 remoteId: self.id, 352 remoteId: self.id,
352 author: self.Author.name, 353 author: self.Author.name,
353 duration: self.duration, 354 duration: self.duration,
354 thumbnailBase64: new Buffer(thumbnailData).toString('base64'), 355 thumbnailData: thumbnailData.toString('binary'),
355 tags: map(self.Tags, 'name'), 356 tags: map(self.Tags, 'name'),
356 createdAt: self.createdAt, 357 createdAt: self.createdAt,
357 extname: self.extname 358 extname: self.extname
@@ -363,12 +364,12 @@ function toRemoteJSON (callback) {
363 364
364// ------------------------------ STATICS ------------------------------ 365// ------------------------------ STATICS ------------------------------
365 366
366function generateThumbnailFromBase64 (video, thumbnailData, callback) { 367function generateThumbnailFromData (video, thumbnailData, callback) {
367 // Creating the thumbnail for a remote video 368 // Creating the thumbnail for a remote video
368 369
369 const thumbnailName = video.getThumbnailName() 370 const thumbnailName = video.getThumbnailName()
370 const thumbnailPath = constants.CONFIG.STORAGE.THUMBNAILS_DIR + thumbnailName 371 const thumbnailPath = constants.CONFIG.STORAGE.THUMBNAILS_DIR + thumbnailName
371 fs.writeFile(thumbnailPath, thumbnailData, { encoding: 'base64' }, function (err) { 372 fs.writeFile(thumbnailPath, Buffer.from(thumbnailData, 'binary'), function (err) {
372 if (err) return callback(err) 373 if (err) return callback(err)
373 374
374 return callback(null, thumbnailName) 375 return callback(null, thumbnailName)