diff options
author | Chocobozzz <me@florianbigard.com> | 2021-12-16 09:38:27 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-12-16 10:08:55 +0100 |
commit | b65de1be4dcf626c552be613d531d3f6e23c6085 (patch) | |
tree | 42c4d7440f9fadee6efb48ad39ccfe1a3bce8511 /server | |
parent | 9576506763c20c7efbdb229483440a1fc984cf4d (diff) | |
download | PeerTube-b65de1be4dcf626c552be613d531d3f6e23c6085.tar.gz PeerTube-b65de1be4dcf626c552be613d531d3f6e23c6085.tar.zst PeerTube-b65de1be4dcf626c552be613d531d3f6e23c6085.zip |
Use different p2p policy for embeds and webapp
Diffstat (limited to 'server')
-rw-r--r-- | server/controllers/api/users/index.ts | 4 | ||||
-rw-r--r-- | server/initializers/config.ts | 7 | ||||
-rw-r--r-- | server/initializers/installer.ts | 2 | ||||
-rw-r--r-- | server/lib/auth/oauth-model.ts | 2 | ||||
-rw-r--r-- | server/lib/server-config-manager.ts | 7 | ||||
-rw-r--r-- | server/tests/api/server/config-defaults.ts | 97 |
6 files changed, 90 insertions, 29 deletions
diff --git a/server/controllers/api/users/index.ts b/server/controllers/api/users/index.ts index f3b4508d9..fcee58f6b 100644 --- a/server/controllers/api/users/index.ts +++ b/server/controllers/api/users/index.ts | |||
@@ -183,7 +183,7 @@ async function createUser (req: express.Request, res: express.Response) { | |||
183 | password: body.password, | 183 | password: body.password, |
184 | email: body.email, | 184 | email: body.email, |
185 | nsfwPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY, | 185 | nsfwPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY, |
186 | p2pEnabled: CONFIG.DEFAULTS.P2P.ENABLED, | 186 | p2pEnabled: CONFIG.DEFAULTS.P2P.WEBAPP.ENABLED, |
187 | autoPlayVideo: true, | 187 | autoPlayVideo: true, |
188 | role: body.role, | 188 | role: body.role, |
189 | videoQuota: body.videoQuota, | 189 | videoQuota: body.videoQuota, |
@@ -233,7 +233,7 @@ async function registerUser (req: express.Request, res: express.Response) { | |||
233 | password: body.password, | 233 | password: body.password, |
234 | email: body.email, | 234 | email: body.email, |
235 | nsfwPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY, | 235 | nsfwPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY, |
236 | p2pEnabled: CONFIG.DEFAULTS.P2P.ENABLED, | 236 | p2pEnabled: CONFIG.DEFAULTS.P2P.WEBAPP.ENABLED, |
237 | autoPlayVideo: true, | 237 | autoPlayVideo: true, |
238 | role: UserRole.USER, | 238 | role: UserRole.USER, |
239 | videoQuota: CONFIG.USER.VIDEO_QUOTA, | 239 | videoQuota: CONFIG.USER.VIDEO_QUOTA, |
diff --git a/server/initializers/config.ts b/server/initializers/config.ts index a6ea6d888..f2e9f7088 100644 --- a/server/initializers/config.ts +++ b/server/initializers/config.ts | |||
@@ -80,7 +80,12 @@ const CONFIG = { | |||
80 | LICENCE: config.get<number>('defaults.publish.licence') | 80 | LICENCE: config.get<number>('defaults.publish.licence') |
81 | }, | 81 | }, |
82 | P2P: { | 82 | P2P: { |
83 | ENABLED: config.get<boolean>('defaults.p2p.enabled') | 83 | WEBAPP: { |
84 | ENABLED: config.get<boolean>('defaults.p2p.webapp.enabled') | ||
85 | }, | ||
86 | EMBED: { | ||
87 | ENABLED: config.get<boolean>('defaults.p2p.embed.enabled') | ||
88 | } | ||
84 | } | 89 | } |
85 | }, | 90 | }, |
86 | 91 | ||
diff --git a/server/initializers/installer.ts b/server/initializers/installer.ts index 19adaf177..7c29a42e1 100644 --- a/server/initializers/installer.ts +++ b/server/initializers/installer.ts | |||
@@ -144,7 +144,7 @@ async function createOAuthAdminIfNotExist () { | |||
144 | role, | 144 | role, |
145 | verified: true, | 145 | verified: true, |
146 | nsfwPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY, | 146 | nsfwPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY, |
147 | p2pEnabled: CONFIG.DEFAULTS.P2P.ENABLED, | 147 | p2pEnabled: CONFIG.DEFAULTS.P2P.WEBAPP.ENABLED, |
148 | videoQuota: -1, | 148 | videoQuota: -1, |
149 | videoQuotaDaily: -1 | 149 | videoQuotaDaily: -1 |
150 | } | 150 | } |
diff --git a/server/lib/auth/oauth-model.ts b/server/lib/auth/oauth-model.ts index 754bee36d..b68cce6d2 100644 --- a/server/lib/auth/oauth-model.ts +++ b/server/lib/auth/oauth-model.ts | |||
@@ -226,7 +226,7 @@ async function createUserFromExternal (pluginAuth: string, options: { | |||
226 | password: null, | 226 | password: null, |
227 | email: options.email, | 227 | email: options.email, |
228 | nsfwPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY, | 228 | nsfwPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY, |
229 | p2pEnabled: CONFIG.DEFAULTS.P2P.ENABLED, | 229 | p2pEnabled: CONFIG.DEFAULTS.P2P.WEBAPP.ENABLED, |
230 | autoPlayVideo: true, | 230 | autoPlayVideo: true, |
231 | role: options.role, | 231 | role: options.role, |
232 | videoQuota: CONFIG.USER.VIDEO_QUOTA, | 232 | videoQuota: CONFIG.USER.VIDEO_QUOTA, |
diff --git a/server/lib/server-config-manager.ts b/server/lib/server-config-manager.ts index d759f85e1..18032ef86 100644 --- a/server/lib/server-config-manager.ts +++ b/server/lib/server-config-manager.ts | |||
@@ -63,7 +63,12 @@ class ServerConfigManager { | |||
63 | licence: CONFIG.DEFAULTS.PUBLISH.LICENCE | 63 | licence: CONFIG.DEFAULTS.PUBLISH.LICENCE |
64 | }, | 64 | }, |
65 | p2p: { | 65 | p2p: { |
66 | enabled: CONFIG.DEFAULTS.P2P.ENABLED | 66 | webapp: { |
67 | enabled: CONFIG.DEFAULTS.P2P.WEBAPP.ENABLED | ||
68 | }, | ||
69 | embed: { | ||
70 | enabled: CONFIG.DEFAULTS.P2P.EMBED.ENABLED | ||
71 | } | ||
67 | } | 72 | } |
68 | }, | 73 | }, |
69 | 74 | ||
diff --git a/server/tests/api/server/config-defaults.ts b/server/tests/api/server/config-defaults.ts index 340d4b44b..117fc20d7 100644 --- a/server/tests/api/server/config-defaults.ts +++ b/server/tests/api/server/config-defaults.ts | |||
@@ -125,40 +125,91 @@ describe('Test config defaults', function () { | |||
125 | 125 | ||
126 | describe('Default P2P values', function () { | 126 | describe('Default P2P values', function () { |
127 | 127 | ||
128 | before(async function () { | 128 | describe('Webapp default value', function () { |
129 | const overrideConfig = { | 129 | |
130 | defaults: { | 130 | before(async function () { |
131 | p2p: { | 131 | const overrideConfig = { |
132 | enabled: false | 132 | defaults: { |
133 | p2p: { | ||
134 | webapp: { | ||
135 | enabled: false | ||
136 | } | ||
137 | } | ||
133 | } | 138 | } |
134 | } | 139 | } |
135 | } | ||
136 | 140 | ||
137 | await server.kill() | 141 | await server.kill() |
138 | await server.run(overrideConfig) | 142 | await server.run(overrideConfig) |
139 | }) | 143 | }) |
140 | 144 | ||
141 | it('Should not have P2P enabled', async function () { | 145 | it('Should have appropriate P2P config', async function () { |
142 | const config = await server.config.getConfig() | 146 | const config = await server.config.getConfig() |
143 | 147 | ||
144 | expect(config.defaults.p2p.enabled).to.be.false | 148 | expect(config.defaults.p2p.webapp.enabled).to.be.false |
145 | }) | 149 | expect(config.defaults.p2p.embed.enabled).to.be.true |
150 | }) | ||
151 | |||
152 | it('Should create a user with this default setting', async function () { | ||
153 | await server.users.create({ username: 'user_p2p_1' }) | ||
154 | const userToken = await server.login.getAccessToken('user_p2p_1') | ||
155 | |||
156 | const { p2pEnabled } = await server.users.getMyInfo({ token: userToken }) | ||
157 | expect(p2pEnabled).to.be.false | ||
158 | }) | ||
146 | 159 | ||
147 | it('Should create a user with this default setting', async function () { | 160 | it('Should register a user with this default setting', async function () { |
148 | await server.users.create({ username: 'user_p2p_1' }) | 161 | await server.users.register({ username: 'user_p2p_2' }) |
149 | const userToken = await server.login.getAccessToken('user_p2p_1') | ||
150 | 162 | ||
151 | const { p2pEnabled } = await server.users.getMyInfo({ token: userToken }) | 163 | const userToken = await server.login.getAccessToken('user_p2p_2') |
152 | expect(p2pEnabled).to.be.false | 164 | |
165 | const { p2pEnabled } = await server.users.getMyInfo({ token: userToken }) | ||
166 | expect(p2pEnabled).to.be.false | ||
167 | }) | ||
153 | }) | 168 | }) |
154 | 169 | ||
155 | it('Should register a user with this default setting', async function () { | 170 | describe('Embed default value', function () { |
156 | await server.users.register({ username: 'user_p2p_2' }) | 171 | |
172 | before(async function () { | ||
173 | const overrideConfig = { | ||
174 | defaults: { | ||
175 | p2p: { | ||
176 | embed: { | ||
177 | enabled: false | ||
178 | } | ||
179 | } | ||
180 | }, | ||
181 | signup: { | ||
182 | limit: 15 | ||
183 | } | ||
184 | } | ||
185 | |||
186 | await server.kill() | ||
187 | await server.run(overrideConfig) | ||
188 | }) | ||
189 | |||
190 | it('Should have appropriate P2P config', async function () { | ||
191 | const config = await server.config.getConfig() | ||
157 | 192 | ||
158 | const userToken = await server.login.getAccessToken('user_p2p_2') | 193 | expect(config.defaults.p2p.webapp.enabled).to.be.true |
194 | expect(config.defaults.p2p.embed.enabled).to.be.false | ||
195 | }) | ||
196 | |||
197 | it('Should create a user with this default setting', async function () { | ||
198 | await server.users.create({ username: 'user_p2p_3' }) | ||
199 | const userToken = await server.login.getAccessToken('user_p2p_3') | ||
200 | |||
201 | const { p2pEnabled } = await server.users.getMyInfo({ token: userToken }) | ||
202 | expect(p2pEnabled).to.be.true | ||
203 | }) | ||
159 | 204 | ||
160 | const { p2pEnabled } = await server.users.getMyInfo({ token: userToken }) | 205 | it('Should register a user with this default setting', async function () { |
161 | expect(p2pEnabled).to.be.false | 206 | await server.users.register({ username: 'user_p2p_4' }) |
207 | |||
208 | const userToken = await server.login.getAccessToken('user_p2p_4') | ||
209 | |||
210 | const { p2pEnabled } = await server.users.getMyInfo({ token: userToken }) | ||
211 | expect(p2pEnabled).to.be.true | ||
212 | }) | ||
162 | }) | 213 | }) |
163 | }) | 214 | }) |
164 | 215 | ||