addition of archive server listing

This commit is contained in:
2026-08-26 11:22:52 +00:00
parent bf59249ed7
commit a239a76cc7
4 changed files with 67 additions and 2 deletions

53
backend/common/archive.js Normal file
View File

@@ -0,0 +1,53 @@
import axios from "axios";
import { getPool } from "../db/index.js";
export async function getArchiveServers(config) {
if (!config.archiveList || config.archiveList == "false") {
return;
}
const client = await getPool();
try {
const settingsResult = await client.query(`
SELECT id FROM system.settings LIMIT 1
`);
if (settingsResult.rows.length === 0) {
return;
}
const sessionId = settingsResult.rows[0].id;
const result = await client.query(`
SELECT
(SELECT COUNT(*)::int FROM public.agreement) AS agreement,
(SELECT COUNT(*)::int FROM public.audit) AS audit,
(SELECT COUNT(*)::int FROM public.entity) AS entity,
(SELECT COUNT(*)::int FROM public.event) AS event,
(SELECT COUNT(*)::int FROM public.usage) AS usage,
(SELECT COUNT(*)::int FROM public.user) AS user
`);
if (!result.rows[0]) {
return;
}
const payload = {
sessionId,
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
publicCoreUrl: config.publicCoreUrl,
tables: Object.entries(result.rows[0]).map(([tableName, recordCount]) => ({ tableName, recordCount })),
};
const proto = 'https'
const host = 'archive-list';
const domain = 'jlinc';
const tld = 'io';
const res = await axios.post(
`${proto}://${host}.${domain}.${tld}/api/v1/archive`,
payload,
);
return res.data;
} finally {
client.release();
}
}

View File

@@ -2,6 +2,7 @@ const DEFAULT_KEY_CACHE = { ttlMs: 30 * 60 * 1000, max: 10_000 };
const config = {
debug: false,
archiveList: true,
dashboard: { core: {}, audit: {}, keyCache: { ...DEFAULT_KEY_CACHE } },
};
@@ -22,6 +23,7 @@ export async function loadConfig() {
config.authModules[type] = getModuleConfig();
}
}
if (process.env.ARCHIVE_LIST) config.archiveList = process.env.ARCHIVE_LIST;
config.appModules = {};
let appModules = [
'core',