-import { readFileSync, writeFileSync } from 'fs'
-import { join } from 'path'
-import * as parseTorrent from 'parse-torrent'
-
-import { CONFIG, STATIC_PATHS } from '../server/initializers/constants'
import { database as db } from '../server/initializers/database'
-import { hasFriends } from '../server/lib/friends'
+import { getServerAccount } from '../server/helpers/utils'
db.init(true)
.then(() => {
- return hasFriends()
+ return getServerAccount()
+ })
+ .then(serverAccount => {
+ return db.AccountFollow.listAcceptedFollowingUrlsForApi([ serverAccount.id ], undefined)
})
- .then(itHasFriends => {
- if (itHasFriends === true) {
- console.log('Cannot update host because you have friends!')
+ .then(res => {
+ return res.total > 0
+ })
+ .then(hasFollowing => {
+ if (hasFollowing === true) {
+ console.log('Cannot update host because you follow other servers!')
process.exit(-1)
}
return db.Video.list()
})
.then(videos => {
+ const tasks: Promise<any>[] = []
+
videos.forEach(video => {
+ console.log('Updating video ' + video.uuid)
+
video.VideoFiles.forEach(file => {
- video.createTorrentAndSetInfoHash(file)
+ tasks.push(video.createTorrentAndSetInfoHash(file))
})
})
+ return Promise.all(tasks)
+ })
+ .then(() => {
process.exit(0)
})