Standard v6

This commit is contained in:
Chocobozzz 2016-02-07 10:39:37 +01:00
parent c5a8be2b62
commit b3077e4170
12 changed files with 35 additions and 26 deletions

View File

@ -3,15 +3,16 @@
'use strict' 'use strict'
var config = require('config') var config = require('config')
var path = require('path')
var winston = require('winston') var winston = require('winston')
winston.emitErrs = true winston.emitErrs = true
var logDir = __dirname + '/../' + config.get('storage.logs') var logDir = path.join(__dirname, '..', config.get('storage.logs'))
var logger = new winston.Logger({ var logger = new winston.Logger({
transports: [ transports: [
new winston.transports.File({ new winston.transports.File({
level: 'debug', level: 'debug',
filename: logDir + '/all-logs.log', filename: path.join(logDir, 'all-logs.log'),
handleExceptions: true, handleExceptions: true,
json: true, json: true,
maxsize: 5242880, maxsize: 5242880,

View File

@ -5,11 +5,12 @@
var crypto = require('crypto') var crypto = require('crypto')
var fs = require('fs') var fs = require('fs')
var openssl = require('openssl-wrapper') var openssl = require('openssl-wrapper')
var path = require('path')
var ursa = require('ursa') var ursa = require('ursa')
var logger = require('./logger') var logger = require('./logger')
var certDir = __dirname + '/../' + config.get('storage.certs') var certDir = path.join(__dirname, '..', config.get('storage.certs'))
var algorithm = 'aes-256-ctr' var algorithm = 'aes-256-ctr'
var peertubeCrypto = { var peertubeCrypto = {

View File

@ -3,6 +3,7 @@
var config = require('config') var config = require('config')
var mkdirp = require('mkdirp') var mkdirp = require('mkdirp')
var path = require('path')
var checker = { var checker = {
checkConfig: checkConfig, checkConfig: checkConfig,
@ -32,9 +33,9 @@
var storages = config.get('storage') var storages = config.get('storage')
for (var key of Object.keys(storages)) { for (var key of Object.keys(storages)) {
var path = storages[key] var dir = storages[key]
try { try {
mkdirp.sync(__dirname + '/../' + path) mkdirp.sync(path.join(__dirname, '..', dir))
} catch (error) { } catch (error) {
// Do not use logger // Do not use logger
console.error('Cannot create ' + path + ':' + error) console.error('Cannot create ' + path + ':' + error)

View File

@ -41,7 +41,7 @@
} }
// Remove the request of the other type // Remove the request of the other type
PoolRequests.removeById(id, function (err) { PoolRequests.removeRequestById(id, function (err) {
if (err) { if (err) {
logger.error('Cannot remove a pool request.', { error: err }) logger.error('Cannot remove a pool request.', { error: err })
return // Abort return // Abort
@ -49,7 +49,7 @@
}) })
} else { } else {
PoolRequests.create(id, type, request, function (err) { PoolRequests.create(id, type, request, function (err) {
logger.error('Cannot create a pool request.', { error: err }) if (err) logger.error('Cannot create a pool request.', { error: err })
return // Abort return // Abort
}) })
} }

View File

@ -3,12 +3,13 @@
var async = require('async') var async = require('async')
var config = require('config') var config = require('config')
var path = require('path')
var webtorrent = require('../lib/webtorrent') var webtorrent = require('../lib/webtorrent')
var logger = require('../helpers/logger') var logger = require('../helpers/logger')
var Videos = require('../models/videos') var Videos = require('../models/videos')
var uploadDir = __dirname + '/../' + config.get('storage.uploads') var uploadDir = path.join(__dirname, '..', config.get('storage.uploads'))
var videos = { var videos = {
seed: seed, seed: seed,

View File

@ -59,7 +59,7 @@
process.exit() process.exit()
}) })
var webtorrent_process = spawn(__dirname + '/webtorrentProcess.js', host, port, { detached: true }) var webtorrent_process = spawn(pathUtils.join(__dirname, 'webtorrentProcess.js'), host, port, { detached: true })
webtorrent_process.stderr.on('data', function (data) { webtorrent_process.stderr.on('data', function (data) {
// logger.debug('Webtorrent process stderr: ', data.toString()) // logger.debug('Webtorrent process stderr: ', data.toString())
}) })

View File

@ -6,13 +6,14 @@
var dz = require('dezalgo') var dz = require('dezalgo')
var fs = require('fs') var fs = require('fs')
var mongoose = require('mongoose') var mongoose = require('mongoose')
var path = require('path')
var logger = require('../helpers/logger') var logger = require('../helpers/logger')
var http = config.get('webserver.https') === true ? 'https' : 'http' var http = config.get('webserver.https') === true ? 'https' : 'http'
var host = config.get('webserver.host') var host = config.get('webserver.host')
var port = config.get('webserver.port') var port = config.get('webserver.port')
var uploadDir = __dirname + '/../' + config.get('storage.uploads') var uploadDir = path.join(__dirname, '..', config.get('storage.uploads'))
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------

View File

@ -66,7 +66,7 @@
"devDependencies": { "devDependencies": {
"chai": "^3.3.0", "chai": "^3.3.0",
"mocha": "^2.3.3", "mocha": "^2.3.3",
"standard": "^5.1.0", "standard": "^6.0.1",
"supertest": "^1.1.0" "supertest": "^1.1.0"
}, },
"standard": { "standard": {

View File

@ -4,6 +4,7 @@
var async = require('async') var async = require('async')
var chai = require('chai') var chai = require('chai')
var expect = chai.expect var expect = chai.expect
var pathUtils = require('path')
var request = require('supertest') var request = require('supertest')
var utils = require('./utils') var utils = require('./utils')
@ -119,7 +120,7 @@
describe('When searching a video', function () { describe('When searching a video', function () {
it('Should fail with nothing', function (done) { it('Should fail with nothing', function (done) {
request(url) request(url)
.get(path + '/search/') .get(pathUtils.join(path, 'search'))
.set('Accept', 'application/json') .set('Accept', 'application/json')
.expect(400, done) .expect(400, done)
}) })
@ -137,7 +138,7 @@
description: 'my super description' description: 'my super description'
} }
var attach = { var attach = {
'input_video': __dirname + '/fixtures/video_short.webm' 'input_video': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
} }
makePostRequest(path, data, attach, done) makePostRequest(path, data, attach, done)
}) })
@ -148,7 +149,7 @@
description: 'my super description' description: 'my super description'
} }
var attach = { var attach = {
'input_video': __dirname + '/fixtures/video_short.webm' 'input_video': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
} }
makePostRequest(path, data, attach, done) makePostRequest(path, data, attach, done)
}) })
@ -158,7 +159,7 @@
name: 'my super name' name: 'my super name'
} }
var attach = { var attach = {
'input_video': __dirname + '/fixtures/video_short.webm' 'input_video': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
} }
makePostRequest(path, data, attach, done) makePostRequest(path, data, attach, done)
}) })
@ -171,7 +172,7 @@
'very very very very very very very very very very very very very very very long' 'very very very very very very very very very very very very very very very long'
} }
var attach = { var attach = {
'input_video': __dirname + '/fixtures/video_short.webm' 'input_video': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
} }
makePostRequest(path, data, attach, done) makePostRequest(path, data, attach, done)
}) })
@ -191,7 +192,7 @@
description: 'my super description' description: 'my super description'
} }
var attach = { var attach = {
'input_video': __dirname + '/../fixtures/video_short_fake.webm' 'input_video': pathUtils.join(__dirname, '..', 'fixtures', 'video_short_fake.webm')
} }
makePostRequest(path, data, attach, done) makePostRequest(path, data, attach, done)
}) })
@ -202,12 +203,12 @@
description: 'my super description' description: 'my super description'
} }
var attach = { var attach = {
'input_video': __dirname + '/fixtures/video_short.webm' 'input_video': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
} }
makePostRequest(path, data, attach, function () { makePostRequest(path, data, attach, function () {
attach.input_video = __dirname + '/fixtures/video_short.mp4' attach.input_video = pathUtils.join(__dirname, 'fixtures', 'video_short.mp4')
makePostRequest(path, data, attach, function () { makePostRequest(path, data, attach, function () {
attach.input_video = __dirname + '/fixtures/video_short.ogv' attach.input_video = pathUtils.join(__dirname, 'fixtures', 'video_short.ogv')
makePostRequest(path, data, attach, done, true) makePostRequest(path, data, attach, done, true)
}, true) }, true)
}, true) }, true)

View File

@ -4,9 +4,10 @@
var async = require('async') var async = require('async')
var chai = require('chai') var chai = require('chai')
var expect = chai.expect var expect = chai.expect
var pathUtils = require('path')
var utils = require('./utils') var utils = require('./utils')
var webtorrent = require(__dirname + '/../../lib/webtorrent') var webtorrent = require(pathUtils.join(__dirname, '../../lib/webtorrent'))
webtorrent.silent = true webtorrent.silent = true
describe('Test multiple pods', function () { describe('Test multiple pods', function () {

View File

@ -5,8 +5,9 @@
var chai = require('chai') var chai = require('chai')
var expect = chai.expect var expect = chai.expect
var fs = require('fs') var fs = require('fs')
var pathUtils = require('path')
var webtorrent = require(__dirname + '/../../lib/webtorrent') var webtorrent = require(pathUtils.join(__dirname, '../../lib/webtorrent'))
webtorrent.silent = true webtorrent.silent = true
var utils = require('./utils') var utils = require('./utils')
@ -112,7 +113,7 @@
utils.removeVideo(url, video_id, function (err) { utils.removeVideo(url, video_id, function (err) {
if (err) throw err if (err) throw err
fs.readdir(__dirname + '/../../test1/uploads/', function (err, files) { fs.readdir(pathUtils.join(__dirname, '../../test1/uploads/'), function (err, files) {
if (err) throw err if (err) throw err
expect(files.length).to.equal(0) expect(files.length).to.equal(0)

View File

@ -4,6 +4,7 @@
var child_process = require('child_process') var child_process = require('child_process')
var exec = child_process.exec var exec = child_process.exec
var fork = child_process.fork var fork = child_process.fork
var pathUtils = require('path')
var request = require('supertest') var request = require('supertest')
var testUtils = { var testUtils = {
@ -22,7 +23,7 @@
// ---------------------- Export functions -------------------- // ---------------------- Export functions --------------------
function flushTests (callback) { function flushTests (callback) {
exec(__dirname + '/../../scripts/clean_test.sh', callback) exec(pathUtils.join(__dirname, '../../scripts/clean_test.sh'), callback)
} }
function getFriendsList (url, end) { function getFriendsList (url, end) {
@ -139,7 +140,7 @@
detached: true detached: true
} }
var app = fork(__dirname + '/../../server.js', [], options) var app = fork(pathUtils.join(__dirname, '../../server.js'), [], options)
app.stdout.on('data', function onStdout (data) { app.stdout.on('data', function onStdout (data) {
var dont_continue = false var dont_continue = false
// Check if all required sentences are here // Check if all required sentences are here
@ -175,7 +176,7 @@
.set('Accept', 'application/json') .set('Accept', 'application/json')
.field('name', name) .field('name', name)
.field('description', description) .field('description', description)
.attach('input_video', __dirname + '/fixtures/' + fixture) .attach('input_video', pathUtils.join(__dirname, 'fixtures', fixture))
.expect(201) .expect(201)
.end(end) .end(end)
} }