X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=sidebyside;f=server%2Fmodels%2Fserver%2Fserver-blocklist.ts;h=092998db33c6682ee1cbe0bdf17c0e18f4ad1b20;hb=636d73c58866ed235c207719e41fdde3c2d6c969;hp=ad8e3d1e88e30694cac7185fba19fc525a20cd2c;hpb=5fb2e2888ce032c638e4b75d07458642f0833e52;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/server/server-blocklist.ts b/server/models/server/server-blocklist.ts index ad8e3d1e8..092998db3 100644 --- a/server/models/server/server-blocklist.ts +++ b/server/models/server/server-blocklist.ts @@ -1,11 +1,11 @@ +import { Op, QueryTypes } 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 { createSafeIn, getSort, searchAttribute } from '../utils' 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' enum ScopeNames { WITH_ACCOUNT = 'WITH_ACCOUNT', @@ -43,7 +43,7 @@ enum ScopeNames { } ] }) -export class ServerBlocklistModel extends Model { +export class ServerBlocklistModel extends Model>> { @CreatedAt createdAt: Date @@ -76,7 +76,7 @@ export class ServerBlocklistModel extends Model { }) BlockedServer: ServerModel - static isServerMutedByMulti (accountIds: number[], targetServerId: number) { + static isServerMutedByAccounts (accountIds: number[], targetServerId: number) { const query = { attributes: [ 'accountId', 'id' ], where: { @@ -101,7 +101,7 @@ export class ServerBlocklistModel extends Model { }) } - static loadByAccountAndHost (accountId: number, host: string): Bluebird { + static loadByAccountAndHost (accountId: number, host: string): Promise { const query = { where: { accountId @@ -120,7 +120,7 @@ export class ServerBlocklistModel extends Model { return ServerBlocklistModel.findOne(query) } - static listHostsBlockedBy (accountIds: number[]): Bluebird { + static listHostsBlockedBy (accountIds: number[]): Promise { const query = { attributes: [ ], where: { @@ -141,6 +141,19 @@ export class ServerBlocklistModel extends Model { .then(entries => entries.map(e => e.BlockedServer.host)) } + static getBlockStatus (byAccountIds: number[], hosts: string[]): Promise<{ host: string, accountId: number }[]> { + const rawQuery = `SELECT "server"."host", "serverBlocklist"."accountId" ` + + `FROM "serverBlocklist" ` + + `INNER JOIN "server" ON "server"."id" = "serverBlocklist"."targetServerId" ` + + `WHERE "server"."host" IN (:hosts) ` + + `AND "serverBlocklist"."accountId" IN (${createSafeIn(ServerBlocklistModel.sequelize, byAccountIds)})` + + return ServerBlocklistModel.sequelize.query(rawQuery, { + type: QueryTypes.SELECT as QueryTypes.SELECT, + replacements: { hosts } + }) + } + static listForApi (parameters: { start: number count: number