diff --git a/core/app.js b/core/app.js index c90b96fc..b51ef753 100644 --- a/core/app.js +++ b/core/app.js @@ -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); diff --git a/core/core.js b/core/core.js index f82879fa..1091b300 100644 --- a/core/core.js +++ b/core/core.js @@ -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; } } diff --git a/src/task.c b/src/task.c index f25146c9..6dcdbf60 100644 --- a/src/task.c +++ b/src/task.c @@ -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]);