thumbnails
config/production.yaml
ffmpeg
++<<<<<<< HEAD
+torrents
++=======
+ .tags
+ *.sublime-project
+ *.sublime-workspace
+ torrents/
++>>>>>>> master
logout() {
// TODO: make an HTTP request to revoke the tokens
this.user = null;
- User.flush();
+
- this.setStatus(AuthStatus.LoggedIn);
+ AuthUser.flush();
+
+ this.setStatus(AuthStatus.LoggedOut);
}
refreshAccessToken() {
uploads: 'uploads/'
logs: 'logs/'
thumbnails: 'thumbnails/'
+ torrents: 'torrents/'
- network:
- friends: []
-
electron:
debug: false
uploads: 'test1/uploads/'
logs: 'test1/logs/'
thumbnails: 'test1/thumbnails/'
-
- network:
- friends:
- - 'http://localhost:9002'
+ torrents: 'test1/torrents/'
uploads: 'test2/uploads/'
logs: 'test2/logs/'
thumbnails: 'test2/thumbnails/'
-
- network:
- friends:
- - 'http://localhost:9003'
+ torrents: 'test2/torrents/'
uploads: 'test3/uploads/'
logs: 'test3/logs/'
thumbnails: 'test3/thumbnails/'
-
- network:
- friends:
- - 'http://localhost:9001'
+ torrents: 'test3/torrents/'
uploads: 'test4/uploads/'
logs: 'test4/logs/'
thumbnails: 'test4/thumbnails/'
-
- network:
- friends:
- - 'http://localhost:9002'
+ torrents: 'test4/torrents/'
uploads: 'test5/uploads/'
logs: 'test5/logs/'
thumbnails: 'test5/thumbnails/'
-
- network:
- friends:
- - 'http://localhost:9001'
- - 'http://localhost:9004'
+ torrents: 'test5/torrents/'
uploads: 'test6/uploads/'
logs: 'test6/logs/'
thumbnails: 'test6/thumbnails/'
-
- network:
- friends:
- - 'http://localhost:9001'
- - 'http://localhost:9002'
- - 'http://localhost:9003'
+ torrents: 'test6/torrents/'
"request": "^2.57.0",
"request-replay": "^1.0.2",
"scripty": "^1.5.0",
- "segfault-handler": "^1.0.0",
"ursa": "^0.9.1",
- "webtorrent": "^0.96.0",
"winston": "^2.1.1",
"ws": "^1.1.1"
},
// ----------- PeerTube modules -----------
const customValidators = require('./server/helpers/custom-validators')
const installer = require('./server/initializers/installer')
+ const migrator = require('./server/initializers/migrator')
const mongoose = require('mongoose')
const routes = require('./server/controllers')
-const utils = require('./server/helpers/utils')
-const webtorrent = require('./server/lib/webtorrent')
const Request = mongoose.model('Request')
-const Video = mongoose.model('Video')
// Get configurations
const port = config.get('listen.port')
installer.installApplication(function (err) {
if (err) throw err
- // ----------- Make the server listening -----------
- server.listen(port, function () {
- // Activate the pool requests
- Request.activate()
+ // Run the migration scripts if needed
+ migrator.migrate(function (err) {
+ if (err) throw err
+
- // Create/activate the webtorrent module
- webtorrent.create(function () {
- function cleanForExit () {
- utils.cleanForExit(webtorrent.app)
- }
-
- function exitGracefullyOnSignal () {
- process.exit(-1)
- }
-
- process.on('exit', cleanForExit)
- process.on('SIGINT', exitGracefullyOnSignal)
- process.on('SIGTERM', exitGracefullyOnSignal)
-
- // ----------- Make the server listening -----------
- server.listen(port, function () {
- // Activate the pool requests
- Request.activate()
-
- Video.seedAllExisting(function (err) {
- if (err) throw err
-
- logger.info('Seeded all the videos')
- logger.info('Server listening on port %d', port)
- app.emit('ready')
- })
- })
++ // ----------- Make the server listening -----------
++ server.listen(port, function () {
++ // Activate the pool requests
++ Request.activate()
+
- logger.info('Seeded all the videos')
- logger.info('Server listening on port %d', port)
- app.emit('ready')
++ logger.info('Seeded all the videos')
++ logger.info('Server listening on port %d', port)
++ app.emit('ready')
+ })
})
})
// Number of requests to retry for replay requests module
const RETRY_REQUESTS = 5
- // Sortable columns per schema
- const SEARCHABLE_COLUMNS = {
- VIDEOS: [ 'name', 'magnetUri', 'podUrl', 'author', 'tags' ]
- }
-
- // Seeds in parallel we send to electron when "seed all"
- // Once a video is in seeding state we seed another video etc
- const SEEDS_IN_PARALLEL = 3
+ // ---------------------------------------------------------------------------
- // Sortable columns per schema
- const SORTABLE_COLUMNS = {
- VIDEOS: [ 'name', '-name', 'duration', '-duration', 'createdDate', '-createdDate' ]
- }
+ // Password encryption
+ const BCRYPT_SALT_SIZE = 10
+// Express static paths (router)
+const STATIC_PATHS = {
+ THUMBNAILS: '/static/thumbnails',
+ TORRENTS: '/static/torrents/',
+ WEBSEED: '/static/webseed/'
+}
+
// Videos thumbnail size
const THUMBNAILS_SIZE = '200x110'
- const VIDEOS_CONSTRAINTS_FIELDS = {
- NAME: { min: 3, max: 50 }, // Length
- DESCRIPTION: { min: 3, max: 250 }, // Length
- MAGNET_URI: { min: 10 }, // Length
- DURATION: { min: 1, max: 7200 }, // Number
- AUTHOR: { min: 3, max: 20 }, // Length
- TAGS: { min: 1, max: 3 }, // Number of total tags
- TAG: { min: 2, max: 10 }, // Length
- THUMBNAIL: { min: 2, max: 30 },
- THUMBNAIL64: { min: 0, max: 20000 } // Bytes
-// Path for access to thumbnails with express router
-const THUMBNAILS_STATIC_PATH = '/static/thumbnails'
-
+ const USER_ROLES = {
+ ADMIN: 'admin',
+ USER: 'user'
}
+ // Seeds in parallel we send to electron when "seed all"
+ // Once a video is in seeding state we seed another video etc
+ const SEEDS_IN_PARALLEL = 3
+
+ // ---------------------------------------------------------------------------
+
// Special constants for a test instance
if (isTestInstance() === true) {
+ CONSTRAINTS_FIELDS.VIDEOS.DURATION.max = 14
FRIEND_SCORE.BASE = 20
- INTERVAL = 10000
- VIDEOS_CONSTRAINTS_FIELDS.DURATION.max = 14
+ REQUESTS_INTERVAL = 10000
}
// ---------------------------------------------------------------------------
module.exports = {
- API_VERSION: API_VERSION,
- FRIEND_SCORE: FRIEND_SCORE,
- INTERVAL: INTERVAL,
- OAUTH_LIFETIME: OAUTH_LIFETIME,
- PAGINATION_COUNT_DEFAULT: PAGINATION_COUNT_DEFAULT,
- PODS_SCORE: PODS_SCORE,
- REQUESTS_IN_PARALLEL: REQUESTS_IN_PARALLEL,
- REQUESTS_LIMIT: REQUESTS_LIMIT,
- RETRY_REQUESTS: RETRY_REQUESTS,
- SEARCHABLE_COLUMNS: SEARCHABLE_COLUMNS,
- SEEDS_IN_PARALLEL: SEEDS_IN_PARALLEL,
- SORTABLE_COLUMNS: SORTABLE_COLUMNS,
- STATIC_PATHS: STATIC_PATHS,
- THUMBNAILS_SIZE: THUMBNAILS_SIZE,
- VIDEOS_CONSTRAINTS_FIELDS: VIDEOS_CONSTRAINTS_FIELDS
+ API_VERSION,
+ BCRYPT_SALT_SIZE,
+ CONFIG,
+ CONSTRAINTS_FIELDS,
+ FRIEND_SCORE,
+ LAST_MONGO_SCHEMA_VERSION,
+ MONGO_MIGRATION_SCRIPTS,
+ OAUTH_LIFETIME,
+ PAGINATION_COUNT_DEFAULT,
+ PODS_SCORE,
+ REQUESTS_IN_PARALLEL,
+ REQUESTS_INTERVAL,
+ REQUESTS_LIMIT,
+ RETRY_REQUESTS,
+ SEARCHABLE_COLUMNS,
+ SEEDS_IN_PARALLEL,
+ SORTABLE_COLUMNS,
++ STATIC_PATHS,
+ THUMBNAILS_SIZE,
- THUMBNAILS_STATIC_PATH,
+ USER_ROLES
}
// ---------------------------------------------------------------------------
const mongoose = require('mongoose')
const constants = require('../initializers/constants')
- const customValidators = require('../helpers/custom-validators')
+ const customVideosValidators = require('../helpers/custom-validators').videos
const logger = require('../helpers/logger')
+ const modelUtils = require('./utils')
const utils = require('../helpers/utils')
-const webtorrent = require('../lib/webtorrent')
+
+const http = config.get('webserver.https') === true ? 'https' : 'http'
+const host = config.get('webserver.host')
+const port = config.get('webserver.port')
+const uploadsDir = pathUtils.join(__dirname, '..', '..', config.get('storage.uploads'))
+const thumbnailsDir = pathUtils.join(__dirname, '..', '..', config.get('storage.thumbnails'))
+const torrentsDir = pathUtils.join(__dirname, '..', '..', config.get('storage.torrents'))
+const webseedBaseUrl = http + '://' + host + ':' + port + constants.STATIC_PATHS.WEBSEED
// ---------------------------------------------------------------------------
}
VideoSchema.statics = {
- getDurationFromFile: getDurationFromFile,
- list: list,
- listByUrlAndMagnet: listByUrlAndMagnet,
- listByUrls: listByUrls,
- listOwned: listOwned,
- listRemotes: listRemotes,
- load: load,
- search: search
+ getDurationFromFile,
+ listForApi,
+ listByUrlAndMagnet,
+ listByUrls,
+ listOwned,
+ listOwnedByAuthor,
+ listRemotes,
+ load,
- search,
- seedAllExisting
++ search
}
VideoSchema.pre('remove', function (next) {
const tasks = []
if (video.isOwned()) {
- const videoPath = pathUtils.join(uploadsDir, video.filename)
- this.podUrl = http + '://' + host + ':' + port
+ const videoPath = pathUtils.join(constants.CONFIG.STORAGE.UPLOAD_DIR, video.filename)
+ this.podUrl = constants.CONFIG.WEBSERVER.URL
tasks.push(
+ // TODO: refractoring
function (callback) {
- seed(videoPath, callback)
+ createTorrent(videoPath, { announceList: [ [ 'ws://' + host + ':' + port + '/tracker/socket' ] ], urlList: [ webseedBaseUrl + video.filename ] }, function (err, torrent) {
+ if (err) return callback(err)
+
+ fs.writeFile(torrentsDir + video.filename + '.torrent', torrent, function (err) {
+ if (err) return callback(err)
+
+ const parsedTorrent = parseTorrent(torrent)
+ parsedTorrent.xs = video.podUrl + constants.STATIC_PATHS.TORRENTS + video.filename + '.torrent'
+ video.magnetUri = magnet.encode(parsedTorrent)
+
+ callback(null)
+ })
+ })
},
function (callback) {
createThumbnail(videoPath, callback)
query[field] = new RegExp(value)
}
- findWithCount.call(this, query, start, count, sort, callback)
+ modelUtils.listForApiWithCount.call(this, query, start, count, sort, callback)
}
-function seedAllExisting (callback) {
- listOwned.call(this, function (err, videos) {
- if (err) return callback(err)
-
- eachLimit(videos, constants.SEEDS_IN_PARALLEL, function (video, callbackEach) {
- const videoPath = pathUtils.join(constants.CONFIG.STORAGE.UPLOAD_DIR, video.filename)
- seed(videoPath, callbackEach)
- }, callback)
- })
-}
-
// ---------------------------------------------------------------------------
- function findWithCount (query, start, count, sort, callback) {
- const self = this
-
- parallel([
- function (asyncCallback) {
- self.find(query).skip(start).limit(count).sort(sort).exec(asyncCallback)
- },
- function (asyncCallback) {
- self.count(query, asyncCallback)
- }
- ], function (err, results) {
- if (err) return callback(err)
-
- const videos = results[0]
- const totalVideos = results[1]
- return callback(null, videos, totalVideos)
- })
- }
-
function removeThumbnail (video, callback) {
- fs.unlink(thumbnailsDir + video.thumbnail, callback)
+ fs.unlink(constants.CONFIG.STORAGE.THUMBNAILS_DIR + video.thumbnail, callback)
}
function removeFile (video, callback) {