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