Move data/global/settings.json into the database. Improved some error plumbing along the way.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3775 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2022-01-18 02:50:46 +00:00
parent 0b5017b208
commit 1515525a1b
3 changed files with 37 additions and 13 deletions

View File

@ -60,6 +60,7 @@ function socket(request, response, client) {
blobId = await new Database(user).get('path:' + path);
if (!blobId) {
response.send(JSON.stringify({action: "error", error: message.path + ' not found'}), 0x1);
return;
}
}
response.send(JSON.stringify({action: "session", credentials: credentials}), 0x1);

View File

@ -275,16 +275,13 @@ function makeDirectoryForFile(fileName) {
}
}
function getGlobalSettings() {
return gGlobalSettings;
}
function setGlobalSettings(settings) {
makeDirectoryForFile(kGlobalSettingsFile);
gGlobalSettings = settings;
return File.writeFile(kGlobalSettingsFile, JSON.stringify(settings)).catch(function(error) {
throw new Error("Unable to save settings: " + error);
});
try {
return new Database('core').set('settings', JSON.stringify(settings));
} catch (error) {
print('Error storing settings:', error);
}
}
var kStaticFiles = [
@ -540,13 +537,28 @@ ssb.addEventListener('connections', function() {
});
async function loadSettings() {
var data;
try {
var data = await readFileUtf8(kGlobalSettingsFile);
if (data) {
gGlobalSettings = JSON.parse(data);
var settings = new Database('core').get('settings');
if (settings) {
data = JSON.parse(settings);
}
} catch (error) {
print("Error loading settings from " + kGlobalSettingsFile + ":", error);
print("Settings not found in database:", error);
}
if (!data) {
try {
data = JSON.parse(await readFileUtf8(kGlobalSettingsFile));
new Database('core').set('settings', JSON.stringify(data));
} catch (error) {
print("Unable to load settings from " + kGlobalSettingsFile + ":", error);
}
}
if (data) {
gGlobalSettings = data;
}
}

View File

@ -1158,7 +1158,18 @@ void tf_task_reject_promise(tf_task_t* task, promiseid_t promise, JSValue value)
promise_t* it = _tf_task_find_promise(task, promise);
if (it)
{
JSValue result = JS_Call(task->_context, it->values[2], JS_UNDEFINED, 1, &value);
JSValue arg = value;
bool free_arg = false;
if (JS_IsException(value))
{
arg = JS_GetException(task->_context);
free_arg = true;
}
JSValue result = JS_Call(task->_context, it->values[2], JS_UNDEFINED, 1, &arg);
if (free_arg)
{
JS_FreeValue(task->_context, arg);
}
tf_util_report_error(task->_context, result);
JS_FreeValue(task->_context, it->values[1]);
JS_FreeValue(task->_context, it->values[2]);