X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=scripts%2Fupdate-host.ts;h=3fb5f1972dd85b6491fed4d9979533743dbeefe7;hb=2b3b76abb0c363d85ff5c831afd541a9c6982e76;hp=7c46dc52b17d0f3a6a76864262680fea6c6e6605;hpb=571389d43b8fc8aaf27e77c06f19b320b08dbbc9;p=github%2FChocobozzz%2FPeerTube.git diff --git a/scripts/update-host.ts b/scripts/update-host.ts index 7c46dc52b..3fb5f1972 100755 --- a/scripts/update-host.ts +++ b/scripts/update-host.ts @@ -1,20 +1,26 @@ -import { database as db } from '../server/initializers/database' -// import { hasFriends } from '../server/lib/friends' +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' -db.init(true) +initDatabaseModels(true) .then(() => { - // FIXME: check if has followers - // return hasFriends() - return true + return getServerActor() }) - .then(itHasFriends => { - if (itHasFriends === true) { - console.log('Cannot update host because you have friends!') + .then(serverAccount => { + return ActorFollowModel.listAcceptedFollowingUrlsForApi([ serverAccount.id ], undefined) + }) + .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[] = []