2021-07-07 16:02:46 +02:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
|
|
|
|
2021-12-06 16:53:00 +01:00
|
|
|
import { AccountBlock, BlockStatus, HttpStatusCode, ResultList, ServerBlock } from '@shared/models'
|
2021-07-07 16:02:46 +02:00
|
|
|
import { AbstractCommand, OverrideCommandOptions } from '../shared'
|
|
|
|
|
|
|
|
type ListBlocklistOptions = OverrideCommandOptions & {
|
|
|
|
start: number
|
|
|
|
count: number
|
2022-06-17 16:06:58 +02:00
|
|
|
|
|
|
|
sort?: string // default -createdAt
|
|
|
|
|
|
|
|
search?: string
|
2021-07-07 16:02:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export class BlocklistCommand extends AbstractCommand {
|
|
|
|
|
|
|
|
listMyAccountBlocklist (options: ListBlocklistOptions) {
|
|
|
|
const path = '/api/v1/users/me/blocklist/accounts'
|
|
|
|
|
|
|
|
return this.listBlocklist<AccountBlock>(options, path)
|
|
|
|
}
|
|
|
|
|
|
|
|
listMyServerBlocklist (options: ListBlocklistOptions) {
|
|
|
|
const path = '/api/v1/users/me/blocklist/servers'
|
|
|
|
|
|
|
|
return this.listBlocklist<ServerBlock>(options, path)
|
|
|
|
}
|
|
|
|
|
|
|
|
listServerAccountBlocklist (options: ListBlocklistOptions) {
|
|
|
|
const path = '/api/v1/server/blocklist/accounts'
|
|
|
|
|
|
|
|
return this.listBlocklist<AccountBlock>(options, path)
|
|
|
|
}
|
|
|
|
|
|
|
|
listServerServerBlocklist (options: ListBlocklistOptions) {
|
|
|
|
const path = '/api/v1/server/blocklist/servers'
|
|
|
|
|
|
|
|
return this.listBlocklist<ServerBlock>(options, path)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2021-12-06 16:53:00 +01:00
|
|
|
getStatus (options: OverrideCommandOptions & {
|
|
|
|
accounts?: string[]
|
|
|
|
hosts?: string[]
|
|
|
|
}) {
|
|
|
|
const { accounts, hosts } = options
|
|
|
|
|
|
|
|
const path = '/api/v1/blocklist/status'
|
|
|
|
|
|
|
|
return this.getRequestBody<BlockStatus>({
|
|
|
|
...options,
|
|
|
|
|
|
|
|
path,
|
|
|
|
query: {
|
|
|
|
accounts,
|
|
|
|
hosts
|
|
|
|
},
|
|
|
|
implicitToken: false,
|
|
|
|
defaultExpectedStatus: HttpStatusCode.OK_200
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2021-07-07 16:02:46 +02:00
|
|
|
addToMyBlocklist (options: OverrideCommandOptions & {
|
|
|
|
account?: string
|
|
|
|
server?: string
|
|
|
|
}) {
|
|
|
|
const { account, server } = options
|
|
|
|
|
|
|
|
const path = account
|
|
|
|
? '/api/v1/users/me/blocklist/accounts'
|
|
|
|
: '/api/v1/users/me/blocklist/servers'
|
|
|
|
|
|
|
|
return this.postBodyRequest({
|
|
|
|
...options,
|
|
|
|
|
|
|
|
path,
|
|
|
|
fields: {
|
|
|
|
accountName: account,
|
|
|
|
host: server
|
|
|
|
},
|
2021-07-08 10:55:16 +02:00
|
|
|
implicitToken: true,
|
2021-07-07 16:02:46 +02:00
|
|
|
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
addToServerBlocklist (options: OverrideCommandOptions & {
|
|
|
|
account?: string
|
|
|
|
server?: string
|
|
|
|
}) {
|
|
|
|
const { account, server } = options
|
|
|
|
|
|
|
|
const path = account
|
|
|
|
? '/api/v1/server/blocklist/accounts'
|
|
|
|
: '/api/v1/server/blocklist/servers'
|
|
|
|
|
|
|
|
return this.postBodyRequest({
|
|
|
|
...options,
|
|
|
|
|
|
|
|
path,
|
|
|
|
fields: {
|
|
|
|
accountName: account,
|
|
|
|
host: server
|
|
|
|
},
|
2021-07-08 10:55:16 +02:00
|
|
|
implicitToken: true,
|
2021-07-07 16:02:46 +02:00
|
|
|
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
removeFromMyBlocklist (options: OverrideCommandOptions & {
|
|
|
|
account?: string
|
|
|
|
server?: string
|
|
|
|
}) {
|
|
|
|
const { account, server } = options
|
|
|
|
|
|
|
|
const path = account
|
|
|
|
? '/api/v1/users/me/blocklist/accounts/' + account
|
|
|
|
: '/api/v1/users/me/blocklist/servers/' + server
|
|
|
|
|
|
|
|
return this.deleteRequest({
|
|
|
|
...options,
|
|
|
|
|
|
|
|
path,
|
2021-07-08 10:55:16 +02:00
|
|
|
implicitToken: true,
|
2021-07-07 16:02:46 +02:00
|
|
|
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
removeFromServerBlocklist (options: OverrideCommandOptions & {
|
|
|
|
account?: string
|
|
|
|
server?: string
|
|
|
|
}) {
|
|
|
|
const { account, server } = options
|
|
|
|
|
|
|
|
const path = account
|
|
|
|
? '/api/v1/server/blocklist/accounts/' + account
|
|
|
|
: '/api/v1/server/blocklist/servers/' + server
|
|
|
|
|
|
|
|
return this.deleteRequest({
|
|
|
|
...options,
|
|
|
|
|
|
|
|
path,
|
2021-07-08 10:55:16 +02:00
|
|
|
implicitToken: true,
|
2021-07-07 16:02:46 +02:00
|
|
|
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
private listBlocklist <T> (options: ListBlocklistOptions, path: string) {
|
2022-06-17 16:06:58 +02:00
|
|
|
const { start, count, search, sort = '-createdAt' } = options
|
2021-07-07 16:02:46 +02:00
|
|
|
|
|
|
|
return this.getRequestBody<ResultList<T>>({
|
|
|
|
...options,
|
|
|
|
|
|
|
|
path,
|
2022-06-17 16:06:58 +02:00
|
|
|
query: { start, count, sort, search },
|
2021-07-08 10:55:16 +02:00
|
|
|
implicitToken: true,
|
2021-07-07 16:02:46 +02:00
|
|
|
defaultExpectedStatus: HttpStatusCode.OK_200
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|