Move video file metadata in their own table
[oweals/peertube.git] / scripts / update-host.ts
1 import { readFileSync, writeFileSync } from 'fs'
2 import { join } from 'path'
3 import * as parseTorrent from 'parse-torrent'
4
5 import { CONFIG, STATIC_PATHS } from '../server/initializers/constants'
6 import { database as db } from '../server/initializers/database'
7 import { hasFriends } from '../server/lib/friends'
8
9 db.init(true)
10   .then(() => {
11     return hasFriends()
12   })
13   .then(itHasFriends => {
14     if (itHasFriends === true) {
15       console.log('Cannot update host because you have friends!')
16       process.exit(-1)
17     }
18
19     console.log('Updating torrent files.')
20     return db.Video.list()
21   })
22   .then(videos => {
23     videos.forEach(video => {
24       video.VideoFiles.forEach(file => {
25         video.createTorrentAndSetInfoHash(file)
26       })
27     })
28
29     process.exit(0)
30   })