]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - scripts/update-host.js
Server: do not break remote videos processing on error
[github/Chocobozzz/PeerTube.git] / scripts / update-host.js
1 #!/usr/bin/env node
2
3 'use strict'
4
5 // TODO: document this script
6
7 const fs = require('fs')
8 const parseTorrent = require('parse-torrent')
9
10 const constants = require('../server/initializers/constants')
11 const db = require('../server/initializers/database')
12
13 const friends = require('../server/lib/friends')
14
15 db.init(true, function () {
16 friends.hasFriends(function (err, hasFriends) {
17 if (err) throw err
18
19 if (hasFriends === true) {
20 console.log('Cannot update host because you have friends!')
21 process.exit(-1)
22 }
23
24 console.log('Updating torrent files.')
25 db.Video.list(function (err, videos) {
26 if (err) throw err
27
28 videos.forEach(function (video) {
29 const torrentName = video._id + '.torrent'
30 const torrentPath = constants.CONFIG.STORAGE.TORRENTS_DIR + torrentName
31 const filename = video._id + video.extname
32
33 const parsed = parseTorrent(fs.readFileSync(torrentPath))
34 parsed.announce = [ constants.CONFIG.WEBSERVER.WS + '://' + constants.CONFIG.WEBSERVER.HOST + '/tracker/socket' ]
35 parsed.urlList = [ constants.CONFIG.WEBSERVER.URL + constants.STATIC_PATHS.WEBSEED + filename ]
36
37 const buf = parseTorrent.toTorrentFile(parsed)
38 fs.writeFileSync(torrentPath, buf)
39 })
40
41 process.exit(0)
42 })
43 })
44 })