diff options
author | Chocobozzz <me@florianbigard.com> | 2019-02-06 12:26:58 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-02-06 12:26:58 +0100 |
commit | 73471b1a52f242e86364ffb077ea6cadb3b07ae2 (patch) | |
tree | 43dbb7748e281f8d80f15326f489cdea10ec857d /shared/utils/server/config.ts | |
parent | c22419dd265c0c7185bf4197a1cb286eb3d8ebc0 (diff) | |
parent | f5305c04aae14467d6f957b713c5a902275cbb89 (diff) | |
download | PeerTube-73471b1a52f242e86364ffb077ea6cadb3b07ae2.tar.gz PeerTube-73471b1a52f242e86364ffb077ea6cadb3b07ae2.tar.zst PeerTube-73471b1a52f242e86364ffb077ea6cadb3b07ae2.zip |
Merge branch 'release/v1.2.0'
Diffstat (limited to 'shared/utils/server/config.ts')
-rw-r--r-- | shared/utils/server/config.ts | 139 |
1 files changed, 139 insertions, 0 deletions
diff --git a/shared/utils/server/config.ts b/shared/utils/server/config.ts new file mode 100644 index 000000000..0c5512bab --- /dev/null +++ b/shared/utils/server/config.ts | |||
@@ -0,0 +1,139 @@ | |||
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 | contactForm: { | ||
84 | enabled: true | ||
85 | }, | ||
86 | user: { | ||
87 | videoQuota: 5242881, | ||
88 | videoQuotaDaily: 318742 | ||
89 | }, | ||
90 | transcoding: { | ||
91 | enabled: true, | ||
92 | allowAdditionalExtensions: true, | ||
93 | threads: 1, | ||
94 | resolutions: { | ||
95 | '240p': false, | ||
96 | '360p': true, | ||
97 | '480p': true, | ||
98 | '720p': false, | ||
99 | '1080p': false | ||
100 | } | ||
101 | }, | ||
102 | import: { | ||
103 | videos: { | ||
104 | http: { | ||
105 | enabled: false | ||
106 | }, | ||
107 | torrent: { | ||
108 | enabled: false | ||
109 | } | ||
110 | } | ||
111 | } | ||
112 | } | ||
113 | |||
114 | Object.assign(updateParams, newConfig) | ||
115 | |||
116 | return updateCustomConfig(url, token, updateParams) | ||
117 | } | ||
118 | |||
119 | function deleteCustomConfig (url: string, token: string, statusCodeExpected = 200) { | ||
120 | const path = '/api/v1/config/custom' | ||
121 | |||
122 | return makeDeleteRequest({ | ||
123 | url, | ||
124 | token, | ||
125 | path, | ||
126 | statusCodeExpected | ||
127 | }) | ||
128 | } | ||
129 | |||
130 | // --------------------------------------------------------------------------- | ||
131 | |||
132 | export { | ||
133 | getConfig, | ||
134 | getCustomConfig, | ||
135 | updateCustomConfig, | ||
136 | getAbout, | ||
137 | deleteCustomConfig, | ||
138 | updateCustomSubConfig | ||
139 | } | ||