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