]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - shared/extra-utils/server/config.ts
Add auto follow back support for instances
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / server / config.ts
1 import { makeDeleteRequest, makeGetRequest, makePutBodyRequest } from '../requests/requests'
2 import { CustomConfig } from '../../models/server/custom-config.model'
3 import { DeepPartial } from '@server/typings/utils'
4 import { merge } from 'lodash'
5
6 function getConfig (url: string) {
7 const path = '/api/v1/config'
8
9 return makeGetRequest({
10 url,
11 path,
12 statusCodeExpected: 200
13 })
14 }
15
16 function getAbout (url: string) {
17 const path = '/api/v1/config/about'
18
19 return makeGetRequest({
20 url,
21 path,
22 statusCodeExpected: 200
23 })
24 }
25
26 function getCustomConfig (url: string, token: string, statusCodeExpected = 200) {
27 const path = '/api/v1/config/custom'
28
29 return makeGetRequest({
30 url,
31 token,
32 path,
33 statusCodeExpected
34 })
35 }
36
37 function updateCustomConfig (url: string, token: string, newCustomConfig: CustomConfig, statusCodeExpected = 200) {
38 const path = '/api/v1/config/custom'
39
40 return makePutBodyRequest({
41 url,
42 token,
43 path,
44 fields: newCustomConfig,
45 statusCodeExpected
46 })
47 }
48
49 function updateCustomSubConfig (url: string, token: string, newConfig: DeepPartial<CustomConfig>) {
50 const updateParams: CustomConfig = {
51 instance: {
52 name: 'PeerTube updated',
53 shortDescription: 'my short description',
54 description: 'my super description',
55 terms: 'my super terms',
56 defaultClientRoute: '/videos/recently-added',
57 isNSFW: true,
58 defaultNSFWPolicy: 'blur',
59 customizations: {
60 javascript: 'alert("coucou")',
61 css: 'body { background-color: red; }'
62 }
63 },
64 theme: {
65 default: 'default'
66 },
67 services: {
68 twitter: {
69 username: '@MySuperUsername',
70 whitelisted: true
71 }
72 },
73 cache: {
74 previews: {
75 size: 2
76 },
77 captions: {
78 size: 3
79 }
80 },
81 signup: {
82 enabled: false,
83 limit: 5,
84 requiresEmailVerification: false
85 },
86 admin: {
87 email: 'superadmin1@example.com'
88 },
89 contactForm: {
90 enabled: true
91 },
92 user: {
93 videoQuota: 5242881,
94 videoQuotaDaily: 318742
95 },
96 transcoding: {
97 enabled: true,
98 allowAdditionalExtensions: true,
99 allowAudioFiles: true,
100 threads: 1,
101 resolutions: {
102 '240p': false,
103 '360p': true,
104 '480p': true,
105 '720p': false,
106 '1080p': false,
107 '2160p': false
108 },
109 hls: {
110 enabled: false
111 }
112 },
113 import: {
114 videos: {
115 http: {
116 enabled: false
117 },
118 torrent: {
119 enabled: false
120 }
121 }
122 },
123 autoBlacklist: {
124 videos: {
125 ofUsers: {
126 enabled: false
127 }
128 }
129 },
130 followers: {
131 instance: {
132 enabled: true,
133 manualApproval: false
134 }
135 },
136 followings: {
137 instance: {
138 autoFollowBack: {
139 enabled: false
140 },
141 autoFollowIndex: {
142 indexUrl: 'https://instances.joinpeertube.org',
143 enabled: false
144 }
145 }
146 }
147 }
148
149 merge(updateParams, newConfig)
150
151 return updateCustomConfig(url, token, updateParams)
152 }
153
154 function deleteCustomConfig (url: string, token: string, statusCodeExpected = 200) {
155 const path = '/api/v1/config/custom'
156
157 return makeDeleteRequest({
158 url,
159 token,
160 path,
161 statusCodeExpected
162 })
163 }
164
165 // ---------------------------------------------------------------------------
166
167 export {
168 getConfig,
169 getCustomConfig,
170 updateCustomConfig,
171 getAbout,
172 deleteCustomConfig,
173 updateCustomSubConfig
174 }