aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2018-10-05 15:17:34 +0200
committerRigel Kent <sendmemail@rigelk.eu>2018-10-13 11:53:42 +0200
commit64cc5e8575fda47b281ae20abf0020e27fc8ce7c (patch)
treec3ec40b03d3fdc5d3beee9ff089384c894d9efe9
parent0e5ff97f6fdf9a4cebe5a15f5a390380465803ad (diff)
downloadPeerTube-64cc5e8575fda47b281ae20abf0020e27fc8ce7c.tar.gz
PeerTube-64cc5e8575fda47b281ae20abf0020e27fc8ce7c.tar.zst
PeerTube-64cc5e8575fda47b281ae20abf0020e27fc8ce7c.zip
add webtorrent opt-out settings
- add a key in localstorage to remember the opt-out - add a user setting
-rw-r--r--client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.html12
-rw-r--r--client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.ts4
-rw-r--r--client/src/app/core/auth/auth-user.model.ts5
-rw-r--r--client/src/app/shared/users/user.model.ts4
-rw-r--r--client/src/assets/player/peertube-player-local-storage.ts10
-rw-r--r--client/src/assets/player/peertube-videojs-plugin.ts6
-rw-r--r--server/controllers/api/users/me.ts1
-rw-r--r--server/helpers/custom-validators/users.ts8
-rw-r--r--server/initializers/constants.ts10
-rw-r--r--server/initializers/migrations/0280-webtorrent-policy-user.ts26
-rw-r--r--server/models/account/user.ts12
-rw-r--r--shared/models/users/user-update-me.model.ts4
-rw-r--r--shared/models/users/user-webtorrent-policy.type.ts1
13 files changed, 97 insertions, 6 deletions
diff --git a/client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.html b/client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.html
index 96629940f..adbb97f00 100644
--- a/client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.html
+++ b/client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.html
@@ -15,6 +15,18 @@
15 </div> 15 </div>
16 </div> 16 </div>
17 17
18 <div class="form-group">
19 <label i18n for="webTorrentPolicy">Policy regarding P2P technologies</label>
20
21 <div class="peertube-select-container">
22 <select id="webTorrentPolicy" formControlName="webTorrentPolicy">
23 <option i18n value="enable">Enable WebTorrent</option>
24 <option i18n value="disable">Disable WebTorrent globally</option>
25 <option i18n value="disable_on_mobile" disabled>Disable WebTorrent on mobile devices (not yet available)</option>
26 </select>
27 </div>
28 </div>
29
18 <my-peertube-checkbox 30 <my-peertube-checkbox
19 inputName="autoPlayVideo" formControlName="autoPlayVideo" 31 inputName="autoPlayVideo" formControlName="autoPlayVideo"
20 i18n-labelText labelText="Automatically plays video" 32 i18n-labelText labelText="Automatically plays video"
diff --git a/client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.ts b/client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.ts
index 7089b2057..9e711a227 100644
--- a/client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.ts
+++ b/client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.ts
@@ -29,12 +29,14 @@ export class MyAccountVideoSettingsComponent extends FormReactive implements OnI
29 ngOnInit () { 29 ngOnInit () {
30 this.buildForm({ 30 this.buildForm({
31 nsfwPolicy: null, 31 nsfwPolicy: null,
32 webTorrentPolicy: null,
32 autoPlayVideo: null 33 autoPlayVideo: null
33 }) 34 })
34 35
35 this.userInformationLoaded.subscribe(() => { 36 this.userInformationLoaded.subscribe(() => {
36 this.form.patchValue({ 37 this.form.patchValue({
37 nsfwPolicy: this.user.nsfwPolicy, 38 nsfwPolicy: this.user.nsfwPolicy,
39 webTorrentPolicy: this.user.webTorrentPolicy,
38 autoPlayVideo: this.user.autoPlayVideo === true 40 autoPlayVideo: this.user.autoPlayVideo === true
39 }) 41 })
40 }) 42 })
@@ -42,9 +44,11 @@ export class MyAccountVideoSettingsComponent extends FormReactive implements OnI
42 44
43 updateDetails () { 45 updateDetails () {
44 const nsfwPolicy = this.form.value['nsfwPolicy'] 46 const nsfwPolicy = this.form.value['nsfwPolicy']
47 const webTorrentPolicy = this.form.value['webTorrentPolicy']
45 const autoPlayVideo = this.form.value['autoPlayVideo'] 48 const autoPlayVideo = this.form.value['autoPlayVideo']
46 const details: UserUpdateMe = { 49 const details: UserUpdateMe = {
47 nsfwPolicy, 50 nsfwPolicy,
51 webTorrentPolicy,
48 autoPlayVideo 52 autoPlayVideo
49 } 53 }
50 54
diff --git a/client/src/app/core/auth/auth-user.model.ts b/client/src/app/core/auth/auth-user.model.ts
index 74ed1c580..97acf7bfe 100644
--- a/client/src/app/core/auth/auth-user.model.ts
+++ b/client/src/app/core/auth/auth-user.model.ts
@@ -4,6 +4,7 @@ import { UserRight } from '../../../../../shared/models/users/user-right.enum'
4import { hasUserRight, UserRole } from '../../../../../shared/models/users/user-role' 4import { hasUserRight, UserRole } from '../../../../../shared/models/users/user-role'
5import { User, UserConstructorHash } from '../../shared/users/user.model' 5import { User, UserConstructorHash } from '../../shared/users/user.model'
6import { NSFWPolicyType } from '../../../../../shared/models/videos/nsfw-policy.type' 6import { NSFWPolicyType } from '../../../../../shared/models/videos/nsfw-policy.type'
7import { WebTorrentPolicyType } from '../../../../../shared/models/users/user-webtorrent-policy.type'
7 8
8export type TokenOptions = { 9export type TokenOptions = {
9 accessToken: string 10 accessToken: string
@@ -72,6 +73,7 @@ export class AuthUser extends User {
72 EMAIL: 'email', 73 EMAIL: 'email',
73 USERNAME: 'username', 74 USERNAME: 'username',
74 NSFW_POLICY: 'nsfw_policy', 75 NSFW_POLICY: 'nsfw_policy',
76 WEBTORRENT_POLICY: 'peertube-videojs-' + 'webtorrent_policy',
75 AUTO_PLAY_VIDEO: 'auto_play_video' 77 AUTO_PLAY_VIDEO: 'auto_play_video'
76 } 78 }
77 79
@@ -87,6 +89,7 @@ export class AuthUser extends User {
87 email: peertubeLocalStorage.getItem(this.KEYS.EMAIL), 89 email: peertubeLocalStorage.getItem(this.KEYS.EMAIL),
88 role: parseInt(peertubeLocalStorage.getItem(this.KEYS.ROLE), 10) as UserRole, 90 role: parseInt(peertubeLocalStorage.getItem(this.KEYS.ROLE), 10) as UserRole,
89 nsfwPolicy: peertubeLocalStorage.getItem(this.KEYS.NSFW_POLICY) as NSFWPolicyType, 91 nsfwPolicy: peertubeLocalStorage.getItem(this.KEYS.NSFW_POLICY) as NSFWPolicyType,
92 webTorrentPolicy: peertubeLocalStorage.getItem(this.KEYS.WEBTORRENT_POLICY) as WebTorrentPolicyType,
90 autoPlayVideo: peertubeLocalStorage.getItem(this.KEYS.AUTO_PLAY_VIDEO) === 'true' 93 autoPlayVideo: peertubeLocalStorage.getItem(this.KEYS.AUTO_PLAY_VIDEO) === 'true'
91 }, 94 },
92 Tokens.load() 95 Tokens.load()
@@ -101,6 +104,7 @@ export class AuthUser extends User {
101 peertubeLocalStorage.removeItem(this.KEYS.ID) 104 peertubeLocalStorage.removeItem(this.KEYS.ID)
102 peertubeLocalStorage.removeItem(this.KEYS.ROLE) 105 peertubeLocalStorage.removeItem(this.KEYS.ROLE)
103 peertubeLocalStorage.removeItem(this.KEYS.NSFW_POLICY) 106 peertubeLocalStorage.removeItem(this.KEYS.NSFW_POLICY)
107 peertubeLocalStorage.removeItem(this.KEYS.WEBTORRENT_POLICY)
104 peertubeLocalStorage.removeItem(this.KEYS.AUTO_PLAY_VIDEO) 108 peertubeLocalStorage.removeItem(this.KEYS.AUTO_PLAY_VIDEO)
105 peertubeLocalStorage.removeItem(this.KEYS.EMAIL) 109 peertubeLocalStorage.removeItem(this.KEYS.EMAIL)
106 Tokens.flush() 110 Tokens.flush()
@@ -138,6 +142,7 @@ export class AuthUser extends User {
138 peertubeLocalStorage.setItem(AuthUser.KEYS.EMAIL, this.email) 142 peertubeLocalStorage.setItem(AuthUser.KEYS.EMAIL, this.email)
139 peertubeLocalStorage.setItem(AuthUser.KEYS.ROLE, this.role.toString()) 143 peertubeLocalStorage.setItem(AuthUser.KEYS.ROLE, this.role.toString())
140 peertubeLocalStorage.setItem(AuthUser.KEYS.NSFW_POLICY, this.nsfwPolicy.toString()) 144 peertubeLocalStorage.setItem(AuthUser.KEYS.NSFW_POLICY, this.nsfwPolicy.toString())
145 peertubeLocalStorage.setItem(AuthUser.KEYS.WEBTORRENT_POLICY, this.webTorrentPolicy.toString())
141 peertubeLocalStorage.setItem(AuthUser.KEYS.AUTO_PLAY_VIDEO, JSON.stringify(this.autoPlayVideo)) 146 peertubeLocalStorage.setItem(AuthUser.KEYS.AUTO_PLAY_VIDEO, JSON.stringify(this.autoPlayVideo))
142 this.tokens.save() 147 this.tokens.save()
143 } 148 }
diff --git a/client/src/app/shared/users/user.model.ts b/client/src/app/shared/users/user.model.ts
index 877f1bf3a..240c7aacf 100644
--- a/client/src/app/shared/users/user.model.ts
+++ b/client/src/app/shared/users/user.model.ts
@@ -9,6 +9,7 @@ import {
9import { NSFWPolicyType } from '../../../../../shared/models/videos/nsfw-policy.type' 9import { NSFWPolicyType } from '../../../../../shared/models/videos/nsfw-policy.type'
10import { Account } from '@app/shared/account/account.model' 10import { Account } from '@app/shared/account/account.model'
11import { Avatar } from '../../../../../shared/models/avatars/avatar.model' 11import { Avatar } from '../../../../../shared/models/avatars/avatar.model'
12import { WebTorrentPolicyType } from '../../../../../shared/models/users/user-webtorrent-policy.type'
12 13
13export type UserConstructorHash = { 14export type UserConstructorHash = {
14 id: number, 15 id: number,
@@ -18,6 +19,7 @@ export type UserConstructorHash = {
18 videoQuota?: number, 19 videoQuota?: number,
19 videoQuotaDaily?: number, 20 videoQuotaDaily?: number,
20 nsfwPolicy?: NSFWPolicyType, 21 nsfwPolicy?: NSFWPolicyType,
22 webTorrentPolicy?: WebTorrentPolicyType,
21 autoPlayVideo?: boolean, 23 autoPlayVideo?: boolean,
22 createdAt?: Date, 24 createdAt?: Date,
23 account?: AccountServerModel, 25 account?: AccountServerModel,
@@ -32,6 +34,7 @@ export class User implements UserServerModel {
32 email: string 34 email: string
33 role: UserRole 35 role: UserRole
34 nsfwPolicy: NSFWPolicyType 36 nsfwPolicy: NSFWPolicyType
37 webTorrentPolicy: WebTorrentPolicyType
35 autoPlayVideo: boolean 38 autoPlayVideo: boolean
36 videoQuota: number 39 videoQuota: number
37 videoQuotaDaily: number 40 videoQuotaDaily: number
@@ -52,6 +55,7 @@ export class User implements UserServerModel {
52 this.videoQuota = hash.videoQuota 55 this.videoQuota = hash.videoQuota
53 this.videoQuotaDaily = hash.videoQuotaDaily 56 this.videoQuotaDaily = hash.videoQuotaDaily
54 this.nsfwPolicy = hash.nsfwPolicy 57 this.nsfwPolicy = hash.nsfwPolicy
58 this.webTorrentPolicy = hash.webTorrentPolicy
55 this.autoPlayVideo = hash.autoPlayVideo 59 this.autoPlayVideo = hash.autoPlayVideo
56 this.createdAt = hash.createdAt 60 this.createdAt = hash.createdAt
57 this.blocked = hash.blocked 61 this.blocked = hash.blocked
diff --git a/client/src/assets/player/peertube-player-local-storage.ts b/client/src/assets/player/peertube-player-local-storage.ts
index dac54c5a4..c3d8b71bc 100644
--- a/client/src/assets/player/peertube-player-local-storage.ts
+++ b/client/src/assets/player/peertube-player-local-storage.ts
@@ -10,6 +10,15 @@ function getStoredVolume () {
10 return undefined 10 return undefined
11} 11}
12 12
13function getStoredWebTorrentPolicy () {
14 const value = getLocalStorage('webtorrent_policy')
15 if (value !== null && value !== undefined) {
16 if (value.toString() === 'disable') return true
17 }
18
19 return undefined
20}
21
13function getStoredMute () { 22function getStoredMute () {
14 const value = getLocalStorage('mute') 23 const value = getLocalStorage('mute')
15 if (value !== null && value !== undefined) return value === 'true' 24 if (value !== null && value !== undefined) return value === 'true'
@@ -56,6 +65,7 @@ function getAverageBandwidthInStore () {
56 65
57export { 66export {
58 getStoredVolume, 67 getStoredVolume,
68 getStoredWebTorrentPolicy,
59 getStoredMute, 69 getStoredMute,
60 getStoredTheater, 70 getStoredTheater,
61 saveVolumeInStore, 71 saveVolumeInStore,
diff --git a/client/src/assets/player/peertube-videojs-plugin.ts b/client/src/assets/player/peertube-videojs-plugin.ts
index 2330f476f..90ca8f9fa 100644
--- a/client/src/assets/player/peertube-videojs-plugin.ts
+++ b/client/src/assets/player/peertube-videojs-plugin.ts
@@ -8,6 +8,7 @@ import { isMobile, timeToInt, videoFileMaxByResolution, videoFileMinByResolution
8import * as CacheChunkStore from 'cache-chunk-store' 8import * as CacheChunkStore from 'cache-chunk-store'
9import { PeertubeChunkStore } from './peertube-chunk-store' 9import { PeertubeChunkStore } from './peertube-chunk-store'
10import { 10import {
11 getStoredWebTorrentPolicy,
11 getAverageBandwidthInStore, 12 getAverageBandwidthInStore,
12 getStoredMute, 13 getStoredMute,
13 getStoredVolume, 14 getStoredVolume,
@@ -64,6 +65,7 @@ class PeerTubePlugin extends Plugin {
64 private autoResolution = true 65 private autoResolution = true
65 private forbidAutoResolution = false 66 private forbidAutoResolution = false
66 private isAutoResolutionObservation = false 67 private isAutoResolutionObservation = false
68 private playerRefusedP2P = false
67 69
68 private videoViewInterval 70 private videoViewInterval
69 private torrentInfoInterval 71 private torrentInfoInterval
@@ -97,6 +99,7 @@ class PeerTubePlugin extends Plugin {
97 if (volume !== undefined) this.player.volume(volume) 99 if (volume !== undefined) this.player.volume(volume)
98 const muted = getStoredMute() 100 const muted = getStoredMute()
99 if (muted !== undefined) this.player.muted(muted) 101 if (muted !== undefined) this.player.muted(muted)
102 this.playerRefusedP2P = getStoredWebTorrentPolicy() || false
100 103
101 this.initializePlayer() 104 this.initializePlayer()
102 this.runTorrentInfoScheduler() 105 this.runTorrentInfoScheduler()
@@ -288,7 +291,8 @@ class PeerTubePlugin extends Plugin {
288 renderVideo(torrent.files[ 0 ], this.playerElement, renderVideoOptions, (err, renderer) => { 291 renderVideo(torrent.files[ 0 ], this.playerElement, renderVideoOptions, (err, renderer) => {
289 this.renderer = renderer 292 this.renderer = renderer
290 293
291 if (err) return this.fallbackToHttp(done) 294 console.log('value this.playerRefusedP2P', this.playerRefusedP2P)
295 if (err || this.playerRefusedP2P) return this.fallbackToHttp(done)
292 296
293 return this.tryToPlay(err => { 297 return this.tryToPlay(err => {
294 if (err) return done(err) 298 if (err) return done(err)
diff --git a/server/controllers/api/users/me.ts b/server/controllers/api/users/me.ts
index 591ec6b25..f78294f17 100644
--- a/server/controllers/api/users/me.ts
+++ b/server/controllers/api/users/me.ts
@@ -327,6 +327,7 @@ async function updateMe (req: express.Request, res: express.Response, next: expr
327 if (body.password !== undefined) user.password = body.password 327 if (body.password !== undefined) user.password = body.password
328 if (body.email !== undefined) user.email = body.email 328 if (body.email !== undefined) user.email = body.email
329 if (body.nsfwPolicy !== undefined) user.nsfwPolicy = body.nsfwPolicy 329 if (body.nsfwPolicy !== undefined) user.nsfwPolicy = body.nsfwPolicy
330 if (body.webTorrentPolicy !== undefined) user.webTorrentPolicy = body.webTorrentPolicy
330 if (body.autoPlayVideo !== undefined) user.autoPlayVideo = body.autoPlayVideo 331 if (body.autoPlayVideo !== undefined) user.autoPlayVideo = body.autoPlayVideo
331 332
332 await sequelizeTypescript.transaction(async t => { 333 await sequelizeTypescript.transaction(async t => {
diff --git a/server/helpers/custom-validators/users.ts b/server/helpers/custom-validators/users.ts
index 90fc74a48..2024d4a22 100644
--- a/server/helpers/custom-validators/users.ts
+++ b/server/helpers/custom-validators/users.ts
@@ -1,7 +1,7 @@
1import 'express-validator' 1import 'express-validator'
2import * as validator from 'validator' 2import * as validator from 'validator'
3import { UserRole } from '../../../shared' 3import { UserRole } from '../../../shared'
4import { CONSTRAINTS_FIELDS, NSFW_POLICY_TYPES } from '../../initializers' 4import { CONSTRAINTS_FIELDS, NSFW_POLICY_TYPES, WEBTORRENT_POLICY_TYPES } from '../../initializers'
5import { exists, isFileValid, isBooleanValid } from './misc' 5import { exists, isFileValid, isBooleanValid } from './misc'
6import { values } from 'lodash' 6import { values } from 'lodash'
7 7
@@ -42,6 +42,11 @@ function isUserNSFWPolicyValid (value: any) {
42 return exists(value) && nsfwPolicies.indexOf(value) !== -1 42 return exists(value) && nsfwPolicies.indexOf(value) !== -1
43} 43}
44 44
45const webTorrentPolicies = values(WEBTORRENT_POLICY_TYPES)
46function isUserWebTorrentPolicyValid (value: any) {
47 return exists(value) && webTorrentPolicies.indexOf(value) !== -1
48}
49
45function isUserAutoPlayVideoValid (value: any) { 50function isUserAutoPlayVideoValid (value: any) {
46 return isBooleanValid(value) 51 return isBooleanValid(value)
47} 52}
@@ -78,6 +83,7 @@ export {
78 isUserUsernameValid, 83 isUserUsernameValid,
79 isUserEmailVerifiedValid, 84 isUserEmailVerifiedValid,
80 isUserNSFWPolicyValid, 85 isUserNSFWPolicyValid,
86 isUserWebTorrentPolicyValid,
81 isUserAutoPlayVideoValid, 87 isUserAutoPlayVideoValid,
82 isUserDisplayNameValid, 88 isUserDisplayNameValid,
83 isUserDescriptionValid, 89 isUserDescriptionValid,
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts
index e08fd75cd..f56763a16 100644
--- a/server/initializers/constants.ts
+++ b/server/initializers/constants.ts
@@ -7,6 +7,7 @@ import { VideoAbuseState, VideoImportState, VideoPrivacy, VideoTranscodingFPS }
7// Do not use barrels, remain constants as independent as possible 7// Do not use barrels, remain constants as independent as possible
8import { buildPath, isTestInstance, parseDuration, parseBytes, root, sanitizeHost, sanitizeUrl } from '../helpers/core-utils' 8import { buildPath, isTestInstance, parseDuration, parseBytes, root, sanitizeHost, sanitizeUrl } from '../helpers/core-utils'
9import { NSFWPolicyType } from '../../shared/models/videos/nsfw-policy.type' 9import { NSFWPolicyType } from '../../shared/models/videos/nsfw-policy.type'
10import { WebTorrentPolicyType } from '../../shared/models/users/user-webtorrent-policy.type'
10import { invert } from 'lodash' 11import { invert } from 'lodash'
11import { CronRepeatOptions, EveryRepeatOptions } from 'bull' 12import { CronRepeatOptions, EveryRepeatOptions } from 'bull'
12import * as bytes from 'bytes' 13import * as bytes from 'bytes'
@@ -16,7 +17,7 @@ let config: IConfig = require('config')
16 17
17// --------------------------------------------------------------------------- 18// ---------------------------------------------------------------------------
18 19
19const LAST_MIGRATION_VERSION = 275 20const LAST_MIGRATION_VERSION = 280
20 21
21// --------------------------------------------------------------------------- 22// ---------------------------------------------------------------------------
22 23
@@ -546,6 +547,12 @@ const NSFW_POLICY_TYPES: { [ id: string]: NSFWPolicyType } = {
546 DISPLAY: 'display' 547 DISPLAY: 'display'
547} 548}
548 549
550const WEBTORRENT_POLICY_TYPES: { [ id: string]: WebTorrentPolicyType } = {
551 ENABLE: 'enable',
552 DISABLE: 'disable',
553 DISABLE_ON_MOBILE: 'disable_on_mobile'
554}
555
549// --------------------------------------------------------------------------- 556// ---------------------------------------------------------------------------
550 557
551// Express static paths (router) 558// Express static paths (router)
@@ -698,6 +705,7 @@ export {
698 FEEDS, 705 FEEDS,
699 JOB_TTL, 706 JOB_TTL,
700 NSFW_POLICY_TYPES, 707 NSFW_POLICY_TYPES,
708 WEBTORRENT_POLICY_TYPES,
701 TORRENT_MIMETYPE_EXT, 709 TORRENT_MIMETYPE_EXT,
702 STATIC_MAX_AGE, 710 STATIC_MAX_AGE,
703 STATIC_PATHS, 711 STATIC_PATHS,
diff --git a/server/initializers/migrations/0280-webtorrent-policy-user.ts b/server/initializers/migrations/0280-webtorrent-policy-user.ts
new file mode 100644
index 000000000..d24f6709e
--- /dev/null
+++ b/server/initializers/migrations/0280-webtorrent-policy-user.ts
@@ -0,0 +1,26 @@
1import * as Sequelize from 'sequelize'
2import { values } from 'lodash'
3import { WEBTORRENT_POLICY_TYPES } from '../constants'
4
5async function up (utils: {
6 transaction: Sequelize.Transaction
7 queryInterface: Sequelize.QueryInterface
8 sequelize: Sequelize.Sequelize
9}): Promise<any> {
10 {
11 const data = {
12 type: Sequelize.ENUM(values(WEBTORRENT_POLICY_TYPES)),
13 allowNull: false,
14 defaultValue: 'enable'
15 }
16
17 await utils.queryInterface.addColumn('user', 'webTorrentPolicy', data)
18 }
19
20}
21
22function down (options) {
23 throw new Error('Not implemented.')
24}
25
26export { up, down }
diff --git a/server/models/account/user.ts b/server/models/account/user.ts
index 39654cfcf..5fe7d7e7d 100644
--- a/server/models/account/user.ts
+++ b/server/models/account/user.ts
@@ -31,7 +31,8 @@ import {
31 isUserRoleValid, 31 isUserRoleValid,
32 isUserUsernameValid, 32 isUserUsernameValid,
33 isUserVideoQuotaDailyValid, 33 isUserVideoQuotaDailyValid,
34 isUserVideoQuotaValid 34 isUserVideoQuotaValid,
35 isUserWebTorrentPolicyValid
35} from '../../helpers/custom-validators/users' 36} from '../../helpers/custom-validators/users'
36import { comparePassword, cryptPassword } from '../../helpers/peertube-crypto' 37import { comparePassword, cryptPassword } from '../../helpers/peertube-crypto'
37import { OAuthTokenModel } from '../oauth/oauth-token' 38import { OAuthTokenModel } from '../oauth/oauth-token'
@@ -39,8 +40,9 @@ import { getSort, throwIfNotValid } from '../utils'
39import { VideoChannelModel } from '../video/video-channel' 40import { VideoChannelModel } from '../video/video-channel'
40import { AccountModel } from './account' 41import { AccountModel } from './account'
41import { NSFWPolicyType } from '../../../shared/models/videos/nsfw-policy.type' 42import { NSFWPolicyType } from '../../../shared/models/videos/nsfw-policy.type'
43import { WebTorrentPolicyType } from '../../../shared/models/users/user-webtorrent-policy.type'
42import { values } from 'lodash' 44import { values } from 'lodash'
43import { NSFW_POLICY_TYPES } from '../../initializers' 45import { NSFW_POLICY_TYPES, WEBTORRENT_POLICY_TYPES } from '../../initializers'
44import { clearCacheByUserId } from '../../lib/oauth-model' 46import { clearCacheByUserId } from '../../lib/oauth-model'
45 47
46enum ScopeNames { 48enum ScopeNames {
@@ -108,6 +110,11 @@ export class UserModel extends Model<UserModel> {
108 nsfwPolicy: NSFWPolicyType 110 nsfwPolicy: NSFWPolicyType
109 111
110 @AllowNull(false) 112 @AllowNull(false)
113 @Is('UserWebTorrentPolicy', value => throwIfNotValid(value, isUserWebTorrentPolicyValid, 'WebTorrent policy'))
114 @Column(DataType.ENUM(values(WEBTORRENT_POLICY_TYPES)))
115 webTorrentPolicy: WebTorrentPolicyType
116
117 @AllowNull(false)
111 @Default(true) 118 @Default(true)
112 @Is('UserAutoPlayVideo', value => throwIfNotValid(value, isUserAutoPlayVideoValid, 'auto play video boolean')) 119 @Is('UserAutoPlayVideo', value => throwIfNotValid(value, isUserAutoPlayVideoValid, 'auto play video boolean'))
113 @Column 120 @Column
@@ -355,6 +362,7 @@ export class UserModel extends Model<UserModel> {
355 email: this.email, 362 email: this.email,
356 emailVerified: this.emailVerified, 363 emailVerified: this.emailVerified,
357 nsfwPolicy: this.nsfwPolicy, 364 nsfwPolicy: this.nsfwPolicy,
365 webTorrentPolicy: this.webTorrentPolicy,
358 autoPlayVideo: this.autoPlayVideo, 366 autoPlayVideo: this.autoPlayVideo,
359 role: this.role, 367 role: this.role,
360 roleLabel: USER_ROLE_LABELS[ this.role ], 368 roleLabel: USER_ROLE_LABELS[ this.role ],
diff --git a/shared/models/users/user-update-me.model.ts b/shared/models/users/user-update-me.model.ts
index bbffe1487..81790377e 100644
--- a/shared/models/users/user-update-me.model.ts
+++ b/shared/models/users/user-update-me.model.ts
@@ -1,9 +1,11 @@
1import { NSFWPolicyType } from '../videos/nsfw-policy.type' 1import { NSFWPolicyType } from '../videos/nsfw-policy.type'
2import { WebTorrentPolicyType } from './user-webtorrent-policy.type'
2 3
3export interface UserUpdateMe { 4export interface UserUpdateMe {
4 displayName?: string 5 displayName?: string
5 description?: string 6 description?: string
6 nsfwPolicy?: NSFWPolicyType 7 nsfwPolicy?: NSFWPolicyType,
8 webTorrentPolicy?: WebTorrentPolicyType,
7 autoPlayVideo?: boolean 9 autoPlayVideo?: boolean
8 email?: string 10 email?: string
9 currentPassword?: string 11 currentPassword?: string
diff --git a/shared/models/users/user-webtorrent-policy.type.ts b/shared/models/users/user-webtorrent-policy.type.ts
new file mode 100644
index 000000000..e293f761d
--- /dev/null
+++ b/shared/models/users/user-webtorrent-policy.type.ts
@@ -0,0 +1 @@
export type WebTorrentPolicyType = 'enable' | 'disable' | 'disable_on_mobile'