]>
Commit | Line | Data |
---|---|---|
75d612ce C |
1 | import { readFileSync, writeFileSync } from 'fs' |
2 | import * as parseTorrent from 'parse-torrent' | |
3 | ||
4 | import { CONFIG, STATIC_PATHS } from '../server/initializers/constants' | |
5 | import { database as db } from '../server/initializers/database' | |
6 | import { hasFriends } from '../server/lib/friends' | |
7 | ||
6fcd19ba C |
8 | db.init(true) |
9 | .then(() => { | |
10 | return hasFriends() | |
11 | }) | |
12 | .then(itHasFriends => { | |
75d612ce C |
13 | if (itHasFriends === true) { |
14 | console.log('Cannot update host because you have friends!') | |
15 | process.exit(-1) | |
16 | } | |
17 | ||
18 | console.log('Updating torrent files.') | |
6fcd19ba C |
19 | return db.Video.list() |
20 | }) | |
21 | .then(videos => { | |
22 | videos.forEach(function (video) { | |
23 | const torrentName = video.id + '.torrent' | |
24 | const torrentPath = CONFIG.STORAGE.TORRENTS_DIR + torrentName | |
25 | const filename = video.id + video.extname | |
26 | ||
27 | const parsed = parseTorrent(readFileSync(torrentPath)) | |
28 | parsed.announce = [ CONFIG.WEBSERVER.WS + '://' + CONFIG.WEBSERVER.HOST + '/tracker/socket' ] | |
29 | parsed.urlList = [ CONFIG.WEBSERVER.URL + STATIC_PATHS.WEBSEED + filename ] | |
30 | ||
31 | const buf = parseTorrent.toTorrentFile(parsed) | |
32 | writeFileSync(torrentPath, buf) | |
75d612ce | 33 | }) |
6fcd19ba C |
34 | |
35 | process.exit(0) | |
75d612ce | 36 | }) |