diff options
author | Chocobozzz <me@florianbigard.com> | 2021-12-17 09:29:23 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-12-17 09:29:23 +0100 |
commit | bf54587a3e2ad9c2c186828f2a5682b91ee2cc00 (patch) | |
tree | 54b40aaf01bae210632473285c3c7571d51e4f89 /shared/server-commands/users/accounts-command.ts | |
parent | 6b5f72beda96d8b7e4d6329c4001827334de27dd (diff) | |
download | PeerTube-bf54587a3e2ad9c2c186828f2a5682b91ee2cc00.tar.gz PeerTube-bf54587a3e2ad9c2c186828f2a5682b91ee2cc00.tar.zst PeerTube-bf54587a3e2ad9c2c186828f2a5682b91ee2cc00.zip |
shared/ typescript types dir server-commands
Diffstat (limited to 'shared/server-commands/users/accounts-command.ts')
-rw-r--r-- | shared/server-commands/users/accounts-command.ts | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/shared/server-commands/users/accounts-command.ts b/shared/server-commands/users/accounts-command.ts new file mode 100644 index 000000000..98d9d5927 --- /dev/null +++ b/shared/server-commands/users/accounts-command.ts | |||
@@ -0,0 +1,78 @@ | |||
1 | import { HttpStatusCode, ResultList } from '@shared/models' | ||
2 | import { Account, ActorFollow } from '../../models/actors' | ||
3 | import { AccountVideoRate, VideoRateType } from '../../models/videos' | ||
4 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
5 | |||
6 | export class AccountsCommand extends AbstractCommand { | ||
7 | |||
8 | list (options: OverrideCommandOptions & { | ||
9 | sort?: string // default -createdAt | ||
10 | } = {}) { | ||
11 | const { sort = '-createdAt' } = options | ||
12 | const path = '/api/v1/accounts' | ||
13 | |||
14 | return this.getRequestBody<ResultList<Account>>({ | ||
15 | ...options, | ||
16 | |||
17 | path, | ||
18 | query: { sort }, | ||
19 | implicitToken: false, | ||
20 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
21 | }) | ||
22 | } | ||
23 | |||
24 | get (options: OverrideCommandOptions & { | ||
25 | accountName: string | ||
26 | }) { | ||
27 | const path = '/api/v1/accounts/' + options.accountName | ||
28 | |||
29 | return this.getRequestBody<Account>({ | ||
30 | ...options, | ||
31 | |||
32 | path, | ||
33 | implicitToken: false, | ||
34 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
35 | }) | ||
36 | } | ||
37 | |||
38 | listRatings (options: OverrideCommandOptions & { | ||
39 | accountName: string | ||
40 | rating?: VideoRateType | ||
41 | }) { | ||
42 | const { rating, accountName } = options | ||
43 | const path = '/api/v1/accounts/' + accountName + '/ratings' | ||
44 | |||
45 | const query = { rating } | ||
46 | |||
47 | return this.getRequestBody<ResultList<AccountVideoRate>>({ | ||
48 | ...options, | ||
49 | |||
50 | path, | ||
51 | query, | ||
52 | implicitToken: true, | ||
53 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
54 | }) | ||
55 | } | ||
56 | |||
57 | listFollowers (options: OverrideCommandOptions & { | ||
58 | accountName: string | ||
59 | start?: number | ||
60 | count?: number | ||
61 | sort?: string | ||
62 | search?: string | ||
63 | }) { | ||
64 | const { accountName, start, count, sort, search } = options | ||
65 | const path = '/api/v1/accounts/' + accountName + '/followers' | ||
66 | |||
67 | const query = { start, count, sort, search } | ||
68 | |||
69 | return this.getRequestBody<ResultList<ActorFollow>>({ | ||
70 | ...options, | ||
71 | |||
72 | path, | ||
73 | query, | ||
74 | implicitToken: true, | ||
75 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
76 | }) | ||
77 | } | ||
78 | } | ||