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:
parent
0b5017b208
commit
1515525a1b
@ -60,6 +60,7 @@ function socket(request, response, client) {
|
|||||||
blobId = await new Database(user).get('path:' + path);
|
blobId = await new Database(user).get('path:' + path);
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
response.send(JSON.stringify({action: "session", credentials: credentials}), 0x1);
|
response.send(JSON.stringify({action: "session", credentials: credentials}), 0x1);
|
||||||
|
36
core/core.js
36
core/core.js
@ -275,16 +275,13 @@ function makeDirectoryForFile(fileName) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getGlobalSettings() {
|
|
||||||
return gGlobalSettings;
|
|
||||||
}
|
|
||||||
|
|
||||||
function setGlobalSettings(settings) {
|
function setGlobalSettings(settings) {
|
||||||
makeDirectoryForFile(kGlobalSettingsFile);
|
|
||||||
gGlobalSettings = settings;
|
gGlobalSettings = settings;
|
||||||
return File.writeFile(kGlobalSettingsFile, JSON.stringify(settings)).catch(function(error) {
|
try {
|
||||||
throw new Error("Unable to save settings: " + error);
|
return new Database('core').set('settings', JSON.stringify(settings));
|
||||||
});
|
} catch (error) {
|
||||||
|
print('Error storing settings:', error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var kStaticFiles = [
|
var kStaticFiles = [
|
||||||
@ -540,13 +537,28 @@ ssb.addEventListener('connections', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
async function loadSettings() {
|
async function loadSettings() {
|
||||||
|
var data;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var data = await readFileUtf8(kGlobalSettingsFile);
|
var settings = new Database('core').get('settings');
|
||||||
if (data) {
|
if (settings) {
|
||||||
gGlobalSettings = JSON.parse(data);
|
data = JSON.parse(settings);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
13
src/task.c
13
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);
|
promise_t* it = _tf_task_find_promise(task, promise);
|
||||||
if (it)
|
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);
|
tf_util_report_error(task->_context, result);
|
||||||
JS_FreeValue(task->_context, it->values[1]);
|
JS_FreeValue(task->_context, it->values[1]);
|
||||||
JS_FreeValue(task->_context, it->values[2]);
|
JS_FreeValue(task->_context, it->values[2]);
|
||||||
|
Loading…
Reference in New Issue
Block a user