Skip to content

Commit

Permalink
Fix various runtime issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Xwilarg committed Jul 24, 2024
1 parent 85e4406 commit ad93a09
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 15 deletions.
19 changes: 5 additions & 14 deletions web/src/getMusics.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ function sanitize(text) {
// #region On page load

function getAlbumImage(elem) {
if (elem.album === null) {
if (elem.album === null || elem.album === undefined) {
return "/img/CD.png";
}
return "/data/icon/" + json.albums[elem.album].path;
Expand Down Expand Up @@ -320,15 +320,6 @@ function addZero(nb) {

let oldRanges = "";

async function loadSongsAsync() {
// Get music infos
json = JSON.parse(document.getElementById("data").innerText);

if (json.readme !== undefined) {
document.getElementById("readme").innerHTML = json.readme.join("<br/>");
}
}

async function updateScrobblerAsync() {
// last.fm documentation says a song can be srobbled if we listended for more than its halve, or more than 4 minutes
console.log(`[Song] Last song was listened for a duration of ${timeListened} out of ${trackDuration} seconds`);
Expand Down Expand Up @@ -549,7 +540,7 @@ function chooseDisplay() {
// If parameter is not set or set to a wrong value
if (playlist === null || playlist === undefined || json["playlists"] === undefined || json["playlists"][playlist] === undefined) {
// If there is no playlist we just display the default one
if (json.musics !== undefined && json.musics.some(x => x.playlist !== "default")) {
if (json.musics !== undefined && json.musics.some(x => x.playlist !== "default" && x.playlist !== null && x.playlist !== undefined)) {
if (playlist === "default") {
playlist = "default";
} else {
Expand All @@ -572,7 +563,7 @@ function chooseDisplay() {
document.getElementById("back").hidden = false;
if (json.musics !== undefined)
{
json.musics = json.musics.filter(x => x.playlist === playlist);
json.musics = json.musics.filter(x => x.playlist === playlist || (playlist === "default" && x.playlist === undefined));
for (let id in json.musics) {
json.musics[id].id = id;
}
Expand All @@ -587,9 +578,9 @@ export async function musics_initAsync() {
document.getElementById("toggle-volume").addEventListener("click", () => { document.getElementById("volume-container").hidden = !document.getElementById("volume-container").hidden; });
document.getElementById("refresh-btn").addEventListener("click", refresh);
document.getElementById("random-btn").addEventListener("click", random);
document.getElementById("minimalistMode").addEventListener("click", toggleMinimalistMode);
document.getElementById("minimalistMode")?.addEventListener("click", toggleMinimalistMode);

await loadSongsAsync();
json = JSON.parse(document.getElementById("data").innerText);

// Filter text bar
document.getElementById("filter").addEventListener("input", (e) => {
Expand Down
2 changes: 2 additions & 0 deletions web/src/lastfm.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ export async function registerScrobbleAsync(song, artist, album, length, timesta

export async function lastfm_initAsync()
{
if (document.getElementById("lastfmLogin") === null) return; // lastfm was disabled, nothing to do

const resp = await fetch("/php/getLastfmApiKey.php");
lastFmApiKey = await resp.text();

Expand Down
2 changes: 1 addition & 1 deletion web/templates/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</div>
</fieldset>
{% endif %}
{% if metadata.showGitHub %}
{% if metadata.showLastfm %}
<fieldset>
<legend>last.fm</legend>
<div>
Expand Down

0 comments on commit ad93a09

Please sign in to comment.