mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 19:42:24 +02:00
shared/ typescript types dir server-commands
This commit is contained in:
parent
6b5f72beda
commit
bf54587a3e
242 changed files with 228 additions and 172 deletions
162
shared/server-commands/users/blocklist-command.ts
Normal file
162
shared/server-commands/users/blocklist-command.ts
Normal file
|
@ -0,0 +1,162 @@
|
|||
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
||||
|
||||
import { AccountBlock, BlockStatus, HttpStatusCode, ResultList, ServerBlock } from '@shared/models'
|
||||
import { AbstractCommand, OverrideCommandOptions } from '../shared'
|
||||
|
||||
type ListBlocklistOptions = OverrideCommandOptions & {
|
||||
start: number
|
||||
count: number
|
||||
sort: string // default -createdAt
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
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
|
||||
})
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
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
|
||||
},
|
||||
implicitToken: true,
|
||||
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
|
||||
},
|
||||
implicitToken: true,
|
||||
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,
|
||||
implicitToken: true,
|
||||
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,
|
||||
implicitToken: true,
|
||||
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
|
||||
})
|
||||
}
|
||||
|
||||
private listBlocklist <T> (options: ListBlocklistOptions, path: string) {
|
||||
const { start, count, sort = '-createdAt' } = options
|
||||
|
||||
return this.getRequestBody<ResultList<T>>({
|
||||
...options,
|
||||
|
||||
path,
|
||||
query: { start, count, sort },
|
||||
implicitToken: true,
|
||||
defaultExpectedStatus: HttpStatusCode.OK_200
|
||||
})
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue