aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/update-host.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-06-12 21:06:32 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-06-12 21:06:32 +0200
commit75d612ce3ca9d6f69fe8e4e83dc3070d9ab56615 (patch)
tree016f64d0fc6cfee533516be40d76eaca1b1f837e /scripts/update-host.ts
parent7593a21d13baad422efedfb658d7ceda4e0a8c6b (diff)
downloadPeerTube-75d612ce3ca9d6f69fe8e4e83dc3070d9ab56615.tar.gz
PeerTube-75d612ce3ca9d6f69fe8e4e83dc3070d9ab56615.tar.zst
PeerTube-75d612ce3ca9d6f69fe8e4e83dc3070d9ab56615.zip
Convert scripts to typescript
Diffstat (limited to 'scripts/update-host.ts')
-rwxr-xr-xscripts/update-host.ts37
1 files changed, 37 insertions, 0 deletions
diff --git a/scripts/update-host.ts b/scripts/update-host.ts
new file mode 100755
index 000000000..0f6af0942
--- /dev/null
+++ b/scripts/update-host.ts
@@ -0,0 +1,37 @@
1import { readFileSync, writeFileSync } from 'fs'
2import * as parseTorrent from 'parse-torrent'
3
4import { CONFIG, STATIC_PATHS } from '../server/initializers/constants'
5import { database as db } from '../server/initializers/database'
6import { hasFriends } from '../server/lib/friends'
7
8db.init(true, function () {
9 hasFriends(function (err, itHasFriends) {
10 if (err) throw err
11
12 if (itHasFriends === true) {
13 console.log('Cannot update host because you have friends!')
14 process.exit(-1)
15 }
16
17 console.log('Updating torrent files.')
18 db.Video.list(function (err, videos) {
19 if (err) throw err
20
21 videos.forEach(function (video) {
22 const torrentName = video.id + '.torrent'
23 const torrentPath = CONFIG.STORAGE.TORRENTS_DIR + torrentName
24 const filename = video.id + video.extname
25
26 const parsed = parseTorrent(readFileSync(torrentPath))
27 parsed.announce = [ CONFIG.WEBSERVER.WS + '://' + CONFIG.WEBSERVER.HOST + '/tracker/socket' ]
28 parsed.urlList = [ CONFIG.WEBSERVER.URL + STATIC_PATHS.WEBSEED + filename ]
29
30 const buf = parseTorrent.toTorrentFile(parsed)
31 writeFileSync(torrentPath, buf)
32 })
33
34 process.exit(0)
35 })
36 })
37})