OrbiSubs panel: channel list, add/edit modal, live status (phase 1, start/stop off)
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
'use strict';
|
||||
// server.js — panel de OrbiSubs (Express, puerto 4700). Hermano de OrbiStream:
|
||||
// misma base técnica (Express + better-sqlite3, panel en public/ sin framework).
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const os = require('os');
|
||||
const express = require('express');
|
||||
|
||||
const PORT = parseInt(process.env.PORT, 10) || 4700;
|
||||
const { db } = require('./db');
|
||||
const auth = require('./routes/auth');
|
||||
const pkg = require('../package.json');
|
||||
|
||||
const app = express();
|
||||
app.set('trust proxy', 'loopback');
|
||||
app.use(express.json({ limit: '64kb' }));
|
||||
|
||||
app.use('/api', auth.middleware);
|
||||
app.use('/api/auth', auth.router);
|
||||
app.get('/api/health', (req, res) => res.json({ status: 'ok' }));
|
||||
|
||||
// Datos del pie común (node-foot.js): producto, hora del nodo, CT e IPs.
|
||||
function nodoConf() {
|
||||
const o = {};
|
||||
try {
|
||||
for (const l of fs.readFileSync('/etc/orbitv/nodo.conf', 'utf8').split('\n')) {
|
||||
const m = /^([A-Z_]+)=["']?(.*?)["']?$/.exec(l.trim());
|
||||
if (m) o[m[1]] = m[2];
|
||||
}
|
||||
} catch { /* sin nodo.conf */ }
|
||||
return o;
|
||||
}
|
||||
app.get('/api/system/nodo', (req, res) => {
|
||||
const n = nodoConf();
|
||||
const ips = [];
|
||||
for (const [ifn, addrs] of Object.entries(os.networkInterfaces())) {
|
||||
for (const a of addrs || []) if (a.family === 'IPv4' && !a.internal) ips.push({ role: n[`RED_${ifn.toUpperCase()}`] || ifn, ip: a.address });
|
||||
}
|
||||
res.json({
|
||||
now: Date.now(),
|
||||
tz: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
||||
product: 'OrbiSubs', version: pkg.version,
|
||||
ct_id: n.CT_ID || process.env.CT_ID || null, pve: n.PVE || process.env.PVE || null,
|
||||
hostname: os.hostname(), ips,
|
||||
});
|
||||
});
|
||||
|
||||
app.use('/api/channels', require('./routes/channels'));
|
||||
app.get('/api/events', (req, res) => {
|
||||
res.json(db.prepare('SELECT * FROM events ORDER BY id DESC LIMIT 200').all());
|
||||
});
|
||||
|
||||
app.use(express.static(path.join(__dirname, 'public')));
|
||||
app.get('*', (req, res, next) => (req.path.startsWith('/api') ? next() : res.sendFile(path.join(__dirname, 'public', 'index.html'))));
|
||||
|
||||
app.use((err, req, res, next) => { // eslint-disable-line no-unused-vars
|
||||
console.error('[orbisubs-panel]', err);
|
||||
res.status(err.status || 500).json({ error: err.status ? err.message : 'Error interno' });
|
||||
});
|
||||
|
||||
app.listen(PORT, () => console.log(`[orbisubs-panel] escuchando en :${PORT}`));
|
||||
Reference in New Issue
Block a user