Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cce1f2f0fd |
92
api/index.js
92
api/index.js
@@ -1528,16 +1528,12 @@ function handleAdminResponseData(responseData) {
|
||||
function handleConfigQueryResponse(responseData) {
|
||||
console.log('=== CONFIG QUERY RESPONSE ===');
|
||||
console.log('Query type:', responseData.query_type);
|
||||
console.log('Total results:', responseData.total_results);
|
||||
console.log('Data:', responseData.data);
|
||||
console.log('Data type:', typeof responseData.data);
|
||||
console.log('Is array:', Array.isArray(responseData.data));
|
||||
console.log('Count:', responseData.count);
|
||||
console.log('Config:', responseData.config);
|
||||
console.log('Config type:', typeof responseData.config);
|
||||
|
||||
// Check if data exists and has content (handle both object and array formats)
|
||||
const hasData = responseData.data && (
|
||||
(Array.isArray(responseData.data) && responseData.data.length > 0) ||
|
||||
(!Array.isArray(responseData.data) && Object.keys(responseData.data).length > 0)
|
||||
);
|
||||
// Backend returns config as an object with nested objects: {key1: {value: 'x', description: 'y'}, ...}
|
||||
const hasData = responseData.config && Object.keys(responseData.config).length > 0;
|
||||
|
||||
if (hasData) {
|
||||
console.log('Converting config response to display format...');
|
||||
@@ -1552,24 +1548,13 @@ function handleConfigQueryResponse(responseData) {
|
||||
tags: []
|
||||
};
|
||||
|
||||
// Convert config data to tags format - handle both array and object formats
|
||||
if (Array.isArray(responseData.data)) {
|
||||
// Array format: [{key: 'x', value: 'y'}, ...]
|
||||
responseData.data.forEach(config => {
|
||||
const key = config.key || config.config_key;
|
||||
const value = config.value || config.config_value;
|
||||
if (key && value !== undefined) {
|
||||
syntheticEvent.tags.push([key, value]);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// Object format: {key1: 'value1', key2: 'value2', ...}
|
||||
Object.entries(responseData.data).forEach(([key, value]) => {
|
||||
if (key && value !== undefined) {
|
||||
syntheticEvent.tags.push([key, value]);
|
||||
}
|
||||
});
|
||||
}
|
||||
// Convert config object to tags format
|
||||
// Backend format: {key1: {value: 'x', description: 'y'}, key2: {value: 'z'}, ...}
|
||||
Object.entries(responseData.config).forEach(([key, configEntry]) => {
|
||||
if (key && configEntry && configEntry.value !== undefined) {
|
||||
syntheticEvent.tags.push([key, configEntry.value]);
|
||||
}
|
||||
});
|
||||
|
||||
console.log('Synthetic event created:', syntheticEvent);
|
||||
console.log('Calling displayConfiguration with synthetic event...');
|
||||
@@ -1583,9 +1568,7 @@ function handleConfigQueryResponse(responseData) {
|
||||
// Initialize toggle buttons with config data
|
||||
initializeToggleButtonsFromConfig(responseData);
|
||||
|
||||
const configCount = Array.isArray(responseData.data) ?
|
||||
responseData.data.length :
|
||||
Object.keys(responseData.data).length;
|
||||
const configCount = responseData.count || Object.keys(responseData.config).length;
|
||||
log(`Configuration loaded: ${configCount} parameters`, 'INFO');
|
||||
} else {
|
||||
console.log('No configuration data received');
|
||||
@@ -1594,17 +1577,14 @@ function handleConfigQueryResponse(responseData) {
|
||||
|
||||
// Also log to test interface for debugging
|
||||
if (typeof logTestEvent === 'function') {
|
||||
logTestEvent('RECV', `Config query response: ${responseData.query_type}, ${responseData.total_results} results`, 'CONFIG_QUERY');
|
||||
logTestEvent('RECV', `Config query response: ${responseData.query_type}, ${responseData.count} results`, 'CONFIG_QUERY');
|
||||
|
||||
if (responseData.data && responseData.data.length > 0) {
|
||||
if (responseData.config && Object.keys(responseData.config).length > 0) {
|
||||
logTestEvent('RECV', '=== CONFIGURATION VALUES ===', 'CONFIG');
|
||||
responseData.data.forEach((config, index) => {
|
||||
const key = config.key || config.config_key || `config_${index}`;
|
||||
const value = config.value || config.config_value || 'undefined';
|
||||
const category = config.category || 'general';
|
||||
const dataType = config.data_type || 'string';
|
||||
|
||||
logTestEvent('RECV', `${key}: ${value} (${dataType}, ${category})`, 'CONFIG');
|
||||
Object.entries(responseData.config).forEach(([key, configEntry]) => {
|
||||
const value = configEntry.value || 'undefined';
|
||||
const description = configEntry.description || '';
|
||||
logTestEvent('RECV', `${key}: ${value} ${description ? '(' + description + ')' : ''}`, 'CONFIG');
|
||||
});
|
||||
logTestEvent('RECV', '=== END CONFIGURATION VALUES ===', 'CONFIG');
|
||||
} else {
|
||||
@@ -1968,8 +1948,9 @@ async function saveIndividualConfig(key, newValue, originalValue, actionsCell) {
|
||||
actionsCell.style.cursor = 'not-allowed';
|
||||
actionsCell.onclick = null;
|
||||
|
||||
// Send single config update
|
||||
await sendConfigUpdateCommand([configObj]);
|
||||
// Send single config update via HTTP POST
|
||||
const responseData = await sendAdminCommandHTTP(['config_update', [configObj]]);
|
||||
handleConfigUpdateResponse(responseData);
|
||||
|
||||
// Update the original value on success
|
||||
const input = actionsCell.parentElement.cells[1].querySelector('input');
|
||||
@@ -3688,19 +3669,17 @@ function getRelayInfo() {
|
||||
|
||||
// Update stored relay info when config is loaded
|
||||
function updateStoredRelayInfo(configData) {
|
||||
if (configData && configData.data) {
|
||||
// Extract relay info from config data - handle both object and array formats
|
||||
if (configData && configData.config) {
|
||||
// Extract relay info from config data
|
||||
// Backend format: {key1: {value: 'x', description: 'y'}, ...}
|
||||
let relayName = 'Blossom';
|
||||
let relayDescription = 'Blob Storage Server';
|
||||
|
||||
if (Array.isArray(configData.data)) {
|
||||
// Array format: [{key: 'x', value: 'y'}, ...]
|
||||
relayName = configData.data.find(item => item.key === 'relay_name')?.value || 'Blossom';
|
||||
relayDescription = configData.data.find(item => item.key === 'relay_description')?.value || 'Blob Storage Server';
|
||||
} else {
|
||||
// Object format: {key1: 'value1', key2: 'value2', ...}
|
||||
relayName = configData.data.relay_name || 'Blossom';
|
||||
relayDescription = configData.data.relay_description || 'Blob Storage Server';
|
||||
if (configData.config.relay_name) {
|
||||
relayName = configData.config.relay_name.value || 'Blossom';
|
||||
}
|
||||
if (configData.config.relay_description) {
|
||||
relayDescription = configData.config.relay_description.value || 'Blob Storage Server';
|
||||
}
|
||||
|
||||
relayInfoData = {
|
||||
@@ -4825,13 +4804,16 @@ function closeSideNav() {
|
||||
}
|
||||
|
||||
function switchPage(pageName) {
|
||||
// Stop statistics polling if leaving statistics page
|
||||
if (currentPage === 'statistics' && pageName !== 'statistics') {
|
||||
stopStatsPolling();
|
||||
}
|
||||
// Keep statistics polling running in background regardless of page
|
||||
// (removed stopStatsPolling call - stats continue updating)
|
||||
|
||||
// Update current page
|
||||
currentPage = pageName;
|
||||
|
||||
// Start statistics polling if switching TO statistics page and not already running
|
||||
if (pageName === 'statistics' && !statsAutoRefreshInterval) {
|
||||
startStatsPolling();
|
||||
}
|
||||
|
||||
// Update navigation active state
|
||||
const navItems = document.querySelectorAll('.nav-item');
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
build/main.o
BIN
build/main.o
Binary file not shown.
Binary file not shown.
@@ -181,16 +181,23 @@ cJSON* admin_cmd_config_query(cJSON* args) {
|
||||
return response;
|
||||
}
|
||||
|
||||
// Check if specific keys were requested (args[1] should be array of keys or null for all)
|
||||
// Check if specific keys were requested (args[1] should be array of keys, null, or "all" for all)
|
||||
cJSON* keys_array = NULL;
|
||||
if (cJSON_GetArraySize(args) >= 2) {
|
||||
keys_array = cJSON_GetArrayItem(args, 1);
|
||||
// Accept array, null, or string "all" for querying all configs
|
||||
if (!cJSON_IsArray(keys_array) && !cJSON_IsNull(keys_array)) {
|
||||
cJSON_AddStringToObject(response, "status", "error");
|
||||
cJSON_AddStringToObject(response, "error", "Keys parameter must be array or null");
|
||||
cJSON_AddNumberToObject(response, "timestamp", (double)time(NULL));
|
||||
sqlite3_close(db);
|
||||
return response;
|
||||
// Check if it's the string "all"
|
||||
if (cJSON_IsString(keys_array) && strcmp(keys_array->valuestring, "all") == 0) {
|
||||
// Treat "all" as null (query all configs)
|
||||
keys_array = NULL;
|
||||
} else {
|
||||
cJSON_AddStringToObject(response, "status", "error");
|
||||
cJSON_AddStringToObject(response, "error", "Keys parameter must be array, null, or \"all\"");
|
||||
cJSON_AddNumberToObject(response, "timestamp", (double)time(NULL));
|
||||
sqlite3_close(db);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -273,18 +280,18 @@ cJSON* admin_cmd_config_update(cJSON* args) {
|
||||
cJSON* response = cJSON_CreateObject();
|
||||
cJSON_AddStringToObject(response, "query_type", "config_update");
|
||||
|
||||
// Expected format: ["config_update", {"key1": "value1", "key2": "value2"}]
|
||||
// Expected format: ["config_update", [{key: "x", value: "y", data_type: "z", category: "w"}]]
|
||||
if (cJSON_GetArraySize(args) < 2) {
|
||||
cJSON_AddStringToObject(response, "status", "error");
|
||||
cJSON_AddStringToObject(response, "error", "Missing config updates object");
|
||||
cJSON_AddStringToObject(response, "error", "Missing config updates array");
|
||||
cJSON_AddNumberToObject(response, "timestamp", (double)time(NULL));
|
||||
return response;
|
||||
}
|
||||
|
||||
cJSON* updates = cJSON_GetArrayItem(args, 1);
|
||||
if (!cJSON_IsObject(updates)) {
|
||||
if (!cJSON_IsArray(updates)) {
|
||||
cJSON_AddStringToObject(response, "status", "error");
|
||||
cJSON_AddStringToObject(response, "error", "Updates must be an object");
|
||||
cJSON_AddStringToObject(response, "error", "Updates must be an array of config objects");
|
||||
cJSON_AddNumberToObject(response, "timestamp", (double)time(NULL));
|
||||
return response;
|
||||
}
|
||||
@@ -311,50 +318,66 @@ cJSON* admin_cmd_config_update(cJSON* args) {
|
||||
return response;
|
||||
}
|
||||
|
||||
// Process each update
|
||||
cJSON* updated_keys = cJSON_CreateArray();
|
||||
cJSON* failed_keys = cJSON_CreateArray();
|
||||
// Process each update - expecting array of config objects
|
||||
cJSON* data_array = cJSON_CreateArray();
|
||||
int success_count = 0;
|
||||
int fail_count = 0;
|
||||
|
||||
cJSON* item = NULL;
|
||||
cJSON_ArrayForEach(item, updates) {
|
||||
const char* key = item->string;
|
||||
const char* value = cJSON_GetStringValue(item);
|
||||
|
||||
if (!value) {
|
||||
cJSON_AddItemToArray(failed_keys, cJSON_CreateString(key));
|
||||
cJSON* config_obj = NULL;
|
||||
cJSON_ArrayForEach(config_obj, updates) {
|
||||
if (!cJSON_IsObject(config_obj)) {
|
||||
fail_count++;
|
||||
continue;
|
||||
}
|
||||
|
||||
cJSON* key_item = cJSON_GetObjectItem(config_obj, "key");
|
||||
cJSON* value_item = cJSON_GetObjectItem(config_obj, "value");
|
||||
|
||||
if (!cJSON_IsString(key_item) || !cJSON_IsString(value_item)) {
|
||||
fail_count++;
|
||||
continue;
|
||||
}
|
||||
|
||||
const char* key = key_item->valuestring;
|
||||
const char* value = value_item->valuestring;
|
||||
|
||||
sqlite3_reset(stmt);
|
||||
sqlite3_bind_text(stmt, 1, value, -1, SQLITE_TRANSIENT);
|
||||
sqlite3_bind_text(stmt, 2, key, -1, SQLITE_TRANSIENT);
|
||||
|
||||
rc = sqlite3_step(stmt);
|
||||
|
||||
// Create result object for this config update
|
||||
cJSON* result_obj = cJSON_CreateObject();
|
||||
cJSON_AddStringToObject(result_obj, "key", key);
|
||||
|
||||
if (rc == SQLITE_DONE && sqlite3_changes(db) > 0) {
|
||||
cJSON_AddItemToArray(updated_keys, cJSON_CreateString(key));
|
||||
cJSON_AddStringToObject(result_obj, "status", "success");
|
||||
cJSON_AddStringToObject(result_obj, "value", value);
|
||||
|
||||
// Add optional fields if present
|
||||
cJSON* data_type_item = cJSON_GetObjectItem(config_obj, "data_type");
|
||||
if (cJSON_IsString(data_type_item)) {
|
||||
cJSON_AddStringToObject(result_obj, "data_type", data_type_item->valuestring);
|
||||
}
|
||||
|
||||
success_count++;
|
||||
app_log(LOG_INFO, "Updated config key: %s", key);
|
||||
app_log(LOG_INFO, "Updated config key: %s = %s", key, value);
|
||||
} else {
|
||||
cJSON_AddItemToArray(failed_keys, cJSON_CreateString(key));
|
||||
cJSON_AddStringToObject(result_obj, "status", "error");
|
||||
cJSON_AddStringToObject(result_obj, "error", "Failed to update");
|
||||
fail_count++;
|
||||
}
|
||||
|
||||
cJSON_AddItemToArray(data_array, result_obj);
|
||||
}
|
||||
|
||||
sqlite3_finalize(stmt);
|
||||
sqlite3_close(db);
|
||||
|
||||
cJSON_AddStringToObject(response, "status", "success");
|
||||
cJSON_AddNumberToObject(response, "updated_count", success_count);
|
||||
cJSON_AddNumberToObject(response, "failed_count", fail_count);
|
||||
cJSON_AddItemToObject(response, "updated_keys", updated_keys);
|
||||
if (fail_count > 0) {
|
||||
cJSON_AddItemToObject(response, "failed_keys", failed_keys);
|
||||
} else {
|
||||
cJSON_Delete(failed_keys);
|
||||
}
|
||||
cJSON_AddStringToObject(response, "status", success_count > 0 ? "success" : "error");
|
||||
cJSON_AddNumberToObject(response, "updates_applied", success_count);
|
||||
cJSON_AddItemToObject(response, "data", data_array);
|
||||
cJSON_AddNumberToObject(response, "timestamp", (double)time(NULL));
|
||||
|
||||
return response;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -10,8 +10,8 @@
|
||||
// Version information (auto-updated by build system)
|
||||
#define VERSION_MAJOR 0
|
||||
#define VERSION_MINOR 1
|
||||
#define VERSION_PATCH 20
|
||||
#define VERSION "v0.1.20"
|
||||
#define VERSION_PATCH 21
|
||||
#define VERSION "v0.1.21"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
Reference in New Issue
Block a user