diff options
author | Rigel Kent <sendmemail@rigelk.eu> | 2018-10-05 15:17:34 +0200 |
---|---|---|
committer | Rigel Kent <sendmemail@rigelk.eu> | 2018-10-13 11:53:42 +0200 |
commit | 64cc5e8575fda47b281ae20abf0020e27fc8ce7c (patch) | |
tree | c3ec40b03d3fdc5d3beee9ff089384c894d9efe9 /server | |
parent | 0e5ff97f6fdf9a4cebe5a15f5a390380465803ad (diff) | |
download | PeerTube-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
Diffstat (limited to 'server')
-rw-r--r-- | server/controllers/api/users/me.ts | 1 | ||||
-rw-r--r-- | server/helpers/custom-validators/users.ts | 8 | ||||
-rw-r--r-- | server/initializers/constants.ts | 10 | ||||
-rw-r--r-- | server/initializers/migrations/0280-webtorrent-policy-user.ts | 26 | ||||
-rw-r--r-- | server/models/account/user.ts | 12 |
5 files changed, 53 insertions, 4 deletions
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 @@ | |||
1 | import 'express-validator' | 1 | import 'express-validator' |
2 | import * as validator from 'validator' | 2 | import * as validator from 'validator' |
3 | import { UserRole } from '../../../shared' | 3 | import { UserRole } from '../../../shared' |
4 | import { CONSTRAINTS_FIELDS, NSFW_POLICY_TYPES } from '../../initializers' | 4 | import { CONSTRAINTS_FIELDS, NSFW_POLICY_TYPES, WEBTORRENT_POLICY_TYPES } from '../../initializers' |
5 | import { exists, isFileValid, isBooleanValid } from './misc' | 5 | import { exists, isFileValid, isBooleanValid } from './misc' |
6 | import { values } from 'lodash' | 6 | import { 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 | ||
45 | const webTorrentPolicies = values(WEBTORRENT_POLICY_TYPES) | ||
46 | function isUserWebTorrentPolicyValid (value: any) { | ||
47 | return exists(value) && webTorrentPolicies.indexOf(value) !== -1 | ||
48 | } | ||
49 | |||
45 | function isUserAutoPlayVideoValid (value: any) { | 50 | function 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 |
8 | import { buildPath, isTestInstance, parseDuration, parseBytes, root, sanitizeHost, sanitizeUrl } from '../helpers/core-utils' | 8 | import { buildPath, isTestInstance, parseDuration, parseBytes, root, sanitizeHost, sanitizeUrl } from '../helpers/core-utils' |
9 | import { NSFWPolicyType } from '../../shared/models/videos/nsfw-policy.type' | 9 | import { NSFWPolicyType } from '../../shared/models/videos/nsfw-policy.type' |
10 | import { WebTorrentPolicyType } from '../../shared/models/users/user-webtorrent-policy.type' | ||
10 | import { invert } from 'lodash' | 11 | import { invert } from 'lodash' |
11 | import { CronRepeatOptions, EveryRepeatOptions } from 'bull' | 12 | import { CronRepeatOptions, EveryRepeatOptions } from 'bull' |
12 | import * as bytes from 'bytes' | 13 | import * as bytes from 'bytes' |
@@ -16,7 +17,7 @@ let config: IConfig = require('config') | |||
16 | 17 | ||
17 | // --------------------------------------------------------------------------- | 18 | // --------------------------------------------------------------------------- |
18 | 19 | ||
19 | const LAST_MIGRATION_VERSION = 275 | 20 | const 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 | ||
550 | const 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 @@ | |||
1 | import * as Sequelize from 'sequelize' | ||
2 | import { values } from 'lodash' | ||
3 | import { WEBTORRENT_POLICY_TYPES } from '../constants' | ||
4 | |||
5 | async 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 | |||
22 | function down (options) { | ||
23 | throw new Error('Not implemented.') | ||
24 | } | ||
25 | |||
26 | export { 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' |
36 | import { comparePassword, cryptPassword } from '../../helpers/peertube-crypto' | 37 | import { comparePassword, cryptPassword } from '../../helpers/peertube-crypto' |
37 | import { OAuthTokenModel } from '../oauth/oauth-token' | 38 | import { OAuthTokenModel } from '../oauth/oauth-token' |
@@ -39,8 +40,9 @@ import { getSort, throwIfNotValid } from '../utils' | |||
39 | import { VideoChannelModel } from '../video/video-channel' | 40 | import { VideoChannelModel } from '../video/video-channel' |
40 | import { AccountModel } from './account' | 41 | import { AccountModel } from './account' |
41 | import { NSFWPolicyType } from '../../../shared/models/videos/nsfw-policy.type' | 42 | import { NSFWPolicyType } from '../../../shared/models/videos/nsfw-policy.type' |
43 | import { WebTorrentPolicyType } from '../../../shared/models/users/user-webtorrent-policy.type' | ||
42 | import { values } from 'lodash' | 44 | import { values } from 'lodash' |
43 | import { NSFW_POLICY_TYPES } from '../../initializers' | 45 | import { NSFW_POLICY_TYPES, WEBTORRENT_POLICY_TYPES } from '../../initializers' |
44 | import { clearCacheByUserId } from '../../lib/oauth-model' | 46 | import { clearCacheByUserId } from '../../lib/oauth-model' |
45 | 47 | ||
46 | enum ScopeNames { | 48 | enum 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 ], |