forked from cory/tildefriends
		
	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:
		
							
								
								
									
										14
									
								
								core/app.js
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								core/app.js
									
									
									
									
									
								
							| @@ -68,17 +68,17 @@ function socket(request, response, client) { | |||||||
| 				if (match = /^\/([&%][^\.]{44}(?:\.\w+)?)(\/?.*)/.exec(message.path)) { | 				if (match = /^\/([&%][^\.]{44}(?:\.\w+)?)(\/?.*)/.exec(message.path)) { | ||||||
| 					blobId = match[1]; | 					blobId = match[1]; | ||||||
| 				} else if (match = /^\/\~([^\/]+)\/([^\/]+)\/$/.exec(message.path)) { | 				} else if (match = /^\/\~([^\/]+)\/([^\/]+)\/$/.exec(message.path)) { | ||||||
| 					var user = match[1]; | 					packageOwner = match[1]; | ||||||
| 					var path = match[2]; | 					packageName = match[2]; | ||||||
| 					blobId = await new Database(user).get('path:' + path); | 					blobId = await new Database(packageOwner).get('path:' + packageName); | ||||||
| 					if (!blobId) { | 					if (!blobId) { | ||||||
| 						response.send(JSON.stringify({action: "error", error: message.path + ' not found'}), 0x1); | 						response.send(JSON.stringify({action: "error", error: message.path + ' not found'}), 0x1); | ||||||
| 						return; | 						return; | ||||||
| 					} | 					} | ||||||
| 					if (user != 'core') { | 					if (packageOwner != 'core') { | ||||||
| 						var coreId = await new Database('core').get('path:' + path); | 						var coreId = await new Database('core').get('path:' + packageName); | ||||||
| 						parentApp = { | 						parentApp = { | ||||||
| 							path: '/~core/' + path + '/', | 							path: '/~core/' + packageName + '/', | ||||||
| 							id: coreId, | 							id: coreId, | ||||||
| 						}; | 						}; | ||||||
| 					} | 					} | ||||||
| @@ -92,6 +92,8 @@ function socket(request, response, client) { | |||||||
|  |  | ||||||
| 				options.api = message.api || []; | 				options.api = message.api || []; | ||||||
| 				options.credentials = credentials; | 				options.credentials = credentials; | ||||||
|  | 				options.packageOwner = packageOwner; | ||||||
|  | 				options.packageName = packageName; | ||||||
| 				var sessionId = makeSessionId(); | 				var sessionId = makeSessionId(); | ||||||
| 				if (blobId) { | 				if (blobId) { | ||||||
| 					process = await getSessionProcessBlob(blobId, sessionId, options); | 					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)])); | 					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.setImports(imports); | ||||||
| 			process.task.activate(); | 			process.task.activate(); | ||||||
| 			let source = await getBlobOrContent(blobId); | 			let source = await getBlobOrContent(blobId); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user