aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-12-16 09:38:27 +0100
committerChocobozzz <me@florianbigard.com>2021-12-16 10:08:55 +0100
commitb65de1be4dcf626c552be613d531d3f6e23c6085 (patch)
tree42c4d7440f9fadee6efb48ad39ccfe1a3bce8511
parent9576506763c20c7efbdb229483440a1fc984cf4d (diff)
downloadPeerTube-b65de1be4dcf626c552be613d531d3f6e23c6085.tar.gz
PeerTube-b65de1be4dcf626c552be613d531d3f6e23c6085.tar.zst
PeerTube-b65de1be4dcf626c552be613d531d3f6e23c6085.zip
Use different p2p policy for embeds and webapp
-rw-r--r--client/e2e/src/utils/hooks.ts7
-rw-r--r--client/src/app/core/users/user-local-storage.service.ts2
-rw-r--r--client/src/standalone/videos/embed.ts2
-rw-r--r--config/default.yaml10
-rw-r--r--config/production.yaml.example6
-rw-r--r--server/controllers/api/users/index.ts4
-rw-r--r--server/initializers/config.ts7
-rw-r--r--server/initializers/installer.ts2
-rw-r--r--server/lib/auth/oauth-model.ts2
-rw-r--r--server/lib/server-config-manager.ts7
-rw-r--r--server/tests/api/server/config-defaults.ts97
-rw-r--r--shared/models/server/server-config.model.ts8
12 files changed, 118 insertions, 36 deletions
diff --git a/client/e2e/src/utils/hooks.ts b/client/e2e/src/utils/hooks.ts
index 2f3d10fe3..e139d8183 100644
--- a/client/e2e/src/utils/hooks.ts
+++ b/client/e2e/src/utils/hooks.ts
@@ -57,7 +57,12 @@ function buildConfig (suiteFile: string = undefined) {
57 licence: 4 57 licence: 4
58 }, 58 },
59 p2p: { 59 p2p: {
60 enabled: false 60 webapp: {
61 enabled: false
62 },
63 embed: {
64 enabled: false
65 }
61 } 66 }
62 } 67 }
63 } 68 }
diff --git a/client/src/app/core/users/user-local-storage.service.ts b/client/src/app/core/users/user-local-storage.service.ts
index 85da46e0d..d15bf735b 100644
--- a/client/src/app/core/users/user-local-storage.service.ts
+++ b/client/src/app/core/users/user-local-storage.service.ts
@@ -101,7 +101,7 @@ export class UserLocalStorageService {
101 const htmlConfig = this.server.getHTMLConfig() 101 const htmlConfig = this.server.getHTMLConfig()
102 102
103 const defaultNSFWPolicy = htmlConfig.instance.defaultNSFWPolicy 103 const defaultNSFWPolicy = htmlConfig.instance.defaultNSFWPolicy
104 const defaultP2PEnabled = htmlConfig.defaults.p2p.enabled 104 const defaultP2PEnabled = htmlConfig.defaults.p2p.webapp.enabled
105 105
106 return { 106 return {
107 nsfwPolicy: this.localStorageService.getItem<NSFWPolicyType>(UserLocalStorageKeys.NSFW_POLICY) || defaultNSFWPolicy, 107 nsfwPolicy: this.localStorageService.getItem<NSFWPolicyType>(UserLocalStorageKeys.NSFW_POLICY) || defaultNSFWPolicy,
diff --git a/client/src/standalone/videos/embed.ts b/client/src/standalone/videos/embed.ts
index 94f1096b7..c04f94d20 100644
--- a/client/src/standalone/videos/embed.ts
+++ b/client/src/standalone/videos/embed.ts
@@ -793,7 +793,7 @@ export class PeerTubeEmbed {
793 private isP2PEnabled (video: Video) { 793 private isP2PEnabled (video: Video) {
794 const userP2PEnabled = getBoolOrDefault( 794 const userP2PEnabled = getBoolOrDefault(
795 peertubeLocalStorage.getItem(UserLocalStorageKeys.P2P_ENABLED), 795 peertubeLocalStorage.getItem(UserLocalStorageKeys.P2P_ENABLED),
796 this.config.defaults.p2p.enabled 796 this.config.defaults.p2p.embed.enabled
797 ) 797 )
798 798
799 return isP2PEnabled(video, this.config, userP2PEnabled) 799 return isP2PEnabled(video, this.config, userP2PEnabled)
diff --git a/config/default.yaml b/config/default.yaml
index 421c19569..e254c2c28 100644
--- a/config/default.yaml
+++ b/config/default.yaml
@@ -93,9 +93,15 @@ defaults:
93 licence: null 93 licence: null
94 94
95 p2p: 95 p2p:
96 # Enable P2P by default 96 # Enable P2P by default in PeerTube client
97 # Can be enabled/disabled by anonymous users and logged in users 97 # Can be enabled/disabled by anonymous users and logged in users
98 enabled: true 98 webapp:
99 enabled: true
100
101 # Enable P2P by default in PeerTube embed
102 # Can be enabled/disabled by URL option
103 embed:
104 enabled: true
99 105
100# From the project root directory 106# From the project root directory
101storage: 107storage:
diff --git a/config/production.yaml.example b/config/production.yaml.example
index 13219fd5d..0ce0b9d0e 100644
--- a/config/production.yaml.example
+++ b/config/production.yaml.example
@@ -93,7 +93,11 @@ defaults:
93 p2p: 93 p2p:
94 # Enable P2P by default 94 # Enable P2P by default
95 # Can be enabled/disabled by anonymous users and logged in users 95 # Can be enabled/disabled by anonymous users and logged in users
96 enabled: true 96 webapp:
97 enabled: true
98
99 embed:
100 enabled: true
97 101
98# From the project root directory 102# From the project root directory
99storage: 103storage:
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
diff --git a/shared/models/server/server-config.model.ts b/shared/models/server/server-config.model.ts
index 71540e603..0e3b4a3d2 100644
--- a/shared/models/server/server-config.model.ts
+++ b/shared/models/server/server-config.model.ts
@@ -57,7 +57,13 @@ export interface ServerConfig {
57 } 57 }
58 58
59 p2p: { 59 p2p: {
60 enabled: boolean 60 webapp: {
61 enabled: boolean
62 }
63
64 embed: {
65 enabled: boolean
66 }
61 } 67 }
62 } 68 }
63 69