]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - scripts/update-host.js
Client: fix video timeout
[github/Chocobozzz/PeerTube.git] / scripts / update-host.js
CommitLineData
93d4a3b5
C
1#!/usr/bin/env node
2
3'use strict'
4
5// TODO: document this script
6
7const fs = require('fs')
93d4a3b5
C
8const parseTorrent = require('parse-torrent')
9
10const constants = require('../server/initializers/constants')
dd601993 11const db = require('../server/initializers/database')
93d4a3b5
C
12
13const friends = require('../server/lib/friends')
93d4a3b5 14
dd601993
C
15db.init(true, function () {
16 friends.hasFriends(function (err, hasFriends) {
93d4a3b5
C
17 if (err) throw err
18
dd601993
C
19 if (hasFriends === true) {
20 console.log('Cannot update host because you have friends!')
21 process.exit(-1)
22 }
23
93d4a3b5 24 console.log('Updating torrent files.')
dd601993 25 db.Video.list(function (err, videos) {
93d4a3b5
C
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})