aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/videos.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-02-04 21:10:33 +0100
committerChocobozzz <florian.bigard@gmail.com>2016-02-04 21:10:33 +0100
commitc173e56520b0fe4206b9ea8049b6add40bfeabcd (patch)
tree264c6cbf1bf81a6522685b4be5771bbeef4cd5dc /lib/videos.js
parentc45f7f84001c2731909db04dd82e1c1f290386eb (diff)
downloadPeerTube-c173e56520b0fe4206b9ea8049b6add40bfeabcd.tar.gz
PeerTube-c173e56520b0fe4206b9ea8049b6add40bfeabcd.tar.zst
PeerTube-c173e56520b0fe4206b9ea8049b6add40bfeabcd.zip
Split models
Diffstat (limited to 'lib/videos.js')
-rw-r--r--lib/videos.js51
1 files changed, 51 insertions, 0 deletions
diff --git a/lib/videos.js b/lib/videos.js
new file mode 100644
index 000000000..5d23070a7
--- /dev/null
+++ b/lib/videos.js
@@ -0,0 +1,51 @@
1;(function () {
2 'use strict'
3
4 var async = require('async')
5 var config = require('config')
6 var webtorrent = require('../lib/webTorrentNode')
7
8 var logger = require('../helpers/logger')
9 var Videos = require('../models/videos')
10
11 var uploadDir = __dirname + '/../' + config.get('storage.uploads')
12
13 var videos = {
14 seed: seed,
15 seedAllExisting: seedAllExisting
16 }
17
18 function seed (path, callback) {
19 logger.info('Seeding %s...', path)
20
21 webtorrent.seed(path, function (torrent) {
22 logger.info('%s seeded (%s).', path, torrent.magnetURI)
23
24 return callback(null, torrent)
25 })
26 }
27
28 function seedAllExisting (callback) {
29 Videos.listOwned(function (err, videos_list) {
30 if (err) {
31 logger.error('Cannot get list of the videos to seed.', { error: err })
32 return callback(err)
33 }
34
35 async.each(videos_list, function (video, each_callback) {
36 seed(uploadDir + video.namePath, function (err) {
37 if (err) {
38 logger.error('Cannot seed this video.', { error: err })
39 return callback(err)
40 }
41
42 each_callback(null)
43 })
44 }, callback)
45 })
46 }
47
48 // ---------------------------------------------------------------------------
49
50 module.exports = videos
51})()