Expose shared_database(), which provides access to data that is specific to the app owner and app and can be written for any visitor.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3860 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
parent
352f33f5a1
commit
5e0c20e432
14
core/app.js
14
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);
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user