diff --git a/src/apps.js b/src/apps.js index b45a54ca1..04e8205b7 100644 --- a/src/apps.js +++ b/src/apps.js @@ -171,6 +171,7 @@ const appTaskManager = require('./apptaskmanager.js'), logs = require('./logs.js'), mail = require('./mail.js'), manifestFormat = require('@cloudron/manifest-format'), + mysql = require('mysql2'), notifications = require('./notifications.js'), once = require('./once.js'), path = require('node:path'), @@ -1133,11 +1134,13 @@ async function del(id) { { query: 'DELETE FROM appEnvVars WHERE appId = ?', args: [ id ] }, { query: 'DELETE FROM appPasswords WHERE identifier = ?', args: [ id ] }, { query: 'DELETE FROM appMounts WHERE appId = ?', args: [ id ] }, + // this removes double quoted "appId" with optional trailing comma from the JSON + { query: `UPDATE backupSites SET contentsJson = REGEXP_REPLACE(contentsJson, ${mysql.escape('"' + id + '"(,)?')}, '') WHERE contentsJson LIKE ${mysql.escape('%"' + id + '"%')}`, args: [] }, { query: 'DELETE FROM apps WHERE id = ?', args: [ id ] } ]; const results = await database.transaction(queries); - if (results[5].affectedRows !== 1) throw new BoxError(BoxError.NOT_FOUND, 'App not found'); + if (results[6].affectedRows !== 1) throw new BoxError(BoxError.NOT_FOUND, 'App not found'); } async function clear() {