PeerTube/scripts/update-host.ts

41 lines
1.0 KiB
TypeScript
Raw Normal View History

2017-12-28 11:16:08 +01:00
import { getServerActor } from '../server/helpers/utils'
2017-12-13 17:46:23 +01:00
import { initDatabaseModels } from '../server/initializers'
2017-12-14 17:38:41 +01:00
import { ActorFollowModel } from '../server/models/activitypub/actor-follow'
2017-12-12 17:53:50 +01:00
import { VideoModel } from '../server/models/video/video'
2017-06-12 21:06:32 +02:00
2017-12-13 17:46:23 +01:00
initDatabaseModels(true)
.then(() => {
2017-12-14 17:38:41 +01:00
return getServerActor()
})
2017-11-17 16:24:08 +01:00
.then(serverAccount => {
2017-12-14 17:38:41 +01:00
return ActorFollowModel.listAcceptedFollowingUrlsForApi([ serverAccount.id ], undefined)
2017-11-17 16:24:08 +01:00
})
.then(res => {
return res.total > 0
})
.then(hasFollowing => {
if (hasFollowing === true) {
console.log('Cannot update host because you follow other servers!')
2017-06-12 21:06:32 +02:00
process.exit(-1)
}
console.log('Updating torrent files.')
2017-12-12 17:53:50 +01:00
return VideoModel.list()
})
.then(videos => {
2017-09-07 15:27:35 +02:00
const tasks: Promise<any>[] = []
videos.forEach(video => {
2017-09-07 15:27:35 +02:00
console.log('Updating video ' + video.uuid)
video.VideoFiles.forEach(file => {
2017-09-07 15:27:35 +02:00
tasks.push(video.createTorrentAndSetInfoHash(file))
})
2017-06-12 21:06:32 +02:00
})
2017-09-07 15:27:35 +02:00
return Promise.all(tasks)
})
.then(() => {
process.exit(0)
2017-06-12 21:06:32 +02:00
})