34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
import { db } from "../src/db";
|
|
import { decryptJson } from "../src/security";
|
|
|
|
const rows = db.query(`
|
|
SELECT id, name, channel, subject_type, mode, enabled, config_encrypted, updated_at
|
|
FROM gateways
|
|
ORDER BY channel, id
|
|
`).all() as Array<Record<string, any>>;
|
|
|
|
const safe = rows.map((row) => {
|
|
const config = decryptJson<Record<string, string>>(row.config_encrypted || "");
|
|
let notifyHost = "";
|
|
try { notifyHost = config.notifyUrl ? new URL(config.notifyUrl).host : ""; } catch { notifyHost = "INVALID_URL"; }
|
|
return {
|
|
id: row.id,
|
|
name: row.name,
|
|
channel: row.channel,
|
|
subjectType: row.subject_type,
|
|
mode: row.mode,
|
|
enabled: Boolean(row.enabled),
|
|
updatedAt: row.updated_at,
|
|
configured: row.channel === "alipay" ? {
|
|
appId: Boolean(config.appId),
|
|
merchantPid: Boolean(config.merchantPid),
|
|
privateKey: Boolean(config.privateKey),
|
|
alipayPublicKey: Boolean(config.alipayPublicKey)
|
|
} : undefined,
|
|
notifyHost,
|
|
customGateway: Boolean(config.gatewayUrl)
|
|
};
|
|
});
|
|
|
|
console.log(JSON.stringify(safe, null, 2));
|