2017-06-12 21:06:32 +02:00
|
|
|
import { database as db } from '../server/initializers/database'
|
2017-11-17 16:24:08 +01:00
|
|
|
import { getServerAccount } from '../server/helpers/utils'
|
2017-06-12 21:06:32 +02:00
|
|
|
|
2017-07-05 13:26:25 +02:00
|
|
|
db.init(true)
|
|
|
|
.then(() => {
|
2017-11-17 16:24:08 +01:00
|
|
|
return getServerAccount()
|
2017-07-05 13:26:25 +02:00
|
|
|
})
|
2017-11-17 16:24:08 +01:00
|
|
|
.then(serverAccount => {
|
2017-11-30 13:16:23 +01:00
|
|
|
return db.AccountFollow.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-07-05 13:26:25 +02:00
|
|
|
return db.Video.list()
|
|
|
|
})
|
|
|
|
.then(videos => {
|
2017-09-07 15:27:35 +02:00
|
|
|
const tasks: Promise<any>[] = []
|
|
|
|
|
2017-08-25 11:36:23 +02:00
|
|
|
videos.forEach(video => {
|
2017-09-07 15:27:35 +02:00
|
|
|
console.log('Updating video ' + video.uuid)
|
|
|
|
|
2017-08-25 11:36:23 +02:00
|
|
|
video.VideoFiles.forEach(file => {
|
2017-09-07 15:27:35 +02:00
|
|
|
tasks.push(video.createTorrentAndSetInfoHash(file))
|
2017-08-25 11:36:23 +02:00
|
|
|
})
|
2017-06-12 21:06:32 +02:00
|
|
|
})
|
2017-07-05 13:26:25 +02:00
|
|
|
|
2017-09-07 15:27:35 +02:00
|
|
|
return Promise.all(tasks)
|
|
|
|
})
|
|
|
|
.then(() => {
|
2017-07-05 13:26:25 +02:00
|
|
|
process.exit(0)
|
2017-06-12 21:06:32 +02:00
|
|
|
})
|