]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - scripts/update-host.ts
Refractor validators
[github/Chocobozzz/PeerTube.git] / scripts / update-host.ts
CommitLineData
75d612ce 1import { database as db } from '../server/initializers/database'
eb8b27c9 2import { getServerAccount } from '../server/helpers/utils'
75d612ce 3
6fcd19ba
C
4db.init(true)
5 .then(() => {
eb8b27c9 6 return getServerAccount()
6fcd19ba 7 })
eb8b27c9
C
8 .then(serverAccount => {
9 return db.AccountFollow.listAcceptedFollowingUrlsForApi([ serverAccount.id ])
10 })
11 .then(res => {
12 return res.total > 0
13 })
14 .then(hasFollowing => {
15 if (hasFollowing === true) {
16 console.log('Cannot update host because you follow other servers!')
75d612ce
C
17 process.exit(-1)
18 }
19
20 console.log('Updating torrent files.')
6fcd19ba
C
21 return db.Video.list()
22 })
23 .then(videos => {
fdbda9e3
C
24 const tasks: Promise<any>[] = []
25
93e1258c 26 videos.forEach(video => {
fdbda9e3
C
27 console.log('Updating video ' + video.uuid)
28
93e1258c 29 video.VideoFiles.forEach(file => {
fdbda9e3 30 tasks.push(video.createTorrentAndSetInfoHash(file))
93e1258c 31 })
75d612ce 32 })
6fcd19ba 33
fdbda9e3
C
34 return Promise.all(tasks)
35 })
36 .then(() => {
6fcd19ba 37 process.exit(0)
75d612ce 38 })