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