feat(logging): implement centralized logging system and replace console errors with structured logs
feat(federation): add room sync and deletion notification endpoints for federated instances fix(federation): handle room deletion and update settings during sync process feat(federation): enhance FederatedRoomCard and FederatedRoomDetail components to display deleted rooms i18n: add translations for room deletion messages in English and German
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import crypto from 'crypto';
|
||||
import xml2js from 'xml2js';
|
||||
import { log, fmtDuration, fmtStatus, fmtMethod, fmtReturncode, sanitizeBBBParams } from './logger.js';
|
||||
|
||||
const BBB_URL = process.env.BBB_URL || 'https://your-bbb-server.com/bigbluebutton/api/';
|
||||
const BBB_SECRET = process.env.BBB_SECRET || '';
|
||||
@@ -18,39 +19,7 @@ function buildUrl(apiCall, params = {}) {
|
||||
|
||||
async function apiCall(apiCallName, params = {}, xmlBody = null) {
|
||||
const url = buildUrl(apiCallName, params);
|
||||
// Logging: compact key=value style, filter sensitive params
|
||||
function formatUTC(d) {
|
||||
const pad = n => String(n).padStart(2, '0');
|
||||
const Y = d.getUTCFullYear();
|
||||
const M = pad(d.getUTCMonth() + 1);
|
||||
const D = pad(d.getUTCDate());
|
||||
const h = pad(d.getUTCHours());
|
||||
const m = pad(d.getUTCMinutes());
|
||||
const s = pad(d.getUTCSeconds());
|
||||
return `${Y}-${M}-${D} ${h}:${m}:${s} UTC`;
|
||||
}
|
||||
|
||||
const SENSITIVE_KEYS = [/pass/i, /pwd/i, /password/i, /token/i, /jwt/i, /secret/i, /authorization/i, /auth/i, /api[_-]?key/i];
|
||||
const isSensitive = key => SENSITIVE_KEYS.some(rx => rx.test(key));
|
||||
|
||||
function sanitizeParams(p) {
|
||||
try {
|
||||
const out = [];
|
||||
for (const k of Object.keys(p || {})) {
|
||||
if (k.toLowerCase() === 'checksum') continue; // never log checksum
|
||||
if (isSensitive(k)) {
|
||||
out.push(`${k}=[FILTERED]`);
|
||||
} else {
|
||||
let v = p[k];
|
||||
if (typeof v === 'string' && v.length > 100) v = v.slice(0, 100) + '...[truncated]';
|
||||
out.push(`${k}=${String(v)}`);
|
||||
}
|
||||
}
|
||||
return out.join('&') || '-';
|
||||
} catch (e) {
|
||||
return '-';
|
||||
}
|
||||
}
|
||||
const method = xmlBody ? 'POST' : 'GET';
|
||||
|
||||
const start = Date.now();
|
||||
try {
|
||||
@@ -65,38 +34,20 @@ async function apiCall(apiCallName, params = {}, xmlBody = null) {
|
||||
trim: true,
|
||||
});
|
||||
|
||||
// Compact log: time=... method=GET path=getMeetings format=xml status=200 duration=12.34 bbb_returncode=SUCCESS params=meetingID=123
|
||||
try {
|
||||
const tokens = [];
|
||||
tokens.push(`time=${formatUTC(new Date())}`);
|
||||
tokens.push(`method=${xmlBody ? 'POST' : 'GET'}`);
|
||||
// include standard BBB api base path
|
||||
let apiBasePath = '/bigbluebutton/api';
|
||||
try {
|
||||
const u = new URL(BBB_URL);
|
||||
apiBasePath = (u.pathname || '/bigbluebutton/api').replace(/\/$/, '');
|
||||
} catch (e) {
|
||||
// keep default
|
||||
}
|
||||
// ensure single slash separation
|
||||
const fullPath = `${apiBasePath}/${apiCallName}`.replace(/\/\/+/, '/');
|
||||
tokens.push(`path=${fullPath}`);
|
||||
tokens.push(`format=xml`);
|
||||
tokens.push(`status=${response.status}`);
|
||||
tokens.push(`duration=${(duration).toFixed(2)}`);
|
||||
const returnCode = result && result.response && result.response.returncode ? result.response.returncode : '-';
|
||||
tokens.push(`returncode=${returnCode}`);
|
||||
const safeParams = sanitizeParams(params);
|
||||
tokens.push(`params=${safeParams}`);
|
||||
console.info(tokens.join(' '));
|
||||
} catch (e) {
|
||||
// ignore logging errors
|
||||
}
|
||||
const returncode = result?.response?.returncode || '-';
|
||||
const paramStr = sanitizeBBBParams(params);
|
||||
|
||||
// Greenlight-style: method action → status returncode (duration) params
|
||||
log.bbb.info(
|
||||
`${fmtMethod(method)} ${apiCallName} → ${fmtStatus(response.status)} ${fmtReturncode(returncode)} (${fmtDuration(duration)}) ${paramStr}`
|
||||
);
|
||||
|
||||
return result.response;
|
||||
} catch (error) {
|
||||
const duration = Date.now() - start;
|
||||
console.error(`BBB API error (${apiCallName}) status=error duration=${(duration).toFixed(2)} err=${error.message}`);
|
||||
log.bbb.error(
|
||||
`${fmtMethod(method)} ${apiCallName} ✗ FAILED (${fmtDuration(duration)}) ${error.message}`
|
||||
);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user