diff --git a/core/app.js b/core/app.js index c5c9f9c3..e237646c 100644 --- a/core/app.js +++ b/core/app.js @@ -68,17 +68,17 @@ function socket(request, response, client) { if (match = /^\/([&%][^\.]{44}(?:\.\w+)?)(\/?.*)/.exec(message.path)) { blobId = match[1]; } else if (match = /^\/\~([^\/]+)\/([^\/]+)\/$/.exec(message.path)) { - var user = match[1]; - var path = match[2]; - blobId = await new Database(user).get('path:' + path); + packageOwner = match[1]; + packageName = match[2]; + blobId = await new Database(packageOwner).get('path:' + packageName); if (!blobId) { response.send(JSON.stringify({action: "error", error: message.path + ' not found'}), 0x1); return; } - if (user != 'core') { - var coreId = await new Database('core').get('path:' + path); + if (packageOwner != 'core') { + var coreId = await new Database('core').get('path:' + packageName); parentApp = { - path: '/~core/' + path + '/', + path: '/~core/' + packageName + '/', id: coreId, }; } @@ -92,6 +92,8 @@ function socket(request, response, client) { options.api = message.api || []; options.credentials = credentials; + options.packageOwner = packageOwner; + options.packageName = packageName; var sessionId = makeSessionId(); if (blobId) { process = await getSessionProcessBlob(blobId, sessionId, options); diff --git a/core/core.js b/core/core.js index 94aa7841..c03663be 100644 --- a/core/core.js +++ b/core/core.js @@ -221,6 +221,12 @@ async function getProcessBlob(blobId, key, options) { return Object.fromEntries(Object.keys(db).map(x => [x, db[x].bind(db)])); }; } + if (options.packageOwner && options.packageName) { + imports.shared_database = function(key) { + var db = new Database(':shared:' + options.packageOwner + ':' + options.packageName + ':' + key); + return Object.fromEntries(Object.keys(db).map(x => [x, db[x].bind(db)])); + } + } process.task.setImports(imports); process.task.activate(); let source = await getBlobOrContent(blobId);