aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/update-host.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-07-05 13:26:25 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-07-05 14:14:16 +0200
commit6fcd19ba737f1f5614a56c6925adb882dea43b8d (patch)
tree3365a96d82bc7f00ae504a568725c8e914150cf8 /scripts/update-host.ts
parent5fe7e898316e18369c3e1aba307b55077adc7bfb (diff)
downloadPeerTube-6fcd19ba737f1f5614a56c6925adb882dea43b8d.tar.gz
PeerTube-6fcd19ba737f1f5614a56c6925adb882dea43b8d.tar.zst
PeerTube-6fcd19ba737f1f5614a56c6925adb882dea43b8d.zip
Move to promises
Closes https://github.com/Chocobozzz/PeerTube/issues/74
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})