Use different p2p policy for embeds and webapp
This commit is contained in:
parent
9576506763
commit
b65de1be4d
12 changed files with 118 additions and 36 deletions
|
@ -57,7 +57,12 @@ function buildConfig (suiteFile: string = undefined) {
|
||||||
licence: 4
|
licence: 4
|
||||||
},
|
},
|
||||||
p2p: {
|
p2p: {
|
||||||
enabled: false
|
webapp: {
|
||||||
|
enabled: false
|
||||||
|
},
|
||||||
|
embed: {
|
||||||
|
enabled: false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,7 +101,7 @@ export class UserLocalStorageService {
|
||||||
const htmlConfig = this.server.getHTMLConfig()
|
const htmlConfig = this.server.getHTMLConfig()
|
||||||
|
|
||||||
const defaultNSFWPolicy = htmlConfig.instance.defaultNSFWPolicy
|
const defaultNSFWPolicy = htmlConfig.instance.defaultNSFWPolicy
|
||||||
const defaultP2PEnabled = htmlConfig.defaults.p2p.enabled
|
const defaultP2PEnabled = htmlConfig.defaults.p2p.webapp.enabled
|
||||||
|
|
||||||
return {
|
return {
|
||||||
nsfwPolicy: this.localStorageService.getItem<NSFWPolicyType>(UserLocalStorageKeys.NSFW_POLICY) || defaultNSFWPolicy,
|
nsfwPolicy: this.localStorageService.getItem<NSFWPolicyType>(UserLocalStorageKeys.NSFW_POLICY) || defaultNSFWPolicy,
|
||||||
|
|
|
@ -793,7 +793,7 @@ export class PeerTubeEmbed {
|
||||||
private isP2PEnabled (video: Video) {
|
private isP2PEnabled (video: Video) {
|
||||||
const userP2PEnabled = getBoolOrDefault(
|
const userP2PEnabled = getBoolOrDefault(
|
||||||
peertubeLocalStorage.getItem(UserLocalStorageKeys.P2P_ENABLED),
|
peertubeLocalStorage.getItem(UserLocalStorageKeys.P2P_ENABLED),
|
||||||
this.config.defaults.p2p.enabled
|
this.config.defaults.p2p.embed.enabled
|
||||||
)
|
)
|
||||||
|
|
||||||
return isP2PEnabled(video, this.config, userP2PEnabled)
|
return isP2PEnabled(video, this.config, userP2PEnabled)
|
||||||
|
|
|
@ -93,9 +93,15 @@ defaults:
|
||||||
licence: null
|
licence: null
|
||||||
|
|
||||||
p2p:
|
p2p:
|
||||||
# Enable P2P by default
|
# Enable P2P by default in PeerTube client
|
||||||
# Can be enabled/disabled by anonymous users and logged in users
|
# Can be enabled/disabled by anonymous users and logged in users
|
||||||
enabled: true
|
webapp:
|
||||||
|
enabled: true
|
||||||
|
|
||||||
|
# Enable P2P by default in PeerTube embed
|
||||||
|
# Can be enabled/disabled by URL option
|
||||||
|
embed:
|
||||||
|
enabled: true
|
||||||
|
|
||||||
# From the project root directory
|
# From the project root directory
|
||||||
storage:
|
storage:
|
||||||
|
|
|
@ -93,7 +93,11 @@ defaults:
|
||||||
p2p:
|
p2p:
|
||||||
# Enable P2P by default
|
# Enable P2P by default
|
||||||
# Can be enabled/disabled by anonymous users and logged in users
|
# Can be enabled/disabled by anonymous users and logged in users
|
||||||
enabled: true
|
webapp:
|
||||||
|
enabled: true
|
||||||
|
|
||||||
|
embed:
|
||||||
|
enabled: true
|
||||||
|
|
||||||
# From the project root directory
|
# From the project root directory
|
||||||
storage:
|
storage:
|
||||||
|
|
|
@ -183,7 +183,7 @@ async function createUser (req: express.Request, res: express.Response) {
|
||||||
password: body.password,
|
password: body.password,
|
||||||
email: body.email,
|
email: body.email,
|
||||||
nsfwPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY,
|
nsfwPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY,
|
||||||
p2pEnabled: CONFIG.DEFAULTS.P2P.ENABLED,
|
p2pEnabled: CONFIG.DEFAULTS.P2P.WEBAPP.ENABLED,
|
||||||
autoPlayVideo: true,
|
autoPlayVideo: true,
|
||||||
role: body.role,
|
role: body.role,
|
||||||
videoQuota: body.videoQuota,
|
videoQuota: body.videoQuota,
|
||||||
|
@ -233,7 +233,7 @@ async function registerUser (req: express.Request, res: express.Response) {
|
||||||
password: body.password,
|
password: body.password,
|
||||||
email: body.email,
|
email: body.email,
|
||||||
nsfwPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY,
|
nsfwPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY,
|
||||||
p2pEnabled: CONFIG.DEFAULTS.P2P.ENABLED,
|
p2pEnabled: CONFIG.DEFAULTS.P2P.WEBAPP.ENABLED,
|
||||||
autoPlayVideo: true,
|
autoPlayVideo: true,
|
||||||
role: UserRole.USER,
|
role: UserRole.USER,
|
||||||
videoQuota: CONFIG.USER.VIDEO_QUOTA,
|
videoQuota: CONFIG.USER.VIDEO_QUOTA,
|
||||||
|
|
|
@ -80,7 +80,12 @@ const CONFIG = {
|
||||||
LICENCE: config.get<number>('defaults.publish.licence')
|
LICENCE: config.get<number>('defaults.publish.licence')
|
||||||
},
|
},
|
||||||
P2P: {
|
P2P: {
|
||||||
ENABLED: config.get<boolean>('defaults.p2p.enabled')
|
WEBAPP: {
|
||||||
|
ENABLED: config.get<boolean>('defaults.p2p.webapp.enabled')
|
||||||
|
},
|
||||||
|
EMBED: {
|
||||||
|
ENABLED: config.get<boolean>('defaults.p2p.embed.enabled')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -144,7 +144,7 @@ async function createOAuthAdminIfNotExist () {
|
||||||
role,
|
role,
|
||||||
verified: true,
|
verified: true,
|
||||||
nsfwPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY,
|
nsfwPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY,
|
||||||
p2pEnabled: CONFIG.DEFAULTS.P2P.ENABLED,
|
p2pEnabled: CONFIG.DEFAULTS.P2P.WEBAPP.ENABLED,
|
||||||
videoQuota: -1,
|
videoQuota: -1,
|
||||||
videoQuotaDaily: -1
|
videoQuotaDaily: -1
|
||||||
}
|
}
|
||||||
|
|
|
@ -226,7 +226,7 @@ async function createUserFromExternal (pluginAuth: string, options: {
|
||||||
password: null,
|
password: null,
|
||||||
email: options.email,
|
email: options.email,
|
||||||
nsfwPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY,
|
nsfwPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY,
|
||||||
p2pEnabled: CONFIG.DEFAULTS.P2P.ENABLED,
|
p2pEnabled: CONFIG.DEFAULTS.P2P.WEBAPP.ENABLED,
|
||||||
autoPlayVideo: true,
|
autoPlayVideo: true,
|
||||||
role: options.role,
|
role: options.role,
|
||||||
videoQuota: CONFIG.USER.VIDEO_QUOTA,
|
videoQuota: CONFIG.USER.VIDEO_QUOTA,
|
||||||
|
|
|
@ -63,7 +63,12 @@ class ServerConfigManager {
|
||||||
licence: CONFIG.DEFAULTS.PUBLISH.LICENCE
|
licence: CONFIG.DEFAULTS.PUBLISH.LICENCE
|
||||||
},
|
},
|
||||||
p2p: {
|
p2p: {
|
||||||
enabled: CONFIG.DEFAULTS.P2P.ENABLED
|
webapp: {
|
||||||
|
enabled: CONFIG.DEFAULTS.P2P.WEBAPP.ENABLED
|
||||||
|
},
|
||||||
|
embed: {
|
||||||
|
enabled: CONFIG.DEFAULTS.P2P.EMBED.ENABLED
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -125,40 +125,91 @@ describe('Test config defaults', function () {
|
||||||
|
|
||||||
describe('Default P2P values', function () {
|
describe('Default P2P values', function () {
|
||||||
|
|
||||||
before(async function () {
|
describe('Webapp default value', function () {
|
||||||
const overrideConfig = {
|
|
||||||
defaults: {
|
before(async function () {
|
||||||
p2p: {
|
const overrideConfig = {
|
||||||
enabled: false
|
defaults: {
|
||||||
|
p2p: {
|
||||||
|
webapp: {
|
||||||
|
enabled: false
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
await server.kill()
|
await server.kill()
|
||||||
await server.run(overrideConfig)
|
await server.run(overrideConfig)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Should have appropriate P2P config', async function () {
|
||||||
|
const config = await server.config.getConfig()
|
||||||
|
|
||||||
|
expect(config.defaults.p2p.webapp.enabled).to.be.false
|
||||||
|
expect(config.defaults.p2p.embed.enabled).to.be.true
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Should create a user with this default setting', async function () {
|
||||||
|
await server.users.create({ username: 'user_p2p_1' })
|
||||||
|
const userToken = await server.login.getAccessToken('user_p2p_1')
|
||||||
|
|
||||||
|
const { p2pEnabled } = await server.users.getMyInfo({ token: userToken })
|
||||||
|
expect(p2pEnabled).to.be.false
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Should register a user with this default setting', async function () {
|
||||||
|
await server.users.register({ username: 'user_p2p_2' })
|
||||||
|
|
||||||
|
const userToken = await server.login.getAccessToken('user_p2p_2')
|
||||||
|
|
||||||
|
const { p2pEnabled } = await server.users.getMyInfo({ token: userToken })
|
||||||
|
expect(p2pEnabled).to.be.false
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should not have P2P enabled', async function () {
|
describe('Embed default value', function () {
|
||||||
const config = await server.config.getConfig()
|
|
||||||
|
|
||||||
expect(config.defaults.p2p.enabled).to.be.false
|
before(async function () {
|
||||||
})
|
const overrideConfig = {
|
||||||
|
defaults: {
|
||||||
|
p2p: {
|
||||||
|
embed: {
|
||||||
|
enabled: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
signup: {
|
||||||
|
limit: 15
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
it('Should create a user with this default setting', async function () {
|
await server.kill()
|
||||||
await server.users.create({ username: 'user_p2p_1' })
|
await server.run(overrideConfig)
|
||||||
const userToken = await server.login.getAccessToken('user_p2p_1')
|
})
|
||||||
|
|
||||||
const { p2pEnabled } = await server.users.getMyInfo({ token: userToken })
|
it('Should have appropriate P2P config', async function () {
|
||||||
expect(p2pEnabled).to.be.false
|
const config = await server.config.getConfig()
|
||||||
})
|
|
||||||
|
|
||||||
it('Should register a user with this default setting', async function () {
|
expect(config.defaults.p2p.webapp.enabled).to.be.true
|
||||||
await server.users.register({ username: 'user_p2p_2' })
|
expect(config.defaults.p2p.embed.enabled).to.be.false
|
||||||
|
})
|
||||||
|
|
||||||
const userToken = await server.login.getAccessToken('user_p2p_2')
|
it('Should create a user with this default setting', async function () {
|
||||||
|
await server.users.create({ username: 'user_p2p_3' })
|
||||||
|
const userToken = await server.login.getAccessToken('user_p2p_3')
|
||||||
|
|
||||||
const { p2pEnabled } = await server.users.getMyInfo({ token: userToken })
|
const { p2pEnabled } = await server.users.getMyInfo({ token: userToken })
|
||||||
expect(p2pEnabled).to.be.false
|
expect(p2pEnabled).to.be.true
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Should register a user with this default setting', async function () {
|
||||||
|
await server.users.register({ username: 'user_p2p_4' })
|
||||||
|
|
||||||
|
const userToken = await server.login.getAccessToken('user_p2p_4')
|
||||||
|
|
||||||
|
const { p2pEnabled } = await server.users.getMyInfo({ token: userToken })
|
||||||
|
expect(p2pEnabled).to.be.true
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,13 @@ export interface ServerConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
p2p: {
|
p2p: {
|
||||||
enabled: boolean
|
webapp: {
|
||||||
|
enabled: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
embed: {
|
||||||
|
enabled: boolean
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue