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

35 lines
798 B
TypeScript
Raw Normal View History

2017-06-12 19:06:32 +00:00
import { database as db } from '../server/initializers/database'
2017-11-10 16:27:49 +00:00
// import { hasFriends } from '../server/lib/friends'
2017-06-12 19:06:32 +00:00
db.init(true)
.then(() => {
// FIXME: check if has following
2017-11-10 16:27:49 +00:00
// return hasFriends()
return true
})
.then(itHasFriends => {
2017-06-12 19:06:32 +00:00
if (itHasFriends === true) {
console.log('Cannot update host because you have friends!')
process.exit(-1)
}
console.log('Updating torrent files.')
return db.Video.list()
})
.then(videos => {
2017-09-07 13:27:35 +00:00
const tasks: Promise<any>[] = []
videos.forEach(video => {
2017-09-07 13:27:35 +00:00
console.log('Updating video ' + video.uuid)
video.VideoFiles.forEach(file => {
2017-09-07 13:27:35 +00:00
tasks.push(video.createTorrentAndSetInfoHash(file))
})
2017-06-12 19:06:32 +00:00
})
2017-09-07 13:27:35 +00:00
return Promise.all(tasks)
})
.then(() => {
process.exit(0)
2017-06-12 19:06:32 +00:00
})