2017-12-14 11:38:41 -05:00
|
|
|
import { getServerActor } from '../server/helpers'
|
2017-12-13 11:46:23 -05:00
|
|
|
import { initDatabaseModels } from '../server/initializers'
|
2017-12-14 11:38:41 -05:00
|
|
|
import { ActorFollowModel } from '../server/models/activitypub/actor-follow'
|
2017-12-12 11:53:50 -05:00
|
|
|
import { VideoModel } from '../server/models/video/video'
|
2017-06-12 15:06:32 -04:00
|
|
|
|
2017-12-13 11:46:23 -05:00
|
|
|
initDatabaseModels(true)
|
2017-07-05 07:26:25 -04:00
|
|
|
.then(() => {
|
2017-12-14 11:38:41 -05:00
|
|
|
return getServerActor()
|
2017-07-05 07:26:25 -04:00
|
|
|
})
|
2017-11-17 10:24:08 -05:00
|
|
|
.then(serverAccount => {
|
2017-12-14 11:38:41 -05:00
|
|
|
return ActorFollowModel.listAcceptedFollowingUrlsForApi([ serverAccount.id ], undefined)
|
2017-11-17 10:24:08 -05: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 15:06:32 -04:00
|
|
|
process.exit(-1)
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log('Updating torrent files.')
|
2017-12-12 11:53:50 -05:00
|
|
|
return VideoModel.list()
|
2017-07-05 07:26:25 -04:00
|
|
|
})
|
|
|
|
.then(videos => {
|
2017-09-07 09:27:35 -04:00
|
|
|
const tasks: Promise<any>[] = []
|
|
|
|
|
2017-08-25 05:36:23 -04:00
|
|
|
videos.forEach(video => {
|
2017-09-07 09:27:35 -04:00
|
|
|
console.log('Updating video ' + video.uuid)
|
|
|
|
|
2017-08-25 05:36:23 -04:00
|
|
|
video.VideoFiles.forEach(file => {
|
2017-09-07 09:27:35 -04:00
|
|
|
tasks.push(video.createTorrentAndSetInfoHash(file))
|
2017-08-25 05:36:23 -04:00
|
|
|
})
|
2017-06-12 15:06:32 -04:00
|
|
|
})
|
2017-07-05 07:26:25 -04:00
|
|
|
|
2017-09-07 09:27:35 -04:00
|
|
|
return Promise.all(tasks)
|
|
|
|
})
|
|
|
|
.then(() => {
|
2017-07-05 07:26:25 -04:00
|
|
|
process.exit(0)
|
2017-06-12 15:06:32 -04:00
|
|
|
})
|