diff options
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 | } | ||