aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/update-host.ts
diff options
context:
space:
mode:
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})