From 64cc5e8575fda47b281ae20abf0020e27fc8ce7c Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Fri, 5 Oct 2018 15:17:34 +0200 Subject: add webtorrent opt-out settings - add a key in localstorage to remember the opt-out - add a user setting --- server/initializers/constants.ts | 10 ++++++++- .../migrations/0280-webtorrent-policy-user.ts | 26 ++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 server/initializers/migrations/0280-webtorrent-policy-user.ts (limited to 'server/initializers') 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 } // Do not use barrels, remain constants as independent as possible import { buildPath, isTestInstance, parseDuration, parseBytes, root, sanitizeHost, sanitizeUrl } from '../helpers/core-utils' import { NSFWPolicyType } from '../../shared/models/videos/nsfw-policy.type' +import { WebTorrentPolicyType } from '../../shared/models/users/user-webtorrent-policy.type' import { invert } from 'lodash' import { CronRepeatOptions, EveryRepeatOptions } from 'bull' import * as bytes from 'bytes' @@ -16,7 +17,7 @@ let config: IConfig = require('config') // --------------------------------------------------------------------------- -const LAST_MIGRATION_VERSION = 275 +const LAST_MIGRATION_VERSION = 280 // --------------------------------------------------------------------------- @@ -546,6 +547,12 @@ const NSFW_POLICY_TYPES: { [ id: string]: NSFWPolicyType } = { DISPLAY: 'display' } +const WEBTORRENT_POLICY_TYPES: { [ id: string]: WebTorrentPolicyType } = { + ENABLE: 'enable', + DISABLE: 'disable', + DISABLE_ON_MOBILE: 'disable_on_mobile' +} + // --------------------------------------------------------------------------- // Express static paths (router) @@ -698,6 +705,7 @@ export { FEEDS, JOB_TTL, NSFW_POLICY_TYPES, + WEBTORRENT_POLICY_TYPES, TORRENT_MIMETYPE_EXT, STATIC_MAX_AGE, 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 @@ +import * as Sequelize from 'sequelize' +import { values } from 'lodash' +import { WEBTORRENT_POLICY_TYPES } from '../constants' + +async function up (utils: { + transaction: Sequelize.Transaction + queryInterface: Sequelize.QueryInterface + sequelize: Sequelize.Sequelize +}): Promise { + { + const data = { + type: Sequelize.ENUM(values(WEBTORRENT_POLICY_TYPES)), + allowNull: false, + defaultValue: 'enable' + } + + await utils.queryInterface.addColumn('user', 'webTorrentPolicy', data) + } + +} + +function down (options) { + throw new Error('Not implemented.') +} + +export { up, down } -- cgit v1.2.3 From ed638e5325096ef580da20f370ac61c59cd48cf7 Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Fri, 12 Oct 2018 18:12:39 +0200 Subject: move to boolean switch --- server/initializers/constants.ts | 8 -------- .../migrations/0280-webtorrent-policy-user.ts | 16 +++++++++------- 2 files changed, 9 insertions(+), 15 deletions(-) (limited to 'server/initializers') 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 } // Do not use barrels, remain constants as independent as possible import { buildPath, isTestInstance, parseDuration, parseBytes, root, sanitizeHost, sanitizeUrl } from '../helpers/core-utils' import { NSFWPolicyType } from '../../shared/models/videos/nsfw-policy.type' -import { WebTorrentPolicyType } from '../../shared/models/users/user-webtorrent-policy.type' import { invert } from 'lodash' import { CronRepeatOptions, EveryRepeatOptions } from 'bull' import * as bytes from 'bytes' @@ -547,12 +546,6 @@ const NSFW_POLICY_TYPES: { [ id: string]: NSFWPolicyType } = { DISPLAY: 'display' } -const WEBTORRENT_POLICY_TYPES: { [ id: string]: WebTorrentPolicyType } = { - ENABLE: 'enable', - DISABLE: 'disable', - DISABLE_ON_MOBILE: 'disable_on_mobile' -} - // --------------------------------------------------------------------------- // Express static paths (router) @@ -705,7 +698,6 @@ export { FEEDS, JOB_TTL, NSFW_POLICY_TYPES, - WEBTORRENT_POLICY_TYPES, TORRENT_MIMETYPE_EXT, STATIC_MAX_AGE, 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 @@ import * as Sequelize from 'sequelize' -import { values } from 'lodash' -import { WEBTORRENT_POLICY_TYPES } from '../constants' async function up (utils: { transaction: Sequelize.Transaction @@ -9,18 +7,22 @@ async function up (utils: { }): Promise { { const data = { - type: Sequelize.ENUM(values(WEBTORRENT_POLICY_TYPES)), + type: Sequelize.BOOLEAN, allowNull: false, - defaultValue: 'enable' + defaultValue: true } - await utils.queryInterface.addColumn('user', 'webTorrentPolicy', data) + await utils.queryInterface.addColumn('user', 'webTorrentEnabled', data) } } -function down (options) { - throw new Error('Not implemented.') +async function down (utils: { + transaction: Sequelize.Transaction + queryInterface: Sequelize.QueryInterface + sequelize: Sequelize.Sequelize +}): Promise { + await utils.queryInterface.removeColumn('user', 'webTorrentEnabled') } export { up, down } -- cgit v1.2.3