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