]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - scripts/update-host.js
5 // TODO: document this script
7 const fs
= require('fs')
8 const mongoose
= require('mongoose')
9 const parseTorrent
= require('parse-torrent')
11 const constants
= require('../server/initializers/constants')
12 const database
= require('../server/initializers/database')
16 const friends
= require('../server/lib/friends')
17 const Video
= mongoose
.model('Video')
19 friends
.hasFriends(function (err
, hasFriends
) {
22 if (hasFriends
=== true) {
23 console
.log('Cannot update host because you have friends!')
27 console
.log('Updating videos host in database.')
28 Video
.update({ }, { podHost: constants
.CONFIG
.WEBSERVER
.HOST
}, { multi: true }, function (err
) {
31 console
.log('Updating torrent files.')
32 Video
.find().lean().exec(function (err
, videos
) {
35 videos
.forEach(function (video
) {
36 const torrentName
= video
._id
+ '.torrent'
37 const torrentPath
= constants
.CONFIG
.STORAGE
.TORRENTS_DIR
+ torrentName
38 const filename
= video
._id
+ video
.extname
40 const parsed
= parseTorrent(fs
.readFileSync(torrentPath
))
41 parsed
.announce
= [ constants
.CONFIG
.WEBSERVER
.WS
+ '://' + constants
.CONFIG
.WEBSERVER
.HOST
+ '/tracker/socket' ]
42 parsed
.urlList
= [ constants
.CONFIG
.WEBSERVER
.URL
+ constants
.STATIC_PATHS
.WEBSEED
+ filename
]
44 const buf
= parseTorrent
.toTorrentFile(parsed
)
45 fs
.writeFileSync(torrentPath
, buf
)