]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/videos.js
Fix clean_test script
[github/Chocobozzz/PeerTube.git] / server / lib / videos.js
CommitLineData
9f10b292
C
1'use strict'
2
3var async = require('async')
4var config = require('config')
6f4e2522 5// TODO
9f10b292
C
6var path = require('path')
7var webtorrent = require('../lib/webtorrent')
8
9var logger = require('../helpers/logger')
10var Videos = require('../models/videos')
11
12var uploadDir = path.join(__dirname, '..', config.get('storage.uploads'))
13
14var videos = {
15 seed: seed,
16 seedAllExisting: seedAllExisting
17}
18
19function 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
29function seedAllExisting (callback) {
30 Videos.listOwned(function (err, videos_list) {
31 if (err) {
32 logger.error('Cannot get list of the videos to seed.')
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) {
39 logger.error('Cannot seed this video.')
40 return callback(err)
41 }
42
43 each_callback(null)
44 })
45 }, callback)
46 })
47}
48
49// ---------------------------------------------------------------------------
50
51module.exports = videos