X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=sidebyside;f=scripts%2Fupdate-host.ts;h=3fb5f1972dd85b6491fed4d9979533743dbeefe7;hb=5e1c08eb94746c44b8b14a12c0937aadb34feb57;hp=5e69e4172bd9629b537605abce809b8f602ee026;hpb=93e1258c7cbc0d1235ca6d2a1f7c1875985328b8;p=github%2FChocobozzz%2FPeerTube.git diff --git a/scripts/update-host.ts b/scripts/update-host.ts index 5e69e4172..3fb5f1972 100755 --- a/scripts/update-host.ts +++ b/scripts/update-host.ts @@ -1,30 +1,40 @@ -import { readFileSync, writeFileSync } from 'fs' -import { join } from 'path' -import * as parseTorrent from 'parse-torrent' +import { getServerActor } from '../server/helpers/utils' +import { initDatabaseModels } from '../server/initializers' +import { ActorFollowModel } from '../server/models/activitypub/actor-follow' +import { VideoModel } from '../server/models/video/video' -import { CONFIG, STATIC_PATHS } from '../server/initializers/constants' -import { database as db } from '../server/initializers/database' -import { hasFriends } from '../server/lib/friends' - -db.init(true) +initDatabaseModels(true) .then(() => { - return hasFriends() + return getServerActor() + }) + .then(serverAccount => { + return ActorFollowModel.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) } console.log('Updating torrent files.') - return db.Video.list() + return VideoModel.list() }) .then(videos => { + const tasks: Promise[] = [] + 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) })