50 lines
1.7 KiB
JavaScript
50 lines
1.7 KiB
JavaScript
|
|
const { keyManager, listModelPrices, pool } = require("./context");
|
||
|
|
|
||
|
|
function registerPriceRoutes(router) {
|
||
|
|
// ── Public ───────────────────────────────────────────────────────────
|
||
|
|
|
||
|
|
router.get("/prices", async (_req, res) => {
|
||
|
|
const prices = await listModelPrices({ enabledOnly: true });
|
||
|
|
res.json(prices);
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
function registerPackageRoutes(router) {
|
||
|
|
// ── Public: Packages ─────────────────────────────────────────────────
|
||
|
|
|
||
|
|
router.get("/packages", async (_req, res) => {
|
||
|
|
const { rows } = await pool.query(
|
||
|
|
"SELECT * FROM packages WHERE enabled = 1 ORDER BY sort_order, id",
|
||
|
|
);
|
||
|
|
res.json(
|
||
|
|
rows.map((row) => ({
|
||
|
|
id: Number(row.id),
|
||
|
|
name: row.name,
|
||
|
|
description: row.description,
|
||
|
|
priceCents: row.price_cents,
|
||
|
|
creditsCents: row.credits_cents,
|
||
|
|
imageQuota: row.image_quota,
|
||
|
|
videoQuota: row.video_quota,
|
||
|
|
textQuota: row.text_quota,
|
||
|
|
durationDays: row.duration_days,
|
||
|
|
sortOrder: row.sort_order,
|
||
|
|
})),
|
||
|
|
);
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
function registerHealthRoutes(router) {
|
||
|
|
// ── Health ───────────────────────────────────────────────────────────
|
||
|
|
|
||
|
|
router.get("/health", async (_req, res) => {
|
||
|
|
const status = await keyManager.getAllStatus();
|
||
|
|
res.json({ status: "ok", uptime: process.uptime(), providers: status });
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
module.exports = {
|
||
|
|
registerPriceRoutes,
|
||
|
|
registerPackageRoutes,
|
||
|
|
registerHealthRoutes,
|
||
|
|
};
|