]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - scripts/update-host.ts
Fix tree comment rendering
[github/Chocobozzz/PeerTube.git] / scripts / update-host.ts
CommitLineData
da854ddd 1import { getServerActor } from '../server/helpers/utils'
91fea9fc 2import { initDatabaseModels } from '../server/initializers'
50d6de9c 3import { ActorFollowModel } from '../server/models/activitypub/actor-follow'
3fd3ab2d 4import { VideoModel } from '../server/models/video/video'
75d612ce 5
91fea9fc 6initDatabaseModels(true)
6fcd19ba 7 .then(() => {
50d6de9c 8 return getServerActor()
6fcd19ba 9 })
eb8b27c9 10 .then(serverAccount => {
50d6de9c 11 return ActorFollowModel.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 })