]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - shared/extra-utils/shared/abstract-command.ts
Introduce bulk command
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / shared / abstract-command.ts
CommitLineData
a6a79eae
C
1import { HttpStatusCode } from '@shared/core-utils'
2import { makePostBodyRequest } from '../requests/requests'
3import { ServerInfo } from '../server/servers'
4
5export interface CommonCommandOptions {
6 token?: string
7 expectedStatus?: number
8}
9
10abstract class AbstractCommand {
11
12 private expectedStatus = HttpStatusCode.OK_200
13
14 constructor (
15 protected server: ServerInfo
16 ) {
17
18 }
19
20 setServer (server: ServerInfo) {
21 this.server = server
22 }
23
24 setExpectedStatus (status: HttpStatusCode) {
25 this.expectedStatus = status
26 }
27
28 protected postBodyRequest (options: CommonCommandOptions & {
29 path: string
30 defaultExpectedStatus: number
31 fields?: { [ fieldName: string ]: any }
32 }) {
33 const { token, fields, expectedStatus, defaultExpectedStatus, path } = options
34
35 return makePostBodyRequest({
36 url: this.server.url,
37 path,
38 token: token ?? this.server.accessToken,
39 fields,
40 statusCodeExpected: expectedStatus ?? this.expectedStatus ?? defaultExpectedStatus
41 })
42 }
43}
44
45export {
46 AbstractCommand
47}