Refactored server/db.js and all routes to use asynchronous fs operations, refactored m3uParser and epgParser to use streaming (via readline and sax) to prevent errors with large files, updated server/routes/proxy.js to use native stream piping for images and video, reducing latency and memory overhead

This commit is contained in:
Trevor Mears
2025-12-30 00:34:55 -08:00
parent 3b0d311756
commit d63c9c37d7
9 changed files with 366 additions and 311 deletions
+8 -8
View File
@@ -3,10 +3,10 @@ const router = express.Router();
const { favorites } = require('../db');
// Get all favorites
router.get('/', (req, res) => {
router.get('/', async (req, res) => {
try {
const { sourceId, itemType } = req.query;
const items = favorites.getAll(sourceId, itemType);
const items = await favorites.getAll(sourceId, itemType);
res.json(items);
} catch (err) {
res.status(500).json({ error: err.message });
@@ -14,14 +14,14 @@ router.get('/', (req, res) => {
});
// Add favorite
router.post('/', (req, res) => {
router.post('/', async (req, res) => {
try {
const { sourceId, itemId, itemType = 'channel' } = req.body;
if (!sourceId || !itemId) {
return res.status(400).json({ error: 'Source ID and Item ID are required' });
}
favorites.add(sourceId, itemId, itemType);
await favorites.add(sourceId, itemId, itemType);
res.json({ success: true });
} catch (err) {
res.status(500).json({ error: err.message });
@@ -29,14 +29,14 @@ router.post('/', (req, res) => {
});
// Remove favorite
router.delete('/', (req, res) => {
router.delete('/', async (req, res) => {
try {
const { sourceId, itemId, itemType = 'channel' } = req.body;
if (!sourceId || !itemId) {
return res.status(400).json({ error: 'Source ID and Item ID are required' });
}
favorites.remove(sourceId, itemId, itemType);
await favorites.remove(sourceId, itemId, itemType);
res.json({ success: true });
} catch (err) {
res.status(500).json({ error: err.message });
@@ -44,14 +44,14 @@ router.delete('/', (req, res) => {
});
// Check if item is favorited
router.get('/check', (req, res) => {
router.get('/check', async (req, res) => {
try {
const { sourceId, itemId, itemType = 'channel' } = req.query;
if (!sourceId || !itemId) {
return res.status(400).json({ error: 'Source ID and Item ID are required' });
}
const isFav = favorites.isFavorite(sourceId, itemId, itemType);
const isFav = await favorites.isFavorite(sourceId, itemId, itemType);
res.json({ isFavorite: isFav });
} catch (err) {
res.status(500).json({ error: err.message });