From e4e763b7a05f8b632a738e7a29fdb8819795889a Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Sun, 13 Feb 2022 22:03:12 +0000 Subject: [PATCH] Delete some old things from core, mostly. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3838 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- core/core.js | 68 ++++++++++++++++------------------------------------ 1 file changed, 20 insertions(+), 48 deletions(-) diff --git a/core/core.js b/core/core.js index 0a9344c2..d43b0ef6 100644 --- a/core/core.js +++ b/core/core.js @@ -101,16 +101,25 @@ function getUser(caller, process) { }; } -function getUsers(packageOwner, packageName) { - var result = []; - for (var key in gProcesses) { - var process = gProcesses[key]; - if ((!packageOwner || process.packageOwner == packageOwner) - && (!packageName || process.packageName == packageName)) { - result.push(getUser(this, process)); +function getApps(user, process) { + if (process.credentials && + process.credentials.session && + process.credentials.session.name) { + if (user && user !== process.credentials.session.name && user !== 'core') { + return {}; + } else if (!user) { + user = process.credentials.session.name; } } - return result; + if (user) { + var db = new Database(user); + try { + var names = JSON.parse(db.get('apps')); + return Object.fromEntries(names.map(name => [name, db.get('path:' + name)])); + } catch { + } + } + return {}; } function postMessageInternal(from, to, message) { @@ -129,12 +138,6 @@ async function getSessionProcessBlob(blobId, session, options) { return getProcessBlob(blobId, 'session_' + session, actualOptions); } -async function readFileUtf8(fileName) { - let data = await File.readFile(fileName); - data = utf8Decode(data); - return data; -} - let gManifestCache = {}; async function getProcessBlob(blobId, key, options) { @@ -169,7 +172,6 @@ async function getProcessBlob(blobId, key, options) { var imports = { 'core': { 'broadcast': broadcast.bind(process), - 'getUsers': getUsers.bind(process), 'register': function(eventName, handler) { if (!process.eventHandlers[eventName]) { process.eventHandlers[eventName] = []; @@ -187,28 +189,8 @@ async function getProcessBlob(blobId, key, options) { } } }, - 'getUser': getUser.bind(null, process, process), 'user': getUser(process, process), - 'apps': function(name) { - if (process.credentials && - process.credentials.session && - process.credentials.session.name) { - if (name && name !== process.credentials.session.name && name !== 'core') { - return {}; - } else if (!name) { - name = process.credentials.session.name; - } - } - if (name) { - var db = new Database(name); - try { - var names = JSON.parse(db.get('apps')); - return Object.fromEntries(names.map(name => [name, db.get('path:' + name)])); - } catch { - } - } - return {}; - }, + 'apps': user => getApps(user, process), } }; if (options.api) { @@ -271,20 +253,10 @@ async function getProcessBlob(blobId, key, options) { return process; } -function makeDirectoryForFile(fileName) { - var parts = fileName.split("/"); - var path = ""; - for (var i = 0; i < parts.length - 1; i++) { - path += parts[i]; - File.makeDirectory(path); - path += "/"; - } -} - function setGlobalSettings(settings) { gGlobalSettings = settings; try { - return new Database('core').set('settings', JSON.stringify(settings)); + return new Database('core').set('settings', JSON.stringify(settings)); } catch (error) { print('Error storing settings:', error); } @@ -560,7 +532,7 @@ async function loadSettings() { if (!data) { try { - data = JSON.parse(await readFileUtf8(kGlobalSettingsFile)); + data = JSON.parse(utf8Decode(await File.readFile(kGlobalSettingsFile))); new Database('core').set('settings', JSON.stringify(data)); } catch (error) { print("Unable to load settings from " + kGlobalSettingsFile + ":", error);