Delete some old things from core, mostly.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3838 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2022-02-13 22:03:12 +00:00
parent 5ffc505ce2
commit e4e763b7a0

View File

@ -101,16 +101,25 @@ function getUser(caller, process) {
}; };
} }
function getUsers(packageOwner, packageName) { function getApps(user, process) {
var result = []; if (process.credentials &&
for (var key in gProcesses) { process.credentials.session &&
var process = gProcesses[key]; process.credentials.session.name) {
if ((!packageOwner || process.packageOwner == packageOwner) if (user && user !== process.credentials.session.name && user !== 'core') {
&& (!packageName || process.packageName == packageName)) { return {};
result.push(getUser(this, process)); } 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) { function postMessageInternal(from, to, message) {
@ -129,12 +138,6 @@ async function getSessionProcessBlob(blobId, session, options) {
return getProcessBlob(blobId, 'session_' + session, actualOptions); return getProcessBlob(blobId, 'session_' + session, actualOptions);
} }
async function readFileUtf8(fileName) {
let data = await File.readFile(fileName);
data = utf8Decode(data);
return data;
}
let gManifestCache = {}; let gManifestCache = {};
async function getProcessBlob(blobId, key, options) { async function getProcessBlob(blobId, key, options) {
@ -169,7 +172,6 @@ async function getProcessBlob(blobId, key, options) {
var imports = { var imports = {
'core': { 'core': {
'broadcast': broadcast.bind(process), 'broadcast': broadcast.bind(process),
'getUsers': getUsers.bind(process),
'register': function(eventName, handler) { 'register': function(eventName, handler) {
if (!process.eventHandlers[eventName]) { if (!process.eventHandlers[eventName]) {
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), 'user': getUser(process, process),
'apps': function(name) { 'apps': user => getApps(user, process),
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 {};
},
} }
}; };
if (options.api) { if (options.api) {
@ -271,20 +253,10 @@ async function getProcessBlob(blobId, key, options) {
return process; 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) { function setGlobalSettings(settings) {
gGlobalSettings = settings; gGlobalSettings = settings;
try { try {
return new Database('core').set('settings', JSON.stringify(settings)); return new Database('core').set('settings', JSON.stringify(settings));
} catch (error) { } catch (error) {
print('Error storing settings:', error); print('Error storing settings:', error);
} }
@ -560,7 +532,7 @@ async function loadSettings() {
if (!data) { if (!data) {
try { try {
data = JSON.parse(await readFileUtf8(kGlobalSettingsFile)); data = JSON.parse(utf8Decode(await File.readFile(kGlobalSettingsFile)));
new Database('core').set('settings', JSON.stringify(data)); new Database('core').set('settings', JSON.stringify(data));
} catch (error) { } catch (error) {
print("Unable to load settings from " + kGlobalSettingsFile + ":", error); print("Unable to load settings from " + kGlobalSettingsFile + ":", error);