]>
Commit | Line | Data |
---|---|---|
d175a6f7 | 1 | import { makeDeleteRequest, makeGetRequest, makePostBodyRequest } from '../requests/requests' |
2d53be02 | 2 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' |
06a05d5f | 3 | |
2d53be02 | 4 | function addUserSubscription (url: string, token: string, targetUri: string, statusCodeExpected = HttpStatusCode.NO_CONTENT_204) { |
06a05d5f C |
5 | const path = '/api/v1/users/me/subscriptions' |
6 | ||
7 | return makePostBodyRequest({ | |
8 | url, | |
9 | path, | |
10 | token, | |
11 | statusCodeExpected, | |
12 | fields: { uri: targetUri } | |
13 | }) | |
14 | } | |
15 | ||
7b390964 RK |
16 | function listUserSubscriptions (parameters: { |
17 | url: string | |
18 | token: string | |
19 | sort?: string | |
20 | search?: string | |
21 | statusCodeExpected?: number | |
22 | }) { | |
2d53be02 | 23 | const { url, token, sort = '-createdAt', search, statusCodeExpected = HttpStatusCode.OK_200 } = parameters |
06a05d5f C |
24 | const path = '/api/v1/users/me/subscriptions' |
25 | ||
26 | return makeGetRequest({ | |
27 | url, | |
28 | path, | |
29 | token, | |
30 | statusCodeExpected, | |
7b390964 RK |
31 | query: { |
32 | sort, | |
33 | search | |
34 | } | |
06a05d5f C |
35 | }) |
36 | } | |
37 | ||
2d53be02 | 38 | function listUserSubscriptionVideos (url: string, token: string, sort = '-createdAt', statusCodeExpected = HttpStatusCode.OK_200) { |
06a05d5f C |
39 | const path = '/api/v1/users/me/subscriptions/videos' |
40 | ||
41 | return makeGetRequest({ | |
42 | url, | |
43 | path, | |
44 | token, | |
45 | statusCodeExpected, | |
46 | query: { sort } | |
47 | }) | |
48 | } | |
49 | ||
2d53be02 | 50 | function getUserSubscription (url: string, token: string, uri: string, statusCodeExpected = HttpStatusCode.OK_200) { |
99492dbc C |
51 | const path = '/api/v1/users/me/subscriptions/' + uri |
52 | ||
53 | return makeGetRequest({ | |
54 | url, | |
55 | path, | |
56 | token, | |
57 | statusCodeExpected | |
58 | }) | |
59 | } | |
60 | ||
2d53be02 | 61 | function removeUserSubscription (url: string, token: string, uri: string, statusCodeExpected = HttpStatusCode.NO_CONTENT_204) { |
06a05d5f C |
62 | const path = '/api/v1/users/me/subscriptions/' + uri |
63 | ||
64 | return makeDeleteRequest({ | |
65 | url, | |
66 | path, | |
67 | token, | |
68 | statusCodeExpected | |
69 | }) | |
70 | } | |
71 | ||
2d53be02 | 72 | function areSubscriptionsExist (url: string, token: string, uris: string[], statusCodeExpected = HttpStatusCode.OK_200) { |
f37dc0dd C |
73 | const path = '/api/v1/users/me/subscriptions/exist' |
74 | ||
75 | return makeGetRequest({ | |
76 | url, | |
77 | path, | |
78 | query: { 'uris[]': uris }, | |
79 | token, | |
80 | statusCodeExpected | |
81 | }) | |
82 | } | |
83 | ||
06a05d5f C |
84 | // --------------------------------------------------------------------------- |
85 | ||
86 | export { | |
f37dc0dd | 87 | areSubscriptionsExist, |
06a05d5f C |
88 | addUserSubscription, |
89 | listUserSubscriptions, | |
99492dbc | 90 | getUserSubscription, |
06a05d5f C |
91 | listUserSubscriptionVideos, |
92 | removeUserSubscription | |
93 | } |