feat: hotspot PIX MikroTik + backend Docker + CI Gitea Actions
build-image / build-push (push) Failing after 4m36s

This commit is contained in:
jfeng committed 2026-10-20 21:07:22 -03:00
commit de9bd4ae0b
15 files changed
+1720

No files matched your search

+44
View File
@@ -0,0 +1,44 @@
import fs from 'node:fs';
import path from 'node:path';
import crypto from 'node:crypto';
import config from './config.js';
const DB_PATH = path.join(config.dataDir, 'db.json');
const DEFAULT_PLANS = [
{ id: 'plano-1h', name: '1 Hora', price: 3.00, profile: 'pix-1h', uptime: '1h', speed: '5M/1M', active: true },
{ id: 'plano-24h', name: '24 Horas', price: 5.00, profile: 'pix-24h', uptime: '1d', speed: '8M/2M', active: true },
{ id: 'plano-7d', name: '7 Dias', price: 15.00, profile: 'pix-7d', uptime: '1w', speed: '10M/3M', active: true },
];
let db = { plans: [], payments: [] };
export function initDb() {
fs.mkdirSync(config.dataDir, { recursive: true });
if (fs.existsSync(DB_PATH)) {
db = JSON.parse(fs.readFileSync(DB_PATH, 'utf8'));
if (!db.plans?.length) db.plans = structuredClone(DEFAULT_PLANS);
if (!db.payments) db.payments = [];
} else {
db = { plans: structuredClone(DEFAULT_PLANS), payments: [] };
saveDb();
}
}
export function saveDb() {
const tmp = DB_PATH + '.tmp';
fs.writeFileSync(tmp, JSON.stringify(db, null, 2));
fs.renameSync(tmp, DB_PATH);
}
export function getDb() {
return db;
}
export function genCode(len = 8) {
const chars = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789';
const bytes = crypto.randomBytes(len);
let out = '';
for (let i = 0; i < len; i++) out += chars[bytes[i] % chars.length];
return out;
}