From e9fc30afda1d2975eccc45495c4c4c401e53dbcb Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Fri, 12 Aug 2022 14:41:37 +0100 Subject: [PATCH] Overwrite existing plugins of the same name and version --- packages/server/src/api/controllers/plugin.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/packages/server/src/api/controllers/plugin.ts b/packages/server/src/api/controllers/plugin.ts index f76d2871b0..4afa59cd3a 100644 --- a/packages/server/src/api/controllers/plugin.ts +++ b/packages/server/src/api/controllers/plugin.ts @@ -32,19 +32,18 @@ export async function upload(ctx: any) { } const jsFileName = jsFile.name const pluginId = generatePluginID(name, version) - let existing + + // overwrite existing docs entirely if they exist + let rev try { - existing = await db.get(pluginId) + const existing = await db.get(pluginId) + rev = existing._rev } catch (err) { - existing = null - } - if (existing) { - throw new Error( - `Plugin already exists: name: ${name}, version: ${version}` - ) + rev = null } const doc = { _id: pluginId, + _rev: rev, name, version, description,