X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=scripts%2Fupdate-host.ts;h=759443623ef74950c8cdfcb65cc9eb5b5422b6f8;hb=3daf400219fe8cc94025886ba14876bc59a45244;hp=23e8d5ef35ca7234ba723b044885be4cfa551e13;hpb=6fcd19ba737f1f5614a56c6925adb882dea43b8d;p=github%2FChocobozzz%2FPeerTube.git diff --git a/scripts/update-host.ts b/scripts/update-host.ts index 23e8d5ef3..759443623 100755 --- a/scripts/update-host.ts +++ b/scripts/update-host.ts @@ -1,17 +1,19 @@ -import { readFileSync, writeFileSync } from 'fs' -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(res => { + return res.total > 0 }) - .then(itHasFriends => { - if (itHasFriends === true) { - console.log('Cannot update host because you have friends!') + .then(hasFollowing => { + if (hasFollowing === true) { + console.log('Cannot update host because you follow other servers!') process.exit(-1) } @@ -19,18 +21,18 @@ db.init(true) return db.Video.list() }) .then(videos => { - videos.forEach(function (video) { - const torrentName = video.id + '.torrent' - const torrentPath = CONFIG.STORAGE.TORRENTS_DIR + torrentName - const filename = video.id + video.extname + const tasks: Promise[] = [] - const parsed = parseTorrent(readFileSync(torrentPath)) - parsed.announce = [ CONFIG.WEBSERVER.WS + '://' + CONFIG.WEBSERVER.HOST + '/tracker/socket' ] - parsed.urlList = [ CONFIG.WEBSERVER.URL + STATIC_PATHS.WEBSEED + filename ] + videos.forEach(video => { + console.log('Updating video ' + video.uuid) - const buf = parseTorrent.toTorrentFile(parsed) - writeFileSync(torrentPath, buf) + video.VideoFiles.forEach(file => { + tasks.push(video.createTorrentAndSetInfoHash(file)) + }) }) + return Promise.all(tasks) + }) + .then(() => { process.exit(0) })