Fix update host script
authorChocobozzz <florian.bigard@gmail.com>
Fri, 17 Nov 2017 15:24:08 +0000 (16:24 +0100)
committerChocobozzz <florian.bigard@gmail.com>
Mon, 27 Nov 2017 18:40:52 +0000 (19:40 +0100)
scripts/update-host.ts

index 05f0ef96d5e67003eef1106d639f71ed7719e6da..4410e1ff7e67110fad1830c6a7526bb7f320c1a8 100755 (executable)
@@ -1,15 +1,19 @@
 import { database as db } from '../server/initializers/database'
-// import { hasFriends } from '../server/lib/friends'
+import { getServerAccount } from '../server/helpers/utils'
 
 db.init(true)
   .then(() => {
-    // FIXME: check if has following
-    // return hasFriends()
-    return true
+    return getServerAccount()
   })
-  .then(itHasFriends => {
-    if (itHasFriends === true) {
-      console.log('Cannot update host because you have friends!')
+  .then(serverAccount => {
+    return db.AccountFollow.listAcceptedFollowingUrlsForApi([ serverAccount.id ])
+  })
+  .then(res => {
+    return res.total > 0
+  })
+  .then(hasFollowing => {
+    if (hasFollowing === true) {
+      console.log('Cannot update host because you follow other servers!')
       process.exit(-1)
     }