3 const async = require('async')
4 const config = require('config')
5 const pathUtils = require('path')
6 const webtorrent = require('../lib/webtorrent')
8 const logger = require('../helpers/logger')
9 const Videos = require('../models/videos')
11 const uploadDir = pathUtils.join(__dirname, '..', '..', config.get('storage.uploads'))
14 getVideoState: getVideoState,
16 seedAllExisting: seedAllExisting
19 function getVideoState (video) {
20 const exist = (video !== null)
23 owned = (video.namePath !== null)
26 return { exist: exist, owned: owned }
29 function seed (path, callback) {
30 logger.info('Seeding %s...', path)
32 webtorrent.seed(path, function (torrent) {
33 logger.info('%s seeded (%s).', path, torrent.magnetURI)
35 return callback(null, torrent)
39 function seedAllExisting (callback) {
40 Videos.listOwned(function (err, videos_list) {
42 logger.error('Cannot get list of the videos to seed.')
46 async.each(videos_list, function (video, each_callback) {
47 seed(uploadDir + video.namePath, function (err) {
49 logger.error('Cannot seed this video.')
59 // ---------------------------------------------------------------------------
61 module.exports = videos