diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-08 13:56:04 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-20 15:27:18 +0200 |
commit | 72cbfc5695ec5ebdb9721d3648218f63feeaeac5 (patch) | |
tree | 945fd16dc2b19537ecbfd0e3b654c9a375993563 /shared/extra-utils/videos/change-ownership-command.ts | |
parent | 44364d06d7434e7e01c5bb383a27e6c3bd8a0f13 (diff) | |
download | PeerTube-72cbfc5695ec5ebdb9721d3648218f63feeaeac5.tar.gz PeerTube-72cbfc5695ec5ebdb9721d3648218f63feeaeac5.tar.zst PeerTube-72cbfc5695ec5ebdb9721d3648218f63feeaeac5.zip |
Introduce change ownership command
Diffstat (limited to 'shared/extra-utils/videos/change-ownership-command.ts')
-rw-r--r-- | shared/extra-utils/videos/change-ownership-command.ts | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/shared/extra-utils/videos/change-ownership-command.ts b/shared/extra-utils/videos/change-ownership-command.ts new file mode 100644 index 000000000..03f77a95f --- /dev/null +++ b/shared/extra-utils/videos/change-ownership-command.ts | |||
@@ -0,0 +1,69 @@ | |||
1 | |||
2 | import { ResultList, VideoChangeOwnership } from '@shared/models' | ||
3 | import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' | ||
4 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
5 | |||
6 | export class ChangeOwnershipCommand extends AbstractCommand { | ||
7 | |||
8 | create (options: OverrideCommandOptions & { | ||
9 | videoId: number | string | ||
10 | username: string | ||
11 | }) { | ||
12 | const { videoId, username } = options | ||
13 | const path = '/api/v1/videos/' + videoId + '/give-ownership' | ||
14 | |||
15 | return this.postBodyRequest({ | ||
16 | ...options, | ||
17 | |||
18 | path, | ||
19 | fields: { username }, | ||
20 | implicitToken: true, | ||
21 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
22 | }) | ||
23 | } | ||
24 | |||
25 | list (options: OverrideCommandOptions = {}) { | ||
26 | const path = '/api/v1/videos/ownership' | ||
27 | |||
28 | return this.getRequestBody<ResultList<VideoChangeOwnership>>({ | ||
29 | ...options, | ||
30 | |||
31 | path, | ||
32 | query: { sort: '-createdAt' }, | ||
33 | implicitToken: true, | ||
34 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
35 | }) | ||
36 | } | ||
37 | |||
38 | accept (options: OverrideCommandOptions & { | ||
39 | ownershipId: number | ||
40 | channelId: number | ||
41 | }) { | ||
42 | const { ownershipId, channelId } = options | ||
43 | const path = '/api/v1/videos/ownership/' + ownershipId + '/accept' | ||
44 | |||
45 | return this.postBodyRequest({ | ||
46 | ...options, | ||
47 | |||
48 | path, | ||
49 | fields: { channelId }, | ||
50 | implicitToken: true, | ||
51 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
52 | }) | ||
53 | } | ||
54 | |||
55 | refuse (options: OverrideCommandOptions & { | ||
56 | ownershipId: number | ||
57 | }) { | ||
58 | const { ownershipId } = options | ||
59 | const path = '/api/v1/videos/ownership/' + ownershipId + '/refuse' | ||
60 | |||
61 | return this.postBodyRequest({ | ||
62 | ...options, | ||
63 | |||
64 | path, | ||
65 | implicitToken: true, | ||
66 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
67 | }) | ||
68 | } | ||
69 | } | ||