]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - scripts/update-host.ts
Convert tests to typescript
[github/Chocobozzz/PeerTube.git] / scripts / update-host.ts
CommitLineData
75d612ce 1import { readFileSync, writeFileSync } from 'fs'
93e1258c 2import { join } from 'path'
75d612ce
C
3import * as parseTorrent from 'parse-torrent'
4
5import { CONFIG, STATIC_PATHS } from '../server/initializers/constants'
6import { database as db } from '../server/initializers/database'
7import { hasFriends } from '../server/lib/friends'
8
6fcd19ba
C
9db.init(true)
10 .then(() => {
11 return hasFriends()
12 })
13 .then(itHasFriends => {
75d612ce
C
14 if (itHasFriends === true) {
15 console.log('Cannot update host because you have friends!')
16 process.exit(-1)
17 }
18
19 console.log('Updating torrent files.')
6fcd19ba
C
20 return db.Video.list()
21 })
22 .then(videos => {
93e1258c
C
23 videos.forEach(video => {
24 video.VideoFiles.forEach(file => {
25 video.createTorrentAndSetInfoHash(file)
26 })
75d612ce 27 })
6fcd19ba
C
28
29 process.exit(0)
75d612ce 30 })