aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2018-10-12 18:12:39 +0200
committerRigel Kent <sendmemail@rigelk.eu>2018-10-13 11:53:48 +0200
commited638e5325096ef580da20f370ac61c59cd48cf7 (patch)
tree8ad4c1001efb3adc3946a6b6c9a3c1ed1f557995
parent64cc5e8575fda47b281ae20abf0020e27fc8ce7c (diff)
downloadPeerTube-ed638e5325096ef580da20f370ac61c59cd48cf7.tar.gz
PeerTube-ed638e5325096ef580da20f370ac61c59cd48cf7.tar.zst
PeerTube-ed638e5325096ef580da20f370ac61c59cd48cf7.zip
move to boolean switch
-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.ts8
-rw-r--r--client/src/app/core/auth/auth-user.model.ts9
-rw-r--r--client/src/app/shared/users/user.model.ts7
-rw-r--r--client/src/assets/player/peertube-player-local-storage.ts12
-rw-r--r--client/src/assets/player/peertube-videojs-plugin.ts5
-rw-r--r--server/controllers/api/users/me.ts2
-rw-r--r--server/helpers/custom-validators/users.ts9
-rw-r--r--server/initializers/constants.ts8
-rw-r--r--server/initializers/migrations/0280-webtorrent-policy-user.ts16
-rw-r--r--server/models/account/user.ts13
-rw-r--r--shared/models/users/user-update-me.model.ts3
-rw-r--r--shared/models/users/user-webtorrent-policy.type.ts1
13 files changed, 47 insertions, 58 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 adbb97f00..50f798c79 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
@@ -16,18 +16,22 @@
16 </div> 16 </div>
17 17
18 <div class="form-group"> 18 <div class="form-group">
19 <label i18n for="webTorrentPolicy">Policy regarding P2P technologies</label> 19 <label i18n for="webTorrentEnabled">Policy regarding P2P technologies</label>
20 20
21 <div class="peertube-select-container"> 21 <div class="peertube-select-container">
22 <select id="webTorrentPolicy" formControlName="webTorrentPolicy"> 22 <select id="webTorrentEnabled" formControlName="webTorrentEnabled">
23 <option i18n value="enable">Enable WebTorrent</option> 23 <option i18n value="enable">Enable WebTorrent</option>
24 <option i18n value="disable">Disable WebTorrent globally</option> 24 <option i18n value="disable">Disable WebTorrent</option>
25 <option i18n value="disable_on_mobile" disabled>Disable WebTorrent on mobile devices (not yet available)</option>
26 </select> 25 </select>
27 </div> 26 </div>
28 </div> 27 </div>
29 28
30 <my-peertube-checkbox 29 <my-peertube-checkbox
30 inputName="webTorrentEnabled" formControlName="webTorrentEnabled"
31 i18n-labelText labelText="Use WebTorrent to exchange parts of the video with others"
32 ></my-peertube-checkbox>
33
34 <my-peertube-checkbox
31 inputName="autoPlayVideo" formControlName="autoPlayVideo" 35 inputName="autoPlayVideo" formControlName="autoPlayVideo"
32 i18n-labelText labelText="Automatically plays video" 36 i18n-labelText labelText="Automatically plays video"
33 ></my-peertube-checkbox> 37 ></my-peertube-checkbox>
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 9e711a227..6c9a7ce75 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,14 +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 webTorrentEnabled: null,
33 autoPlayVideo: null 33 autoPlayVideo: null
34 }) 34 })
35 35
36 this.userInformationLoaded.subscribe(() => { 36 this.userInformationLoaded.subscribe(() => {
37 this.form.patchValue({ 37 this.form.patchValue({
38 nsfwPolicy: this.user.nsfwPolicy, 38 nsfwPolicy: this.user.nsfwPolicy,
39 webTorrentPolicy: this.user.webTorrentPolicy, 39 webTorrentEnabled: this.user.webTorrentEnabled,
40 autoPlayVideo: this.user.autoPlayVideo === true 40 autoPlayVideo: this.user.autoPlayVideo === true
41 }) 41 })
42 }) 42 })
@@ -44,11 +44,11 @@ export class MyAccountVideoSettingsComponent extends FormReactive implements OnI
44 44
45 updateDetails () { 45 updateDetails () {
46 const nsfwPolicy = this.form.value['nsfwPolicy'] 46 const nsfwPolicy = this.form.value['nsfwPolicy']
47 const webTorrentPolicy = this.form.value['webTorrentPolicy'] 47 const webTorrentEnabled = this.form.value['webTorrentEnabled']
48 const autoPlayVideo = this.form.value['autoPlayVideo'] 48 const autoPlayVideo = this.form.value['autoPlayVideo']
49 const details: UserUpdateMe = { 49 const details: UserUpdateMe = {
50 nsfwPolicy, 50 nsfwPolicy,
51 webTorrentPolicy, 51 webTorrentEnabled,
52 autoPlayVideo 52 autoPlayVideo
53 } 53 }
54 54
diff --git a/client/src/app/core/auth/auth-user.model.ts b/client/src/app/core/auth/auth-user.model.ts
index 97acf7bfe..acd13d9c5 100644
--- a/client/src/app/core/auth/auth-user.model.ts
+++ b/client/src/app/core/auth/auth-user.model.ts
@@ -4,7 +4,6 @@ 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'
8 7
9export type TokenOptions = { 8export type TokenOptions = {
10 accessToken: string 9 accessToken: string
@@ -73,7 +72,7 @@ export class AuthUser extends User {
73 EMAIL: 'email', 72 EMAIL: 'email',
74 USERNAME: 'username', 73 USERNAME: 'username',
75 NSFW_POLICY: 'nsfw_policy', 74 NSFW_POLICY: 'nsfw_policy',
76 WEBTORRENT_POLICY: 'peertube-videojs-' + 'webtorrent_policy', 75 WEBTORRENT_ENABLED: 'peertube-videojs-' + 'webtorrent_enabled',
77 AUTO_PLAY_VIDEO: 'auto_play_video' 76 AUTO_PLAY_VIDEO: 'auto_play_video'
78 } 77 }
79 78
@@ -89,7 +88,7 @@ export class AuthUser extends User {
89 email: peertubeLocalStorage.getItem(this.KEYS.EMAIL), 88 email: peertubeLocalStorage.getItem(this.KEYS.EMAIL),
90 role: parseInt(peertubeLocalStorage.getItem(this.KEYS.ROLE), 10) as UserRole, 89 role: parseInt(peertubeLocalStorage.getItem(this.KEYS.ROLE), 10) as UserRole,
91 nsfwPolicy: peertubeLocalStorage.getItem(this.KEYS.NSFW_POLICY) as NSFWPolicyType, 90 nsfwPolicy: peertubeLocalStorage.getItem(this.KEYS.NSFW_POLICY) as NSFWPolicyType,
92 webTorrentPolicy: peertubeLocalStorage.getItem(this.KEYS.WEBTORRENT_POLICY) as WebTorrentPolicyType, 91 webTorrentEnabled: peertubeLocalStorage.getItem(this.KEYS.WEBTORRENT_ENABLED) === 'true',
93 autoPlayVideo: peertubeLocalStorage.getItem(this.KEYS.AUTO_PLAY_VIDEO) === 'true' 92 autoPlayVideo: peertubeLocalStorage.getItem(this.KEYS.AUTO_PLAY_VIDEO) === 'true'
94 }, 93 },
95 Tokens.load() 94 Tokens.load()
@@ -104,7 +103,7 @@ export class AuthUser extends User {
104 peertubeLocalStorage.removeItem(this.KEYS.ID) 103 peertubeLocalStorage.removeItem(this.KEYS.ID)
105 peertubeLocalStorage.removeItem(this.KEYS.ROLE) 104 peertubeLocalStorage.removeItem(this.KEYS.ROLE)
106 peertubeLocalStorage.removeItem(this.KEYS.NSFW_POLICY) 105 peertubeLocalStorage.removeItem(this.KEYS.NSFW_POLICY)
107 peertubeLocalStorage.removeItem(this.KEYS.WEBTORRENT_POLICY) 106 peertubeLocalStorage.removeItem(this.KEYS.WEBTORRENT_ENABLED)
108 peertubeLocalStorage.removeItem(this.KEYS.AUTO_PLAY_VIDEO) 107 peertubeLocalStorage.removeItem(this.KEYS.AUTO_PLAY_VIDEO)
109 peertubeLocalStorage.removeItem(this.KEYS.EMAIL) 108 peertubeLocalStorage.removeItem(this.KEYS.EMAIL)
110 Tokens.flush() 109 Tokens.flush()
@@ -142,7 +141,7 @@ export class AuthUser extends User {
142 peertubeLocalStorage.setItem(AuthUser.KEYS.EMAIL, this.email) 141 peertubeLocalStorage.setItem(AuthUser.KEYS.EMAIL, this.email)
143 peertubeLocalStorage.setItem(AuthUser.KEYS.ROLE, this.role.toString()) 142 peertubeLocalStorage.setItem(AuthUser.KEYS.ROLE, this.role.toString())
144 peertubeLocalStorage.setItem(AuthUser.KEYS.NSFW_POLICY, this.nsfwPolicy.toString()) 143 peertubeLocalStorage.setItem(AuthUser.KEYS.NSFW_POLICY, this.nsfwPolicy.toString())
145 peertubeLocalStorage.setItem(AuthUser.KEYS.WEBTORRENT_POLICY, this.webTorrentPolicy.toString()) 144 peertubeLocalStorage.setItem(AuthUser.KEYS.WEBTORRENT_ENABLED, JSON.stringify(this.webTorrentEnabled))
146 peertubeLocalStorage.setItem(AuthUser.KEYS.AUTO_PLAY_VIDEO, JSON.stringify(this.autoPlayVideo)) 145 peertubeLocalStorage.setItem(AuthUser.KEYS.AUTO_PLAY_VIDEO, JSON.stringify(this.autoPlayVideo))
147 this.tokens.save() 146 this.tokens.save()
148 } 147 }
diff --git a/client/src/app/shared/users/user.model.ts b/client/src/app/shared/users/user.model.ts
index 240c7aacf..7c840ffa7 100644
--- a/client/src/app/shared/users/user.model.ts
+++ b/client/src/app/shared/users/user.model.ts
@@ -9,7 +9,6 @@ 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'
13 12
14export type UserConstructorHash = { 13export type UserConstructorHash = {
15 id: number, 14 id: number,
@@ -19,7 +18,7 @@ export type UserConstructorHash = {
19 videoQuota?: number, 18 videoQuota?: number,
20 videoQuotaDaily?: number, 19 videoQuotaDaily?: number,
21 nsfwPolicy?: NSFWPolicyType, 20 nsfwPolicy?: NSFWPolicyType,
22 webTorrentPolicy?: WebTorrentPolicyType, 21 webTorrentEnabled?: boolean,
23 autoPlayVideo?: boolean, 22 autoPlayVideo?: boolean,
24 createdAt?: Date, 23 createdAt?: Date,
25 account?: AccountServerModel, 24 account?: AccountServerModel,
@@ -34,7 +33,7 @@ export class User implements UserServerModel {
34 email: string 33 email: string
35 role: UserRole 34 role: UserRole
36 nsfwPolicy: NSFWPolicyType 35 nsfwPolicy: NSFWPolicyType
37 webTorrentPolicy: WebTorrentPolicyType 36 webTorrentEnabled: boolean
38 autoPlayVideo: boolean 37 autoPlayVideo: boolean
39 videoQuota: number 38 videoQuota: number
40 videoQuotaDaily: number 39 videoQuotaDaily: number
@@ -55,7 +54,7 @@ export class User implements UserServerModel {
55 this.videoQuota = hash.videoQuota 54 this.videoQuota = hash.videoQuota
56 this.videoQuotaDaily = hash.videoQuotaDaily 55 this.videoQuotaDaily = hash.videoQuotaDaily
57 this.nsfwPolicy = hash.nsfwPolicy 56 this.nsfwPolicy = hash.nsfwPolicy
58 this.webTorrentPolicy = hash.webTorrentPolicy 57 this.webTorrentEnabled = hash.webTorrentEnabled
59 this.autoPlayVideo = hash.autoPlayVideo 58 this.autoPlayVideo = hash.autoPlayVideo
60 this.createdAt = hash.createdAt 59 this.createdAt = hash.createdAt
61 this.blocked = hash.blocked 60 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 c3d8b71bc..3ac5fe58a 100644
--- a/client/src/assets/player/peertube-player-local-storage.ts
+++ b/client/src/assets/player/peertube-player-local-storage.ts
@@ -10,13 +10,11 @@ function getStoredVolume () {
10 return undefined 10 return undefined
11} 11}
12 12
13function getStoredWebTorrentPolicy () { 13function getStoredWebTorrentEnabled (): boolean {
14 const value = getLocalStorage('webtorrent_policy') 14 const value = getLocalStorage('webtorrent_enabled')
15 if (value !== null && value !== undefined) { 15 if (value !== null && value !== undefined) return value === 'true'
16 if (value.toString() === 'disable') return true
17 }
18 16
19 return undefined 17 return false
20} 18}
21 19
22function getStoredMute () { 20function getStoredMute () {
@@ -65,7 +63,7 @@ function getAverageBandwidthInStore () {
65 63
66export { 64export {
67 getStoredVolume, 65 getStoredVolume,
68 getStoredWebTorrentPolicy, 66 getStoredWebTorrentEnabled,
69 getStoredMute, 67 getStoredMute,
70 getStoredTheater, 68 getStoredTheater,
71 saveVolumeInStore, 69 saveVolumeInStore,
diff --git a/client/src/assets/player/peertube-videojs-plugin.ts b/client/src/assets/player/peertube-videojs-plugin.ts
index 90ca8f9fa..a53a2cc69 100644
--- a/client/src/assets/player/peertube-videojs-plugin.ts
+++ b/client/src/assets/player/peertube-videojs-plugin.ts
@@ -8,7 +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 getStoredWebTorrentEnabled,
12 getAverageBandwidthInStore, 12 getAverageBandwidthInStore,
13 getStoredMute, 13 getStoredMute,
14 getStoredVolume, 14 getStoredVolume,
@@ -82,6 +82,7 @@ class PeerTubePlugin extends Plugin {
82 82
83 // Disable auto play on iOS 83 // Disable auto play on iOS
84 this.autoplay = options.autoplay && this.isIOS() === false 84 this.autoplay = options.autoplay && this.isIOS() === false
85 this.playerRefusedP2P = !getStoredWebTorrentEnabled()
85 86
86 this.startTime = timeToInt(options.startTime) 87 this.startTime = timeToInt(options.startTime)
87 this.videoFiles = options.videoFiles 88 this.videoFiles = options.videoFiles
@@ -99,7 +100,6 @@ class PeerTubePlugin extends Plugin {
99 if (volume !== undefined) this.player.volume(volume) 100 if (volume !== undefined) this.player.volume(volume)
100 const muted = getStoredMute() 101 const muted = getStoredMute()
101 if (muted !== undefined) this.player.muted(muted) 102 if (muted !== undefined) this.player.muted(muted)
102 this.playerRefusedP2P = getStoredWebTorrentPolicy() || false
103 103
104 this.initializePlayer() 104 this.initializePlayer()
105 this.runTorrentInfoScheduler() 105 this.runTorrentInfoScheduler()
@@ -291,7 +291,6 @@ class PeerTubePlugin extends Plugin {
291 renderVideo(torrent.files[ 0 ], this.playerElement, renderVideoOptions, (err, renderer) => { 291 renderVideo(torrent.files[ 0 ], this.playerElement, renderVideoOptions, (err, renderer) => {
292 this.renderer = renderer 292 this.renderer = renderer
293 293
294 console.log('value this.playerRefusedP2P', this.playerRefusedP2P)
295 if (err || this.playerRefusedP2P) return this.fallbackToHttp(done) 294 if (err || this.playerRefusedP2P) return this.fallbackToHttp(done)
296 295
297 return this.tryToPlay(err => { 296 return this.tryToPlay(err => {
diff --git a/server/controllers/api/users/me.ts b/server/controllers/api/users/me.ts
index f78294f17..3c511dc70 100644
--- a/server/controllers/api/users/me.ts
+++ b/server/controllers/api/users/me.ts
@@ -327,7 +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.webTorrentEnabled !== undefined) user.webTorrentEnabled = body.webTorrentEnabled
331 if (body.autoPlayVideo !== undefined) user.autoPlayVideo = body.autoPlayVideo 331 if (body.autoPlayVideo !== undefined) user.autoPlayVideo = body.autoPlayVideo
332 332
333 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 2024d4a22..1cb5e5b0f 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, WEBTORRENT_POLICY_TYPES } from '../../initializers' 4import { CONSTRAINTS_FIELDS, NSFW_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,9 +42,8 @@ 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) 45function isUserWebTorrentEnabledValid (value: any) {
46function isUserWebTorrentPolicyValid (value: any) { 46 return isBooleanValid(value)
47 return exists(value) && webTorrentPolicies.indexOf(value) !== -1
48} 47}
49 48
50function isUserAutoPlayVideoValid (value: any) { 49function isUserAutoPlayVideoValid (value: any) {
@@ -83,7 +82,7 @@ export {
83 isUserUsernameValid, 82 isUserUsernameValid,
84 isUserEmailVerifiedValid, 83 isUserEmailVerifiedValid,
85 isUserNSFWPolicyValid, 84 isUserNSFWPolicyValid,
86 isUserWebTorrentPolicyValid, 85 isUserWebTorrentEnabledValid,
87 isUserAutoPlayVideoValid, 86 isUserAutoPlayVideoValid,
88 isUserDisplayNameValid, 87 isUserDisplayNameValid,
89 isUserDescriptionValid, 88 isUserDescriptionValid,
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts
index f56763a16..c3e4fcede 100644
--- a/server/initializers/constants.ts
+++ b/server/initializers/constants.ts
@@ -7,7 +7,6 @@ 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'
11import { invert } from 'lodash' 10import { invert } from 'lodash'
12import { CronRepeatOptions, EveryRepeatOptions } from 'bull' 11import { CronRepeatOptions, EveryRepeatOptions } from 'bull'
13import * as bytes from 'bytes' 12import * as bytes from 'bytes'
@@ -547,12 +546,6 @@ const NSFW_POLICY_TYPES: { [ id: string]: NSFWPolicyType } = {
547 DISPLAY: 'display' 546 DISPLAY: 'display'
548} 547}
549 548
550const WEBTORRENT_POLICY_TYPES: { [ id: string]: WebTorrentPolicyType } = {
551 ENABLE: 'enable',
552 DISABLE: 'disable',
553 DISABLE_ON_MOBILE: 'disable_on_mobile'
554}
555
556// --------------------------------------------------------------------------- 549// ---------------------------------------------------------------------------
557 550
558// Express static paths (router) 551// Express static paths (router)
@@ -705,7 +698,6 @@ export {
705 FEEDS, 698 FEEDS,
706 JOB_TTL, 699 JOB_TTL,
707 NSFW_POLICY_TYPES, 700 NSFW_POLICY_TYPES,
708 WEBTORRENT_POLICY_TYPES,
709 TORRENT_MIMETYPE_EXT, 701 TORRENT_MIMETYPE_EXT,
710 STATIC_MAX_AGE, 702 STATIC_MAX_AGE,
711 STATIC_PATHS, 703 STATIC_PATHS,
diff --git a/server/initializers/migrations/0280-webtorrent-policy-user.ts b/server/initializers/migrations/0280-webtorrent-policy-user.ts
index d24f6709e..e6488356a 100644
--- a/server/initializers/migrations/0280-webtorrent-policy-user.ts
+++ b/server/initializers/migrations/0280-webtorrent-policy-user.ts
@@ -1,6 +1,4 @@
1import * as Sequelize from 'sequelize' 1import * as Sequelize from 'sequelize'
2import { values } from 'lodash'
3import { WEBTORRENT_POLICY_TYPES } from '../constants'
4 2
5async function up (utils: { 3async function up (utils: {
6 transaction: Sequelize.Transaction 4 transaction: Sequelize.Transaction
@@ -9,18 +7,22 @@ async function up (utils: {
9}): Promise<any> { 7}): Promise<any> {
10 { 8 {
11 const data = { 9 const data = {
12 type: Sequelize.ENUM(values(WEBTORRENT_POLICY_TYPES)), 10 type: Sequelize.BOOLEAN,
13 allowNull: false, 11 allowNull: false,
14 defaultValue: 'enable' 12 defaultValue: true
15 } 13 }
16 14
17 await utils.queryInterface.addColumn('user', 'webTorrentPolicy', data) 15 await utils.queryInterface.addColumn('user', 'webTorrentEnabled', data)
18 } 16 }
19 17
20} 18}
21 19
22function down (options) { 20async function down (utils: {
23 throw new Error('Not implemented.') 21 transaction: Sequelize.Transaction
22 queryInterface: Sequelize.QueryInterface
23 sequelize: Sequelize.Sequelize
24}): Promise<any> {
25 await utils.queryInterface.removeColumn('user', 'webTorrentEnabled')
24} 26}
25 27
26export { up, down } 28export { up, down }
diff --git a/server/models/account/user.ts b/server/models/account/user.ts
index 5fe7d7e7d..4b4a562fa 100644
--- a/server/models/account/user.ts
+++ b/server/models/account/user.ts
@@ -32,7 +32,7 @@ import {
32 isUserUsernameValid, 32 isUserUsernameValid,
33 isUserVideoQuotaDailyValid, 33 isUserVideoQuotaDailyValid,
34 isUserVideoQuotaValid, 34 isUserVideoQuotaValid,
35 isUserWebTorrentPolicyValid 35 isUserWebTorrentEnabledValid
36} from '../../helpers/custom-validators/users' 36} from '../../helpers/custom-validators/users'
37import { comparePassword, cryptPassword } from '../../helpers/peertube-crypto' 37import { comparePassword, cryptPassword } from '../../helpers/peertube-crypto'
38import { OAuthTokenModel } from '../oauth/oauth-token' 38import { OAuthTokenModel } from '../oauth/oauth-token'
@@ -40,9 +40,8 @@ import { getSort, throwIfNotValid } from '../utils'
40import { VideoChannelModel } from '../video/video-channel' 40import { VideoChannelModel } from '../video/video-channel'
41import { AccountModel } from './account' 41import { AccountModel } from './account'
42import { 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'
44import { values } from 'lodash' 43import { values } from 'lodash'
45import { NSFW_POLICY_TYPES, WEBTORRENT_POLICY_TYPES } from '../../initializers' 44import { NSFW_POLICY_TYPES } from '../../initializers'
46import { clearCacheByUserId } from '../../lib/oauth-model' 45import { clearCacheByUserId } from '../../lib/oauth-model'
47 46
48enum ScopeNames { 47enum ScopeNames {
@@ -110,9 +109,9 @@ export class UserModel extends Model<UserModel> {
110 nsfwPolicy: NSFWPolicyType 109 nsfwPolicy: NSFWPolicyType
111 110
112 @AllowNull(false) 111 @AllowNull(false)
113 @Is('UserWebTorrentPolicy', value => throwIfNotValid(value, isUserWebTorrentPolicyValid, 'WebTorrent policy')) 112 @Is('UserWebTorrentEnabled', value => throwIfNotValid(value, isUserWebTorrentEnabledValid, 'WebTorrent enabled'))
114 @Column(DataType.ENUM(values(WEBTORRENT_POLICY_TYPES))) 113 @Column
115 webTorrentPolicy: WebTorrentPolicyType 114 webTorrentEnabled: boolean
116 115
117 @AllowNull(false) 116 @AllowNull(false)
118 @Default(true) 117 @Default(true)
@@ -362,7 +361,7 @@ export class UserModel extends Model<UserModel> {
362 email: this.email, 361 email: this.email,
363 emailVerified: this.emailVerified, 362 emailVerified: this.emailVerified,
364 nsfwPolicy: this.nsfwPolicy, 363 nsfwPolicy: this.nsfwPolicy,
365 webTorrentPolicy: this.webTorrentPolicy, 364 webTorrentEnabled: this.webTorrentEnabled,
366 autoPlayVideo: this.autoPlayVideo, 365 autoPlayVideo: this.autoPlayVideo,
367 role: this.role, 366 role: this.role,
368 roleLabel: USER_ROLE_LABELS[ this.role ], 367 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 81790377e..10edeee2e 100644
--- a/shared/models/users/user-update-me.model.ts
+++ b/shared/models/users/user-update-me.model.ts
@@ -1,11 +1,10 @@
1import { NSFWPolicyType } from '../videos/nsfw-policy.type' 1import { NSFWPolicyType } from '../videos/nsfw-policy.type'
2import { WebTorrentPolicyType } from './user-webtorrent-policy.type'
3 2
4export interface UserUpdateMe { 3export interface UserUpdateMe {
5 displayName?: string 4 displayName?: string
6 description?: string 5 description?: string
7 nsfwPolicy?: NSFWPolicyType, 6 nsfwPolicy?: NSFWPolicyType,
8 webTorrentPolicy?: WebTorrentPolicyType, 7 webTorrentEnabled?: boolean,
9 autoPlayVideo?: boolean 8 autoPlayVideo?: boolean
10 email?: string 9 email?: string
11 currentPassword?: string 10 currentPassword?: string
diff --git a/shared/models/users/user-webtorrent-policy.type.ts b/shared/models/users/user-webtorrent-policy.type.ts
deleted file mode 100644
index e293f761d..000000000
--- a/shared/models/users/user-webtorrent-policy.type.ts
+++ /dev/null
@@ -1 +0,0 @@
1export type WebTorrentPolicyType = 'enable' | 'disable' | 'disable_on_mobile'