diff options
Diffstat (limited to 'packages/server-commands/src/users/accounts-command.ts')
-rw-r--r-- | packages/server-commands/src/users/accounts-command.ts | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/packages/server-commands/src/users/accounts-command.ts b/packages/server-commands/src/users/accounts-command.ts new file mode 100644 index 000000000..fd98b7eea --- /dev/null +++ b/packages/server-commands/src/users/accounts-command.ts | |||
@@ -0,0 +1,76 @@ | |||
1 | import { Account, AccountVideoRate, ActorFollow, HttpStatusCode, ResultList, VideoRateType } from '@peertube/peertube-models' | ||
2 | import { AbstractCommand, OverrideCommandOptions } from '../shared/index.js' | ||
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 }, | ||
17 | implicitToken: false, | ||
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, | ||
31 | implicitToken: false, | ||
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, | ||
50 | implicitToken: true, | ||
51 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
52 | }) | ||
53 | } | ||
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 | } | ||
76 | } | ||