Skip to content

Commit

Permalink
Upd: Show placeholder image by playlist type
Browse files Browse the repository at this point in the history
  • Loading branch information
jcorporation committed Sep 15, 2024
1 parent 8bf9789 commit b4774cd
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/references/webserver-uris.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Reference of all webserver uris.
| `/browse/` | Prints the list of [published directories]({{ site.baseurl }}/references/published-directories) |
| `/ca.crt` | Returns the myMPD CA certificate |
| `/folderart?path=<path>` | Returns the folderart thumbnail. |
| `/playlistart?playlist=<playlist name>` | Returns the playlistart thumbnail. |
| `/playlistart?type=<plist,smartpls>&playlist=<playlist name>` | Returns the playlistart thumbnail or a redirect to the placeholder image if not found. |
| `/proxy?uri=<uri>` | Fetches the response from the uri (GET), allowed hosts: `jcorporation.github.io`, `musicbrainz.org`, `listenbrainz.org` |
| `/script/<partition>/<script>` | Executes a script (Script should return a valid http response) |
| `/script-api/<partition>` | Jsonrpc api endpoint for mympd-script |
Expand Down
3 changes: 2 additions & 1 deletion htdocs/js/viewBrowsePlaylist.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ function parsePlaylistDetail(obj) {

if (obj.result.pics === true) {
const img = elCreateEmpty('div', {});
img.style.backgroundImage = getCssImageUri('/playlistart?playlist=' + myEncodeURIComponent(obj.result.plist));
img.style.backgroundImage = getCssImageUri('/playlistart?type=' +
(obj.result.smartpls === false ? 'plist' : 'smartpls') + '&playlist=' + myEncodeURIComponent(obj.result.plist));
img.addEventListener('click', function(event) {
zoomPicture(event.target);
}, false);
Expand Down
2 changes: 1 addition & 1 deletion htdocs/js/views.js
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ function setEntryData(entry, data) {
break;
case 'plist':
case 'smartpls':
data.Thumbnail = getCssImageUri('/playlistart?playlist=' + myEncodeURIComponent(data.uri));
data.Thumbnail = getCssImageUri('/playlistart?type=' + data.Type + '&playlist=' + myEncodeURIComponent(data.uri));
break;
case 'webradiodb':
data.Thumbnail = getCssImageUri(data.Image);
Expand Down
12 changes: 11 additions & 1 deletion src/web_server/playlistart.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,18 @@ bool request_handler_playlistart(struct mg_connection *nc, struct mg_http_messag
{
struct t_config *config = mg_user_data->config;
sds name = get_uri_param(&hm->query, "playlist=");
sds type = get_uri_param(&hm->query, "type=");

if (name == NULL ||
type == NULL ||
sdslen(name) == 0 ||
sdslen(type) == 0 ||
vcb_isfilepath(name) == false)
{
MYMPD_LOG_ERROR(NULL, "Failed to decode query");
webserver_redirect_placeholder_image(nc, PLACEHOLDER_PLAYLIST);
FREE_SDS(name);
FREE_SDS(type);
return false;
}
strip_file_extension(name);
Expand All @@ -53,9 +57,15 @@ bool request_handler_playlistart(struct mg_connection *nc, struct mg_http_messag
}
else {
MYMPD_LOG_DEBUG(NULL, "No image for playlist found");
webserver_redirect_placeholder_image(nc, PLACEHOLDER_PLAYLIST);
if (strcmp(type, "smartpls") == 0) {
webserver_redirect_placeholder_image(nc, PLACEHOLDER_SMARTPLS);
}
else {
webserver_redirect_placeholder_image(nc, PLACEHOLDER_PLAYLIST);
}
}
FREE_SDS(mediafile);
FREE_SDS(name);
FREE_SDS(type);
return true;
}

0 comments on commit b4774cd

Please sign in to comment.