X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fserver%2Fserver-blocklist.ts;h=68cd72ee791c1dd3e6b575c3994569779d12589d;hb=ef680f68351ec10ab73a1131570a6d14ce14c195;hp=883ae47ab0c84e61d7d65299b3e1f386ba79d358;hpb=7cd1b12c19d0589d1d692ed0571ca0800f028aea;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/server/server-blocklist.ts b/server/models/server/server-blocklist.ts index 883ae47ab..68cd72ee7 100644 --- a/server/models/server/server-blocklist.ts +++ b/server/models/server/server-blocklist.ts @@ -1,11 +1,11 @@ +import * as Bluebird from 'bluebird' +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 { ServerBlock } from '@shared/models' import { AccountModel } from '../account/account' +import { getSort, searchAttribute } from '../utils' import { ServerModel } from './server' -import { ServerBlock } from '../../../shared/models/blocklist' -import { getSort } from '../utils' -import * as Bluebird from 'bluebird' -import { MServerBlocklist, MServerBlocklistAccountServer, MServerBlocklistFormattable } from '@server/typings/models' -import { Op } from 'sequelize' enum ScopeNames { WITH_ACCOUNT = 'WITH_ACCOUNT', @@ -120,13 +120,43 @@ export class ServerBlocklistModel extends Model { return ServerBlocklistModel.findOne(query) } - static listForApi (accountId: number, start: number, count: number, sort: string) { + static listHostsBlockedBy (accountIds: number[]): Bluebird { + 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 + sort: string + search?: string + accountId: number + }) { + const { start, count, sort, search, accountId } = parameters + const query = { offset: start, limit: count, order: getSort(sort), where: { - accountId + accountId, + ...searchAttribute(search, '$BlockedServer.host$') } }