53 lines
1.6 KiB
JavaScript
53 lines
1.6 KiB
JavaScript
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();
|
|
}
|
|
} |