From 32a18cbf33a7cdbbe3d4885d32e4b67e19cdc1cf Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 11 Mar 2021 16:54:52 +0100 Subject: Add new plugin/peertube version notifs --- server/initializers/checker-before-init.ts | 1 + server/initializers/config.ts | 6 +++ server/initializers/constants.ts | 4 +- .../migrations/0610-views-index copy.ts | 20 ++++++++++ server/initializers/migrations/0610-views-index.ts | 20 ---------- .../0615-latest-versions-notification-settings.ts | 44 ++++++++++++++++++++++ .../migrations/0620-latest-versions-application.ts | 27 +++++++++++++ .../0625-latest-versions-notification.ts | 26 +++++++++++++ 8 files changed, 127 insertions(+), 21 deletions(-) create mode 100644 server/initializers/migrations/0610-views-index copy.ts delete mode 100644 server/initializers/migrations/0610-views-index.ts create mode 100644 server/initializers/migrations/0615-latest-versions-notification-settings.ts create mode 100644 server/initializers/migrations/0620-latest-versions-application.ts create mode 100644 server/initializers/migrations/0625-latest-versions-notification.ts (limited to 'server/initializers') diff --git a/server/initializers/checker-before-init.ts b/server/initializers/checker-before-init.ts index 65a019ca6..e92cc4d2c 100644 --- a/server/initializers/checker-before-init.ts +++ b/server/initializers/checker-before-init.ts @@ -37,6 +37,7 @@ function checkMissedConfig () { 'theme.default', 'remote_redundancy.videos.accept_from', 'federation.videos.federate_unlisted', 'federation.videos.cleanup_remote_interactions', + 'peertube.check_latest_version.enabled', 'peertube.check_latest_version.url', 'search.remote_uri.users', 'search.remote_uri.anonymous', 'search.search_index.enabled', 'search.search_index.url', 'search.search_index.disable_local_search', 'search.search_index.is_default_search', 'live.enabled', 'live.allow_replay', 'live.max_duration', 'live.max_user_lives', 'live.max_instance_lives', diff --git a/server/initializers/config.ts b/server/initializers/config.ts index c16b63c33..48e7f7397 100644 --- a/server/initializers/config.ts +++ b/server/initializers/config.ts @@ -163,6 +163,12 @@ const CONFIG = { CLEANUP_REMOTE_INTERACTIONS: config.get('federation.videos.cleanup_remote_interactions') } }, + PEERTUBE: { + CHECK_LATEST_VERSION: { + ENABLED: config.get('peertube.check_latest_version.enabled'), + URL: config.get('peertube.check_latest_version.url') + } + }, ADMIN: { get EMAIL () { return config.get('admin.email') } }, diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index ea98e8a38..b37aeb622 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts @@ -24,7 +24,7 @@ import { CONFIG, registerConfigChangedHandler } from './config' // --------------------------------------------------------------------------- -const LAST_MIGRATION_VERSION = 610 +const LAST_MIGRATION_VERSION = 625 // --------------------------------------------------------------------------- @@ -207,6 +207,7 @@ const SCHEDULER_INTERVALS_MS = { updateVideos: 60000, // 1 minute youtubeDLUpdate: 60000 * 60 * 24, // 1 day checkPlugins: CONFIG.PLUGINS.INDEX.CHECK_LATEST_VERSIONS_INTERVAL, + checkPeerTubeVersion: 60000 * 60 * 24, // 1 day autoFollowIndexInstances: 60000 * 60 * 24, // 1 day removeOldViews: 60000 * 60 * 24, // 1 day removeOldHistory: 60000 * 60 * 24, // 1 day @@ -763,6 +764,7 @@ if (isTestInstance() === true) { SCHEDULER_INTERVALS_MS.updateVideos = 5000 SCHEDULER_INTERVALS_MS.autoFollowIndexInstances = 5000 SCHEDULER_INTERVALS_MS.updateInboxStats = 5000 + SCHEDULER_INTERVALS_MS.checkPeerTubeVersion = 2000 REPEAT_JOBS['videos-views'] = { every: 5000 } REPEAT_JOBS['activitypub-cleaner'] = { every: 5000 } diff --git a/server/initializers/migrations/0610-views-index copy.ts b/server/initializers/migrations/0610-views-index copy.ts new file mode 100644 index 000000000..02ee21172 --- /dev/null +++ b/server/initializers/migrations/0610-views-index copy.ts @@ -0,0 +1,20 @@ +import * as Sequelize from 'sequelize' + +async function up (utils: { + transaction: Sequelize.Transaction + queryInterface: Sequelize.QueryInterface + sequelize: Sequelize.Sequelize + db: any +}): Promise { + + await utils.sequelize.query('DROP INDEX IF EXISTS video_views;') +} + +function down (options) { + throw new Error('Not implemented.') +} + +export { + up, + down +} diff --git a/server/initializers/migrations/0610-views-index.ts b/server/initializers/migrations/0610-views-index.ts deleted file mode 100644 index 02ee21172..000000000 --- a/server/initializers/migrations/0610-views-index.ts +++ /dev/null @@ -1,20 +0,0 @@ -import * as Sequelize from 'sequelize' - -async function up (utils: { - transaction: Sequelize.Transaction - queryInterface: Sequelize.QueryInterface - sequelize: Sequelize.Sequelize - db: any -}): Promise { - - await utils.sequelize.query('DROP INDEX IF EXISTS video_views;') -} - -function down (options) { - throw new Error('Not implemented.') -} - -export { - up, - down -} diff --git a/server/initializers/migrations/0615-latest-versions-notification-settings.ts b/server/initializers/migrations/0615-latest-versions-notification-settings.ts new file mode 100644 index 000000000..86bf56009 --- /dev/null +++ b/server/initializers/migrations/0615-latest-versions-notification-settings.ts @@ -0,0 +1,44 @@ +import * as Sequelize from 'sequelize' + +async function up (utils: { + transaction: Sequelize.Transaction + queryInterface: Sequelize.QueryInterface + sequelize: Sequelize.Sequelize + db: any +}): Promise { + { + const notificationSettingColumns = [ 'newPeerTubeVersion', 'newPluginVersion' ] + + for (const column of notificationSettingColumns) { + const data = { + type: Sequelize.INTEGER, + defaultValue: null, + allowNull: true + } + await utils.queryInterface.addColumn('userNotificationSetting', column, data) + } + + { + const query = 'UPDATE "userNotificationSetting" SET "newPeerTubeVersion" = 3, "newPluginVersion" = 1' + await utils.sequelize.query(query) + } + + for (const column of notificationSettingColumns) { + const data = { + type: Sequelize.INTEGER, + defaultValue: null, + allowNull: false + } + await utils.queryInterface.changeColumn('userNotificationSetting', column, data) + } + } +} + +function down (options) { + throw new Error('Not implemented.') +} + +export { + up, + down +} diff --git a/server/initializers/migrations/0620-latest-versions-application.ts b/server/initializers/migrations/0620-latest-versions-application.ts new file mode 100644 index 000000000..a689b18fc --- /dev/null +++ b/server/initializers/migrations/0620-latest-versions-application.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.STRING, + defaultValue: null, + allowNull: true + } + await utils.queryInterface.addColumn('application', 'latestPeerTubeVersion', data) + } +} + +function down (options) { + throw new Error('Not implemented.') +} + +export { + up, + down +} diff --git a/server/initializers/migrations/0625-latest-versions-notification.ts b/server/initializers/migrations/0625-latest-versions-notification.ts new file mode 100644 index 000000000..77f395ce4 --- /dev/null +++ b/server/initializers/migrations/0625-latest-versions-notification.ts @@ -0,0 +1,26 @@ +import * as Sequelize from 'sequelize' + +async function up (utils: { + transaction: Sequelize.Transaction + queryInterface: Sequelize.QueryInterface + sequelize: Sequelize.Sequelize + db: any +}): Promise { + + { + await utils.sequelize.query(` + ALTER TABLE "userNotification" + ADD COLUMN "applicationId" INTEGER REFERENCES "application" ("id") ON DELETE SET NULL ON UPDATE CASCADE, + ADD COLUMN "pluginId" INTEGER REFERENCES "plugin" ("id") ON DELETE SET NULL ON UPDATE CASCADE + `) + } +} + +function down (options) { + throw new Error('Not implemented.') +} + +export { + up, + down +} -- cgit v1.2.3