]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - shared/extra-utils/server/config.ts
Add more attributes to about page
[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 codeOfConduct: 'my super coc',
57
58 moderationInformation: 'my super moderation information',
59 administrator: 'Kuja',
60 maintenanceLifetime: 'forever',
61 businessModel: 'my super business model',
62
63 languages: [ 'en', 'es' ],
64 categories: [ 1, 2 ],
65
66 defaultClientRoute: '/videos/recently-added',
67 isNSFW: true,
68 defaultNSFWPolicy: 'blur',
69 customizations: {
70 javascript: 'alert("coucou")',
71 css: 'body { background-color: red; }'
72 }
73 },
74 theme: {
75 default: 'default'
76 },
77 services: {
78 twitter: {
79 username: '@MySuperUsername',
80 whitelisted: true
81 }
82 },
83 cache: {
84 previews: {
85 size: 2
86 },
87 captions: {
88 size: 3
89 }
90 },
91 signup: {
92 enabled: false,
93 limit: 5,
94 requiresEmailVerification: false
95 },
96 admin: {
97 email: 'superadmin1@example.com'
98 },
99 contactForm: {
100 enabled: true
101 },
102 user: {
103 videoQuota: 5242881,
104 videoQuotaDaily: 318742
105 },
106 transcoding: {
107 enabled: true,
108 allowAdditionalExtensions: true,
109 allowAudioFiles: true,
110 threads: 1,
111 resolutions: {
112 '240p': false,
113 '360p': true,
114 '480p': true,
115 '720p': false,
116 '1080p': false,
117 '2160p': false
118 },
119 hls: {
120 enabled: false
121 }
122 },
123 import: {
124 videos: {
125 http: {
126 enabled: false
127 },
128 torrent: {
129 enabled: false
130 }
131 }
132 },
133 autoBlacklist: {
134 videos: {
135 ofUsers: {
136 enabled: false
137 }
138 }
139 },
140 followers: {
141 instance: {
142 enabled: true,
143 manualApproval: false
144 }
145 },
146 followings: {
147 instance: {
148 autoFollowBack: {
149 enabled: false
150 },
151 autoFollowIndex: {
152 indexUrl: 'https://instances.joinpeertube.org',
153 enabled: false
154 }
155 }
156 }
157 }
158
159 merge(updateParams, newConfig)
160
161 return updateCustomConfig(url, token, updateParams)
162 }
163
164 function deleteCustomConfig (url: string, token: string, statusCodeExpected = 200) {
165 const path = '/api/v1/config/custom'
166
167 return makeDeleteRequest({
168 url,
169 token,
170 path,
171 statusCodeExpected
172 })
173 }
174
175 // ---------------------------------------------------------------------------
176
177 export {
178 getConfig,
179 getCustomConfig,
180 updateCustomConfig,
181 getAbout,
182 deleteCustomConfig,
183 updateCustomSubConfig
184 }