feat(epg): order EPG sources by priority (#24)

Add persistent EPG priority ordering, source reorder validation, and priority-aware EPG matching for live channels.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
blomios
2026-10-06 11:58:50 +02:00
parent 9718155e75
commit afe91089e5
8 changed files with 254 additions and 8 deletions

View File

@ -3,6 +3,7 @@ const { requireAuth, requireAdmin } = require('../auth');
const liveProjection = require('../services/liveProjectionService');
const iptvOrgCatalog = require('../services/iptvOrgCatalogService');
const { getDb } = require('../db/sqlite');
const { sources } = require('../db');
const router = express.Router();
@ -44,7 +45,8 @@ router.get('/channels', requireAuth, async (req, res) => {
if (state.status !== 'success' && state.status !== 'building') {
state = await liveProjection.startRebuild().promise;
}
const allChannels = liveProjection.getChannels({ sourceId, includeHidden, userId: req.user.id });
const epgSources = await sources.getByType('epg');
const allChannels = liveProjection.getChannels({ sourceId, includeHidden, userId: req.user.id, epgSources });
const availableLanguages = [...new Map(allChannels.map(channel => [channel.language.code, channel.language])).values()]
.map(language => ({ code: language.code, short: language.short, label: language.label }))
.sort((left, right) => left.label.localeCompare(right.label));

View File

@ -47,6 +47,20 @@ router.get('/type/:type', async (req, res) => {
}
});
router.put('/epg/order', async (req, res) => {
try {
const ordered = await sources.reorderEpg(req.body?.orderedIds);
res.json(ordered.map(source => ({
...source,
password: source.password ? '••••••••' : null
})));
} catch (err) {
if (err.code) return res.status(400).json({ error: err.message, code: err.code });
console.error('Error reordering EPG sources:', err);
res.status(500).json({ error: 'Failed to reorder EPG sources' });
}
});
// Get single source
router.get('/:id', async (req, res) => {
try {