1
0
Fork 0
peertube/scripts/update-host.ts

36 lines
1009 B
TypeScript
Raw Normal View History

2017-12-28 10:16:08 +00:00
import { getServerActor } from '../server/helpers/utils'
2017-12-13 16:46:23 +00:00
import { initDatabaseModels } from '../server/initializers'
2017-12-14 16:38:41 +00:00
import { ActorFollowModel } from '../server/models/activitypub/actor-follow'
2017-12-12 16:53:50 +00:00
import { VideoModel } from '../server/models/video/video'
2017-06-12 19:06:32 +00:00
2017-12-13 16:46:23 +00:00
initDatabaseModels(true)
.then(() => {
2017-12-14 16:38:41 +00:00
return getServerActor()
})
2017-11-17 15:24:08 +00:00
.then(serverAccount => {
2017-12-14 16:38:41 +00:00
return ActorFollowModel.listAcceptedFollowingUrlsForApi([ serverAccount.id ], undefined)
2017-11-17 15:24:08 +00: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 19:06:32 +00:00
process.exit(-1)
}
console.log('Updating torrent files.')
2017-12-12 16:53:50 +00:00
return VideoModel.list()
})
2018-03-20 07:54:24 +00:00
.then(async videos => {
for (const video of videos) {
for (const file of video.VideoFiles) {
await video.createTorrentAndSetInfoHash(file)
console.log('Updated video ' + video.uuid)
}
}
2017-09-07 13:27:35 +00:00
})
.then(() => {
process.exit(0)
2017-06-12 19:06:32 +00:00
})