2017-06-12 15:06:32 -04:00
|
|
|
import { database as db } from '../server/initializers/database'
|
2017-11-10 11:27:49 -05:00
|
|
|
// import { hasFriends } from '../server/lib/friends'
|
2017-06-12 15:06:32 -04:00
|
|
|
|
2017-07-05 07:26:25 -04:00
|
|
|
db.init(true)
|
|
|
|
.then(() => {
|
2017-11-15 04:10:41 -05:00
|
|
|
// FIXME: check if has following
|
2017-11-10 11:27:49 -05:00
|
|
|
// return hasFriends()
|
|
|
|
return true
|
2017-07-05 07:26:25 -04:00
|
|
|
})
|
|
|
|
.then(itHasFriends => {
|
2017-06-12 15:06:32 -04:00
|
|
|
if (itHasFriends === true) {
|
|
|
|
console.log('Cannot update host because you have friends!')
|
|
|
|
process.exit(-1)
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log('Updating torrent files.')
|
2017-07-05 07:26:25 -04:00
|
|
|
return db.Video.list()
|
|
|
|
})
|
|
|
|
.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
|
|
|
})
|