]>
Commit | Line | Data |
---|---|---|
c55e3d72 | 1 | import { Account, AccountVideoRate, ActorFollow, HttpStatusCode, ResultList, VideoRateType } from '@shared/models' |
9fff08cf C |
2 | import { AbstractCommand, OverrideCommandOptions } from '../shared' |
3 | ||
4 | export class AccountsCommand extends AbstractCommand { | |
5 | ||
6 | list (options: OverrideCommandOptions & { | |
7 | sort?: string // default -createdAt | |
8 | } = {}) { | |
9 | const { sort = '-createdAt' } = options | |
10 | const path = '/api/v1/accounts' | |
11 | ||
12 | return this.getRequestBody<ResultList<Account>>({ | |
13 | ...options, | |
14 | ||
15 | path, | |
16 | query: { sort }, | |
a1637fa1 | 17 | implicitToken: false, |
9fff08cf C |
18 | defaultExpectedStatus: HttpStatusCode.OK_200 |
19 | }) | |
20 | } | |
21 | ||
22 | get (options: OverrideCommandOptions & { | |
23 | accountName: string | |
24 | }) { | |
25 | const path = '/api/v1/accounts/' + options.accountName | |
26 | ||
27 | return this.getRequestBody<Account>({ | |
28 | ...options, | |
29 | ||
30 | path, | |
a1637fa1 | 31 | implicitToken: false, |
9fff08cf C |
32 | defaultExpectedStatus: HttpStatusCode.OK_200 |
33 | }) | |
34 | } | |
35 | ||
36 | listRatings (options: OverrideCommandOptions & { | |
37 | accountName: string | |
38 | rating?: VideoRateType | |
39 | }) { | |
40 | const { rating, accountName } = options | |
41 | const path = '/api/v1/accounts/' + accountName + '/ratings' | |
42 | ||
43 | const query = { rating } | |
44 | ||
45 | return this.getRequestBody<ResultList<AccountVideoRate>>({ | |
46 | ...options, | |
47 | ||
48 | path, | |
49 | query, | |
a1637fa1 | 50 | implicitToken: true, |
9fff08cf C |
51 | defaultExpectedStatus: HttpStatusCode.OK_200 |
52 | }) | |
53 | } | |
4beda9e1 C |
54 | |
55 | listFollowers (options: OverrideCommandOptions & { | |
56 | accountName: string | |
57 | start?: number | |
58 | count?: number | |
59 | sort?: string | |
60 | search?: string | |
61 | }) { | |
62 | const { accountName, start, count, sort, search } = options | |
63 | const path = '/api/v1/accounts/' + accountName + '/followers' | |
64 | ||
65 | const query = { start, count, sort, search } | |
66 | ||
67 | return this.getRequestBody<ResultList<ActorFollow>>({ | |
68 | ...options, | |
69 | ||
70 | path, | |
71 | query, | |
72 | implicitToken: true, | |
73 | defaultExpectedStatus: HttpStatusCode.OK_200 | |
74 | }) | |
75 | } | |
9fff08cf | 76 | } |