Shows playlist editor now shows media title instead of ID

This commit is contained in:
Speng Reb 2026-05-20 21:10:49 +02:00
parent 56ab732f6b
commit c4ee655d15
2 changed files with 84 additions and 1 deletions

View file

@ -3,6 +3,7 @@ const webserver = require('../../webserver');
const showDB = require('../../../database/shows'); const showDB = require('../../../database/shows');
const shows = require('../../../shows'); const shows = require('../../../shows');
const botDB = require('../../../database/bots'); const botDB = require('../../../database/bots');
const infoGetter = require('../../../get-info');
const { getChannelRow, getUserEffectiveRank, hashToken } = require('./middleware'); const { getChannelRow, getUserEffectiveRank, hashToken } = require('./middleware');
const router = express.Router({ mergeParams: true }); const router = express.Router({ mergeParams: true });
@ -186,6 +187,46 @@ router.get('/:id', async (req, res) => {
res.json(show); res.json(show);
}); });
router.post('/resolve-media', async (req, res) => {
const auth = await authorizeChannel(req, res);
if (!auth) return;
const items = Array.isArray(req.body && req.body.items) ? req.body.items : [];
if (items.length === 0) {
return res.json({ items: [] });
}
const capped = items.slice(0, 50).map(item => ({
id: item && item.id ? String(item.id).trim() : '',
type: item && item.type ? String(item.type).trim() : ''
})).filter(item => item.id && item.type);
const resolved = await Promise.all(capped.map(item => {
return new Promise(resolve => {
infoGetter.getMedia(item.id, item.type, (err, media) => {
if (err || !media) {
resolve({
id: item.id,
type: item.type,
title: item.id,
ok: false
});
return;
}
resolve({
id: item.id,
type: item.type,
title: media.title || item.id,
ok: true
});
});
});
}));
res.json({ items: resolved });
});
router.post('/', async (req, res) => { router.post('/', async (req, res) => {
const auth = await authorizeChannel(req, res); const auth = await authorizeChannel(req, res);
if (!auth) return; if (!auth) return;

View file

@ -1178,6 +1178,7 @@ var CSTShows = (function () {
var selectedId = null; var selectedId = null;
var draftPlaylist = []; var draftPlaylist = [];
var timezoneOptionsLoaded = false; var timezoneOptionsLoaded = false;
var resolvingTitles = false;
function apiBase() { function apiBase() {
return '/api/v1/channels/' + CHANNEL.name + '/shows'; return '/api/v1/channels/' + CHANNEL.name + '/shows';
@ -1234,7 +1235,7 @@ var CSTShows = (function () {
draftPlaylist.forEach(function (item, idx) { draftPlaylist.forEach(function (item, idx) {
var li = $('<li class="queue_entry">').attr('data-idx', idx); var li = $('<li class="queue_entry">').attr('data-idx', idx);
var title = item.title || (item.type + ':' + item.id); var title = item.title || item.id || (item.type + ':' + item.id);
$('<span>').text('[' + item.type + '] ' + title).appendTo(li); $('<span>').text('[' + item.type + '] ' + title).appendTo(li);
var controls = $('<div class="btn-group pull-right">').appendTo(li); var controls = $('<div class="btn-group pull-right">').appendTo(li);
$('<button class="btn btn-xs btn-default" type="button" title="Move up">') $('<button class="btn btn-xs btn-default" type="button" title="Move up">')
@ -1268,6 +1269,45 @@ var CSTShows = (function () {
}); });
} }
function resolveDraftTitles() {
if (resolvingTitles || draftPlaylist.length === 0) {
return;
}
var unresolved = draftPlaylist.filter(function (item) {
return !item.title || item.title === item.id;
}).map(function (item) {
return { id: item.id, type: item.type };
});
if (unresolved.length === 0) {
return;
}
resolvingTitles = true;
$.ajax({
url: apiBase() + '/resolve-media',
method: 'POST',
contentType: 'application/json',
data: JSON.stringify({ items: unresolved })
}).done(function (data) {
var map = {};
(data.items || []).forEach(function (item) {
map[item.type + ':' + item.id] = item.title || item.id;
});
draftPlaylist.forEach(function (item) {
var key = item.type + ':' + item.id;
if (map[key]) {
item.title = map[key];
}
});
renderDraftPlaylist();
}).always(function () {
resolvingTitles = false;
});
}
function addUrlToDraft(pos) { function addUrlToDraft(pos) {
var raw = $('#cs-shows-mediaurl').val(); var raw = $('#cs-shows-mediaurl').val();
if (!raw) { if (!raw) {
@ -1313,6 +1353,7 @@ var CSTShows = (function () {
$('#cs-shows-mediaurl').val(''); $('#cs-shows-mediaurl').val('');
renderDraftPlaylist(); renderDraftPlaylist();
resolveDraftTitles();
if (parseFail > 0 || duplicates > 0) { if (parseFail > 0 || duplicates > 0) {
var parts = []; var parts = [];
@ -1389,6 +1430,7 @@ var CSTShows = (function () {
}; };
}); });
renderDraftPlaylist(); renderDraftPlaylist();
resolveDraftTitles();
} }
function action(id, actionName) { function action(id, actionName) {