diff --git a/core/core.js b/core/core.js index 00facd834..49793fd7e 100644 --- a/core/core.js +++ b/core/core.js @@ -193,12 +193,17 @@ async function getProcessBlob(blobId, key, options) { 'getUser': getUser.bind(null, process, process), 'user': getUser(process, process), 'apps': function() { - var apps = process.credentials && + if (process.credentials && process.credentials.session && - process.credentials.session.name ? - new Database(process.credentials.session.name).getLike('path:%') : - {}; - return Object.fromEntries(Object.keys(apps).map(key => [key.substring(5), apps[key]])); + process.credentials.session.name) { + var db = new Database(process.credentials.session.name); + try { + var names = JSON.parse(db.get('apps')); + return Object.fromEntries(names.map(name => [name, db.get('path:' + name)])); + } catch { + } + } + return {}; }, } }; @@ -478,7 +483,16 @@ async function blobHandler(request, response, blobId, uri) { return; } var database = new Database(user); - await database.set('path:' + app, newBlobId); + var apps = new Set(); + try { + apps = new Set(JSON.parse(database.get('apps'))); + } catch { + } + if (!apps.has(app)) { + apps.add(app); + database.set('apps', JSON.stringify([...apps])); + } + database.set('path:' + app, newBlobId); } response.writeHead(200, {"Content-Type": "text/plain; charset=utf-8"});