]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - shared/utils/server/config.ts
Support additional video extensions
[github/Chocobozzz/PeerTube.git] / shared / utils / server / config.ts
1 import { makeDeleteRequest, makeGetRequest, makePutBodyRequest } from '../requests/requests'
2 import { CustomConfig } from '../../models/server/custom-config.model'
3
4 function getConfig (url: string) {
5 const path = '/api/v1/config'
6
7 return makeGetRequest({
8 url,
9 path,
10 statusCodeExpected: 200
11 })
12 }
13
14 function getAbout (url: string) {
15 const path = '/api/v1/config/about'
16
17 return makeGetRequest({
18 url,
19 path,
20 statusCodeExpected: 200
21 })
22 }
23
24 function getCustomConfig (url: string, token: string, statusCodeExpected = 200) {
25 const path = '/api/v1/config/custom'
26
27 return makeGetRequest({
28 url,
29 token,
30 path,
31 statusCodeExpected
32 })
33 }
34
35 function updateCustomConfig (url: string, token: string, newCustomConfig: CustomConfig, statusCodeExpected = 200) {
36 const path = '/api/v1/config/custom'
37
38 return makePutBodyRequest({
39 url,
40 token,
41 path,
42 fields: newCustomConfig,
43 statusCodeExpected
44 })
45 }
46
47 function updateCustomSubConfig (url: string, token: string, newConfig: any) {
48 const updateParams: CustomConfig = {
49 instance: {
50 name: 'PeerTube updated',
51 shortDescription: 'my short description',
52 description: 'my super description',
53 terms: 'my super terms',
54 defaultClientRoute: '/videos/recently-added',
55 defaultNSFWPolicy: 'blur',
56 customizations: {
57 javascript: 'alert("coucou")',
58 css: 'body { background-color: red; }'
59 }
60 },
61 services: {
62 twitter: {
63 username: '@MySuperUsername',
64 whitelisted: true
65 }
66 },
67 cache: {
68 previews: {
69 size: 2
70 },
71 captions: {
72 size: 3
73 }
74 },
75 signup: {
76 enabled: false,
77 limit: 5,
78 requiresEmailVerification: false
79 },
80 admin: {
81 email: 'superadmin1@example.com'
82 },
83 user: {
84 videoQuota: 5242881,
85 videoQuotaDaily: 318742
86 },
87 transcoding: {
88 enabled: true,
89 allowAdditionalExtensions: true,
90 threads: 1,
91 resolutions: {
92 '240p': false,
93 '360p': true,
94 '480p': true,
95 '720p': false,
96 '1080p': false
97 }
98 },
99 import: {
100 videos: {
101 http: {
102 enabled: false
103 },
104 torrent: {
105 enabled: false
106 }
107 }
108 }
109 }
110
111 Object.assign(updateParams, newConfig)
112
113 return updateCustomConfig(url, token, updateParams)
114 }
115
116 function deleteCustomConfig (url: string, token: string, statusCodeExpected = 200) {
117 const path = '/api/v1/config/custom'
118
119 return makeDeleteRequest({
120 url,
121 token,
122 path,
123 statusCodeExpected
124 })
125 }
126
127 // ---------------------------------------------------------------------------
128
129 export {
130 getConfig,
131 getCustomConfig,
132 updateCustomConfig,
133 getAbout,
134 deleteCustomConfig,
135 updateCustomSubConfig
136 }