]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/server/server-blocklist.ts
Translated using Weblate (German)
[github/Chocobozzz/PeerTube.git] / server / models / server / server-blocklist.ts
index 892024c04a4e074d25739bd6adf8ee80d6c9b7ed..b3579d5896f41f1bf596436abb4a67e484d4d463 100644 (file)
@@ -1,11 +1,11 @@
+import { Op } from 'sequelize'
 import { BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript'
+import { MServerBlocklist, MServerBlocklistAccountServer, MServerBlocklistFormattable } from '@server/types/models'
+import { AttributesOnly } from '@shared/core-utils'
+import { ServerBlock } from '@shared/models'
 import { AccountModel } from '../account/account'
-import { ServerModel } from './server'
-import { ServerBlock } from '../../../shared/models/blocklist'
 import { getSort, searchAttribute } from '../utils'
-import * as Bluebird from 'bluebird'
-import { MServerBlocklist, MServerBlocklistAccountServer, MServerBlocklistFormattable } from '@server/typings/models'
-import { Op } from 'sequelize'
+import { ServerModel } from './server'
 
 enum ScopeNames {
   WITH_ACCOUNT = 'WITH_ACCOUNT',
@@ -43,7 +43,7 @@ enum ScopeNames {
     }
   ]
 })
-export class ServerBlocklistModel extends Model<ServerBlocklistModel> {
+export class ServerBlocklistModel extends Model<Partial<AttributesOnly<ServerBlocklistModel>>> {
 
   @CreatedAt
   createdAt: Date
@@ -101,7 +101,7 @@ export class ServerBlocklistModel extends Model<ServerBlocklistModel> {
                                 })
   }
 
-  static loadByAccountAndHost (accountId: number, host: string): Bluebird<MServerBlocklist> {
+  static loadByAccountAndHost (accountId: number, host: string): Promise<MServerBlocklist> {
     const query = {
       where: {
         accountId
@@ -120,6 +120,27 @@ export class ServerBlocklistModel extends Model<ServerBlocklistModel> {
     return ServerBlocklistModel.findOne(query)
   }
 
+  static listHostsBlockedBy (accountIds: number[]): Promise<string[]> {
+    const query = {
+      attributes: [ ],
+      where: {
+        accountId: {
+          [Op.in]: accountIds
+        }
+      },
+      include: [
+        {
+          attributes: [ 'host' ],
+          model: ServerModel.unscoped(),
+          required: true
+        }
+      ]
+    }
+
+    return ServerBlocklistModel.findAll(query)
+      .then(entries => entries.map(e => e.BlockedServer.host))
+  }
+
   static listForApi (parameters: {
     start: number
     count: number