v0.1.21 - Fixed some web page errors. About to clean out websocket functions in index.js. Last push before we do this.
This commit is contained in:
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');
|
||||
|
||||
Reference in New Issue
Block a user