const db = require('../../initializers/database')
const logger = require('../../helpers/logger')
+const peertubeCrypto = require('../../helpers/peertube-crypto')
const utils = require('../../helpers/utils')
const friends = require('../../lib/friends')
const middlewares = require('../../middlewares')
},
function fetchMyCertificate (callback) {
- friends.getMyCertificate(function (err, cert) {
+ peertubeCrypto.getMyPublicCert(function (err, cert) {
if (err) {
logger.error('Cannot read cert file.')
return callback(err)
const router = express.Router()
const opengraphComment = '<!-- opengraph tags -->'
-const distPath = path.join(__dirname, '../../client/dist')
+const distPath = path.join(__dirname, '..', '..', 'client/dist')
const embedPath = path.join(distPath, 'standalone/videos/embed.html')
const indexPath = path.join(distPath, 'index.html')
const bcrypt = require('bcrypt')
const fs = require('fs')
const openssl = require('openssl-wrapper')
+const pathUtils = require('path')
const constants = require('../initializers/constants')
const logger = require('./logger')
comparePassword,
createCertsIfNotExist,
cryptPassword,
+ getMyPrivateCert,
+ getMyPublicCert,
sign
}
sign.update(dataString, 'utf8')
// TODO: make async
- const myKey = fs.readFileSync(constants.CONFIG.STORAGE.CERT_DIR + 'peertube.key.pem')
+ const certPath = pathUtils.join(constants.CONFIG.STORAGE.CERT_DIR, constants.PRIVATE_CERT_NAME)
+ const myKey = fs.readFileSync(certPath)
const signature = sign.sign(myKey, constants.SIGNATURE_ENCODING)
return signature
})
}
+function getMyPrivateCert (callback) {
+ const certPath = pathUtils.join(constants.CONFIG.STORAGE.CERT_DIR, constants.PRIVATE_CERT_NAME)
+ fs.readFile(certPath, 'utf8', callback)
+}
+
+function getMyPublicCert (callback) {
+ const certPath = pathUtils.join(constants.CONFIG.STORAGE.CERT_DIR, constants.PUBLIC_CERT_NAME)
+ fs.readFile(certPath, 'utf8', callback)
+}
+
// ---------------------------------------------------------------------------
module.exports = peertubeCrypto
// ---------------------------------------------------------------------------
function certsExist (callback) {
- fs.exists(constants.CONFIG.STORAGE.CERT_DIR + 'peertube.key.pem', function (exists) {
+ const certPath = pathUtils.join(constants.CONFIG.STORAGE.CERT_DIR, constants.PRIVATE_CERT_NAME)
+ fs.exists(certPath, function (exists) {
return callback(exists)
})
}
logger.info('Generating a RSA key...')
- let options = {
- 'out': constants.CONFIG.STORAGE.CERT_DIR + 'peertube.key.pem',
+ const privateCertPath = pathUtils.join(constants.CONFIG.STORAGE.CERT_DIR, constants.PRIVATE_CERT_NAME)
+ const genRsaOptions = {
+ 'out': privateCertPath,
'2048': false
}
- openssl.exec('genrsa', options, function (err) {
+ openssl.exec('genrsa', genRsaOptions, function (err) {
if (err) {
logger.error('Cannot create private key on this pod.')
return callback(err)
}
+
logger.info('RSA key generated.')
+ logger.info('Managing public key...')
- options = {
- 'in': constants.CONFIG.STORAGE.CERT_DIR + 'peertube.key.pem',
+ const publicCertPath = pathUtils.join(constants.CONFIG.STORAGE.CERT_DIR, 'peertube.pub')
+ const rsaOptions = {
+ 'in': privateCertPath,
'pubout': true,
- 'out': constants.CONFIG.STORAGE.CERT_DIR + 'peertube.pub'
+ 'out': publicCertPath
}
- logger.info('Manage public key...')
- openssl.exec('rsa', options, function (err) {
+ openssl.exec('rsa', rsaOptions, function (err) {
if (err) {
logger.error('Cannot create public key on this pod.')
return callback(err)
// ---------------------------------------------------------------------------
+const PRIVATE_CERT_NAME = 'peertube.key.pem'
+const PUBLIC_CERT_NAME = 'peertube.pub'
const SIGNATURE_ALGORITHM = 'RSA-SHA256'
const SIGNATURE_ENCODING = 'hex'
PAGINATION_COUNT_DEFAULT,
PODS_SCORE,
PREVIEWS_SIZE,
+ PRIVATE_CERT_NAME,
+ PUBLIC_CERT_NAME,
REMOTE_SCHEME,
- REQUEST_ENDPOINTS,
REQUEST_ENDPOINT_ACTIONS,
+ REQUEST_ENDPOINTS,
REQUESTS_IN_PARALLEL,
REQUESTS_INTERVAL,
- REQUESTS_LIMIT_PODS,
REQUESTS_LIMIT_PER_POD,
+ REQUESTS_LIMIT_PODS,
RETRY_REQUESTS,
SEARCHABLE_COLUMNS,
SIGNATURE_ALGORITHM,
const each = require('async/each')
const eachLimit = require('async/eachLimit')
const eachSeries = require('async/eachSeries')
-const fs = require('fs')
const request = require('request')
const waterfall = require('async/waterfall')
const constants = require('../initializers/constants')
const db = require('../initializers/database')
const logger = require('../helpers/logger')
+const peertubeCrypto = require('../helpers/peertube-crypto')
const requests = require('../helpers/requests')
const ENDPOINT_ACTIONS = constants.REQUEST_ENDPOINT_ACTIONS[constants.REQUEST_ENDPOINTS.VIDEOS]
updateVideoToFriends,
reportAbuseVideoToFriend,
hasFriends,
- getMyCertificate,
makeFriends,
quitFriends,
removeVideoToFriends,
})
}
-function getMyCertificate (callback) {
- fs.readFile(constants.CONFIG.STORAGE.CERT_DIR + 'peertube.pub', 'utf8', callback)
-}
-
function makeFriends (hosts, callback) {
const podsScore = {}
logger.info('Make friends!')
- getMyCertificate(function (err, cert) {
+ peertubeCrypto.getMyPublicCert(function (err, cert) {
if (err) {
logger.error('Cannot read public cert.')
return callback(err)
const videoPath = pathUtils.join(constants.CONFIG.STORAGE.VIDEOS_DIR, video.getVideoFilename())
tasks.push(
- // TODO: refractoring
- function (callback) {
+ function createVideoTorrent (callback) {
const options = {
announceList: [
[ constants.CONFIG.WEBSERVER.WS + '://' + constants.CONFIG.WEBSERVER.HOSTNAME + ':' + constants.CONFIG.WEBSERVER.PORT + '/tracker/socket' ]
createTorrent(videoPath, options, function (err, torrent) {
if (err) return callback(err)
- fs.writeFile(constants.CONFIG.STORAGE.TORRENTS_DIR + video.getTorrentName(), torrent, function (err) {
+ const filePath = pathUtils.join(constants.CONFIG.STORAGE.TORRENTS_DIR, video.getTorrentName())
+ fs.writeFile(filePath, torrent, function (err) {
if (err) return callback(err)
const parsedTorrent = parseTorrent(torrent)
})
})
},
- function (callback) {
+
+ function createVideoThumbnail (callback) {
createThumbnail(video, videoPath, callback)
},
- function (callback) {
+
+ function createVIdeoPreview (callback) {
createPreview(video, videoPath, callback)
}
)
if (video.isOwned()) {
tasks.push(
- function (callback) {
+ function removeVideoFile (callback) {
removeFile(video, callback)
},
- function (callback) {
+ function removeVideoTorrent (callback) {
removeTorrent(video, callback)
},
- function (callback) {
+ function removeVideoPreview (callback) {
removePreview(video, callback)
},
- function (callback) {
+ function removeVideoToFriends (callback) {
const params = {
remoteId: video.id
}
// Creating the thumbnail for a remote video
const thumbnailName = video.getThumbnailName()
- const thumbnailPath = constants.CONFIG.STORAGE.THUMBNAILS_DIR + thumbnailName
+ const thumbnailPath = pathUtils.join(constants.CONFIG.STORAGE.THUMBNAILS_DIR, thumbnailName)
fs.writeFile(thumbnailPath, Buffer.from(thumbnailData, 'binary'), function (err) {
if (err) return callback(err)
// ---------------------------------------------------------------------------
function removeThumbnail (video, callback) {
- fs.unlink(constants.CONFIG.STORAGE.THUMBNAILS_DIR + video.getThumbnailName(), callback)
+ const thumbnailPath = pathUtils.join(constants.CONFIG.STORAGE.THUMBNAILS_DIR, video.getThumbnailName())
+ fs.unlink(thumbnailPath, callback)
}
function removeFile (video, callback) {
- fs.unlink(constants.CONFIG.STORAGE.VIDEOS_DIR + video.getVideoFilename(), callback)
+ const filePath = pathUtils.join(constants.CONFIG.STORAGE.VIDEOS_DIR, video.getVideoFilename())
+ fs.unlink(filePath, callback)
}
function removeTorrent (video, callback) {
- fs.unlink(constants.CONFIG.STORAGE.TORRENTS_DIR + video.getTorrentName(), callback)
+ const torrenPath = pathUtils.join(constants.CONFIG.STORAGE.TORRENTS_DIR, video.getTorrentName())
+ fs.unlink(torrenPath, callback)
}
function removePreview (video, callback) {
videosUtils.removeVideo(server.url, server.accessToken, videoId, function (err) {
if (err) throw err
- fs.readdir(pathUtils.join(__dirname, '../../../test1/videos/'), function (err, files) {
+ fs.readdir(pathUtils.join(__dirname, '..', '..', '..', 'test1/videos/'), function (err, files) {
if (err) throw err
expect(files.length).to.equal(0)
- fs.readdir(pathUtils.join(__dirname, '../../../test1/thumbnails/'), function (err, files) {
+ fs.readdir(pathUtils.join(__dirname, '..', '..', '..', 'test1/thumbnails/'), function (err, files) {
if (err) throw err
expect(files.length).to.equal(0)
detached: true
}
- server.app = fork(pathUtils.join(__dirname, '../../../server.js'), [], options)
+ server.app = fork(pathUtils.join(__dirname, '..', '..', '..', 'server.js'), [], options)
server.app.stdout.on('data', function onStdout (data) {
let dontContinue = false