]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - shared/extra-utils/users/user-subscriptions.ts
Fix player height on mobile
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / users / user-subscriptions.ts
1 import { makeDeleteRequest, makeGetRequest, makePostBodyRequest } from '../requests/requests'
2
3 function 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
15 function 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
23 const path = '/api/v1/users/me/subscriptions'
24
25 return makeGetRequest({
26 url,
27 path,
28 token,
29 statusCodeExpected,
30 query: {
31 sort,
32 search
33 }
34 })
35 }
36
37 function 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
49 function 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
60 function 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
71 function 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
83 // ---------------------------------------------------------------------------
84
85 export {
86 areSubscriptionsExist,
87 addUserSubscription,
88 listUserSubscriptions,
89 getUserSubscription,
90 listUserSubscriptionVideos,
91 removeUserSubscription
92 }