aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/update-host.ts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/update-host.ts')
-rwxr-xr-xscripts/update-host.ts43
1 files changed, 21 insertions, 22 deletions
diff --git a/scripts/update-host.ts b/scripts/update-host.ts
index 0f6af0942..23e8d5ef3 100755
--- a/scripts/update-host.ts
+++ b/scripts/update-host.ts
@@ -5,33 +5,32 @@ import { CONFIG, STATIC_PATHS } from '../server/initializers/constants'
5import { database as db } from '../server/initializers/database' 5import { database as db } from '../server/initializers/database'
6import { hasFriends } from '../server/lib/friends' 6import { hasFriends } from '../server/lib/friends'
7 7
8db.init(true, function () { 8db.init(true)
9 hasFriends(function (err, itHasFriends) { 9 .then(() => {
10 if (err) throw err 10 return hasFriends()
11 11 })
12 .then(itHasFriends => {
12 if (itHasFriends === true) { 13 if (itHasFriends === true) {
13 console.log('Cannot update host because you have friends!') 14 console.log('Cannot update host because you have friends!')
14 process.exit(-1) 15 process.exit(-1)
15 } 16 }
16 17
17 console.log('Updating torrent files.') 18 console.log('Updating torrent files.')
18 db.Video.list(function (err, videos) { 19 return db.Video.list()
19 if (err) throw err 20 })
20 21 .then(videos => {
21 videos.forEach(function (video) { 22 videos.forEach(function (video) {
22 const torrentName = video.id + '.torrent' 23 const torrentName = video.id + '.torrent'
23 const torrentPath = CONFIG.STORAGE.TORRENTS_DIR + torrentName 24 const torrentPath = CONFIG.STORAGE.TORRENTS_DIR + torrentName
24 const filename = video.id + video.extname 25 const filename = video.id + video.extname
25 26
26 const parsed = parseTorrent(readFileSync(torrentPath)) 27 const parsed = parseTorrent(readFileSync(torrentPath))
27 parsed.announce = [ CONFIG.WEBSERVER.WS + '://' + CONFIG.WEBSERVER.HOST + '/tracker/socket' ] 28 parsed.announce = [ CONFIG.WEBSERVER.WS + '://' + CONFIG.WEBSERVER.HOST + '/tracker/socket' ]
28 parsed.urlList = [ CONFIG.WEBSERVER.URL + STATIC_PATHS.WEBSEED + filename ] 29 parsed.urlList = [ CONFIG.WEBSERVER.URL + STATIC_PATHS.WEBSEED + filename ]
29 30
30 const buf = parseTorrent.toTorrentFile(parsed) 31 const buf = parseTorrent.toTorrentFile(parsed)
31 writeFileSync(torrentPath, buf) 32 writeFileSync(torrentPath, buf)
32 })
33
34 process.exit(0)
35 }) 33 })
34
35 process.exit(0)
36 }) 36 })
37})