]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - lib/videos.js
Standard v6
[github/Chocobozzz/PeerTube.git] / lib / videos.js
CommitLineData
c173e565
C
1;(function () {
2 'use strict'
3
4 var async = require('async')
5 var config = require('config')
b3077e41 6 var path = require('path')
c5a8be2b 7 var webtorrent = require('../lib/webtorrent')
c173e565
C
8
9 var logger = require('../helpers/logger')
10 var Videos = require('../models/videos')
11
b3077e41 12 var uploadDir = path.join(__dirname, '..', config.get('storage.uploads'))
c173e565
C
13
14 var videos = {
15 seed: seed,
16 seedAllExisting: seedAllExisting
17 }
18
19 function seed (path, callback) {
20 logger.info('Seeding %s...', path)
21
22 webtorrent.seed(path, function (torrent) {
23 logger.info('%s seeded (%s).', path, torrent.magnetURI)
24
25 return callback(null, torrent)
26 })
27 }
28
29 function seedAllExisting (callback) {
30 Videos.listOwned(function (err, videos_list) {
31 if (err) {
8425cb89 32 logger.error('Cannot get list of the videos to seed.')
c173e565
C
33 return callback(err)
34 }
35
36 async.each(videos_list, function (video, each_callback) {
37 seed(uploadDir + video.namePath, function (err) {
38 if (err) {
8425cb89 39 logger.error('Cannot seed this video.')
c173e565
C
40 return callback(err)
41 }
42
43 each_callback(null)
44 })
45 }, callback)
46 })
47 }
48
49 // ---------------------------------------------------------------------------
50
51 module.exports = videos
52})()