From bee29df8a9ba3090be3daa8ff806dd9a26d7a5cf Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Wed, 11 Dec 2019 20:20:42 +0100 Subject: autoplay next video support for playlists --- server/controllers/api/users/me.ts | 1 + server/helpers/custom-validators/users.ts | 5 ++++ server/initializers/constants.ts | 2 +- .../migrations/0460-user-playlist-autoplay.ts | 27 ++++++++++++++++++++++ server/models/account/user.ts | 8 +++++++ 5 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 server/initializers/migrations/0460-user-playlist-autoplay.ts (limited to 'server') diff --git a/server/controllers/api/users/me.ts b/server/controllers/api/users/me.ts index cfc346c35..ba976ab03 100644 --- a/server/controllers/api/users/me.ts +++ b/server/controllers/api/users/me.ts @@ -176,6 +176,7 @@ async function updateMe (req: express.Request, res: express.Response) { if (body.webTorrentEnabled !== undefined) user.webTorrentEnabled = body.webTorrentEnabled if (body.autoPlayVideo !== undefined) user.autoPlayVideo = body.autoPlayVideo if (body.autoPlayNextVideo !== undefined) user.autoPlayNextVideo = body.autoPlayNextVideo + if (body.autoPlayNextVideoPlaylist !== undefined) user.autoPlayNextVideoPlaylist = body.autoPlayNextVideoPlaylist if (body.videosHistoryEnabled !== undefined) user.videosHistoryEnabled = body.videosHistoryEnabled if (body.videoLanguages !== undefined) user.videoLanguages = body.videoLanguages if (body.theme !== undefined) user.theme = body.theme diff --git a/server/helpers/custom-validators/users.ts b/server/helpers/custom-validators/users.ts index 16a95f120..008916a04 100644 --- a/server/helpers/custom-validators/users.ts +++ b/server/helpers/custom-validators/users.ts @@ -69,6 +69,10 @@ function isUserAutoPlayNextVideoValid (value: any) { return isBooleanValid(value) } +function isUserAutoPlayNextVideoPlaylistValid (value: any) { + return isBooleanValid(value) +} + function isNoInstanceConfigWarningModal (value: any) { return isBooleanValid(value) } @@ -111,6 +115,7 @@ export { isUserWebTorrentEnabledValid, isUserAutoPlayVideoValid, isUserAutoPlayNextVideoValid, + isUserAutoPlayNextVideoPlaylistValid, isUserDisplayNameValid, isUserDescriptionValid, isNoInstanceConfigWarningModal, diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index d0cf4d5de..00238f7a1 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts @@ -14,7 +14,7 @@ import { CONFIG, registerConfigChangedHandler } from './config' // --------------------------------------------------------------------------- -const LAST_MIGRATION_VERSION = 455 +const LAST_MIGRATION_VERSION = 460 // --------------------------------------------------------------------------- diff --git a/server/initializers/migrations/0460-user-playlist-autoplay.ts b/server/initializers/migrations/0460-user-playlist-autoplay.ts new file mode 100644 index 000000000..3067ac1a4 --- /dev/null +++ b/server/initializers/migrations/0460-user-playlist-autoplay.ts @@ -0,0 +1,27 @@ +import * as Sequelize from 'sequelize' + +async function up (utils: { + transaction: Sequelize.Transaction, + queryInterface: Sequelize.QueryInterface, + sequelize: Sequelize.Sequelize, + db: any +}): Promise { + { + const data = { + type: Sequelize.BOOLEAN, + allowNull: false, + defaultValue: true + } + + await utils.queryInterface.addColumn('user', 'autoPlayNextVideoPlaylist', data) + } +} + +function down (options) { + throw new Error('Not implemented.') +} + +export { + up, + down +} diff --git a/server/models/account/user.ts b/server/models/account/user.ts index 522ea3310..b2cd25bc3 100644 --- a/server/models/account/user.ts +++ b/server/models/account/user.ts @@ -26,6 +26,7 @@ import { isUserAdminFlagsValid, isUserAutoPlayVideoValid, isUserAutoPlayNextVideoValid, + isUserAutoPlayNextVideoPlaylistValid, isUserBlockedReasonValid, isUserBlockedValid, isUserEmailVerifiedValid, @@ -167,6 +168,12 @@ export class UserModel extends Model { @Column autoPlayNextVideo: boolean + @AllowNull(false) + @Default(true) + @Is('UserAutoPlayNextVideoPlaylist', value => throwIfNotValid(value, isUserAutoPlayNextVideoPlaylistValid, 'auto play next video for playlists boolean')) + @Column + autoPlayNextVideoPlaylist: boolean + @AllowNull(true) @Default(null) @Is('UserVideoLanguages', value => throwIfNotValid(value, isUserVideoLanguages, 'video languages')) @@ -619,6 +626,7 @@ export class UserModel extends Model { videosHistoryEnabled: this.videosHistoryEnabled, autoPlayVideo: this.autoPlayVideo, autoPlayNextVideo: this.autoPlayNextVideo, + autoPlayNextVideoPlaylist: this.autoPlayNextVideoPlaylist, videoLanguages: this.videoLanguages, role: this.role, -- cgit v1.2.3