Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Add plugin table migration table

Chocobozzz587568e1cc0e
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts
index 1111fd97f3..5329d5fabb 100644
--- a/server/initializers/constants.ts
+++ b/server/initializers/constants.ts
@@ -14,7 +14,7 @@ import { CONFIG, registerConfigChangedHandler } from './config'
// ---------------------------------------------------------------------------
-const LAST_MIGRATION_VERSION = 400
+const LAST_MIGRATION_VERSION = 405
// ---------------------------------------------------------------------------
diff --git a/server/initializers/migrations/0405-plugin.ts b/server/initializers/migrations/0405-plugin.ts
new file mode 100644
index 0000000000..c55b819602
--- /dev/null
+++ b/server/initializers/migrations/0405-plugin.ts
@@ -0,0 +1,40 @@
+import * as Sequelize from 'sequelize'
+
+async function up (utils: {
+ transaction: Sequelize.Transaction,
+ queryInterface: Sequelize.QueryInterface,
+ sequelize: Sequelize.Sequelize,
+ db: any
+}): Promise<void> {
+ {
+ const query = `
+CREATE TABLE IF NOT EXISTS "plugin"
+(
+ "id" SERIAL,
+ "name" VARCHAR(255) NOT NULL,
+ "type" INTEGER NOT NULL,
+ "version" VARCHAR(255) NOT NULL,
+ "latestVersion" VARCHAR(255),
+ "enabled" BOOLEAN NOT NULL,
+ "uninstalled" BOOLEAN NOT NULL,
+ "peertubeEngine" VARCHAR(255) NOT NULL,
+ "description" VARCHAR(255),
+ "homepage" VARCHAR(255) NOT NULL,
+ "settings" JSONB,
+ "storage" JSONB,
+ "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL,
+ "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL,
+ PRIMARY KEY ("id")
+);`
+ await utils.sequelize.query(query)
+ }
+}
+
+function down (options) {
+ throw new Error('Not implemented.')
+}
+
+export {
+ up,
+ down
+}
diff --git a/server/lib/plugins/hooks.ts b/server/lib/plugins/hooks.ts
index b694d4118f..bcc8c674ec 100644
--- a/server/lib/plugins/hooks.ts
+++ b/server/lib/plugins/hooks.ts
@@ -9,7 +9,7 @@ type RawFunction <U, T> = (params: U) => T
// Helpers to run hooks
const Hooks = {
wrapObject: <T, U extends ServerFilterHookName>(result: T, hookName: U) => {
- return PluginManager.Instance.runHook(hookName, result) as Promise<T>
+ return PluginManager.Instance.runHook(hookName, result)
},
wrapPromiseFun: async <U, T, V extends ServerFilterHookName>(fun: PromiseFunction<U, T>, params: U, hookName: V) => {
diff --git a/server/lib/plugins/plugin-manager.ts b/server/lib/plugins/plugin-manager.ts
index 6485a47c51..afc07a1511 100644
--- a/server/lib/plugins/plugin-manager.ts
+++ b/server/lib/plugins/plugin-manager.ts
@@ -125,6 +125,13 @@ export class PluginManager implements ServerHook {
try {
await this.registerPluginOrTheme(plugin)
} catch (err) {
+ // Try to unregister the plugin
+ try {
+ await this.unregister(PluginModel.buildNpmName(plugin.name, plugin.type))
+ } catch {
+ // we don't care if we cannot unregister it
+ }
+
logger.error('Cannot register plugin %s, skipping.', plugin.name, { err })
}
}
diff --git a/server/tests/plugins/action-hooks.ts b/server/tests/plugins/action-hooks.ts
index 2a941148a4..e28732caca 100644
--- a/server/tests/plugins/action-hooks.ts
+++ b/server/tests/plugins/action-hooks.ts
@@ -43,7 +43,7 @@ describe('Test plugin action hooks', function () {
path: getPluginTestPath()
})
- await killallServers([ servers[0] ])
+ killallServers([ servers[0] ])
await reRunServer(servers[0])
})
diff --git a/shared/core-utils/plugins/hooks.ts b/shared/core-utils/plugins/hooks.ts
index 60f4130f5b..3d59a7428d 100644
--- a/shared/core-utils/plugins/hooks.ts
+++ b/shared/core-utils/plugins/hooks.ts
@@ -8,7 +8,7 @@ function getHookType (hookName: string) {
return HookType.STATIC
}
-async function internalRunHook <T>(handler: Function, hookType: HookType, result: T, params: any, onError: (err: Error) => void) {
+async function internalRunHook <T> (handler: Function, hookType: HookType, result: T, params: any, onError: (err: Error) => void) {
try {
if (hookType === HookType.FILTER) {
const p = handler(result, params)