From a60707965b707ecb0c8171379adcf145296f60a8 Mon Sep 17 00:00:00 2001 From: TheTeaCat Date: Fri, 17 Jan 2020 08:55:09 +0000 Subject: [PATCH] Ignore tags with ampersands (addresses #15) --- src/assets/js/Generator.js | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/assets/js/Generator.js b/src/assets/js/Generator.js index cd1c4d0..47179fe 100644 --- a/src/assets/js/Generator.js +++ b/src/assets/js/Generator.js @@ -67,6 +67,8 @@ class Generator { /**If the response doesn't have the data we need, we just return and declare the request as failed. */ if (response.data.toptags == undefined) { return } for (var tag of response.data.toptags.tag) { + /**I'm currently ignoring tags that contain ampersands because the last.fm API is broken for them. */ + if (tag.name.includes("&")) { continue } /**Tag "counts" cap out at 100. * I am assuming that they are a confidence % given by last.fm as to how accurate the tag is. */ @@ -110,19 +112,21 @@ class Generator { var tag_promises = [] for (var tag of this.result.tags) { tag_promises.push(new Promise( - async function(resolve){ - await axios.get("https://ws.audioscrobbler.com/2.0/?method=tag.getinfo"+ - "&api_key="+API_KEY+ - "&tag="+tag+ - "&format=json").then( - function(response){ - if (response.data.tag == undefined) { return } - this.result.tag_meta[response.data.tag.name].reach = response.data.tag.reach - this.result.tag_meta[response.data.tag.name].total = response.data.tag.total - }.bind(this) - ) - resolve(true) - }.bind(this) + function(tag_name){ + return async function (resolve){ + await axios.get("https://ws.audioscrobbler.com/2.0/?method=tag.getinfo"+ + "&api_key="+API_KEY+ + "&tag="+tag_name+ + "&format=json").then( + function(response){ + if (response.data.tag == undefined ) { return } + this.result.tag_meta[tag_name].reach = response.data.tag.reach + this.result.tag_meta[tag_name].total = response.data.tag.total + }.bind(this) + ) + resolve(true) + }.bind(this) + }.bind(this)(tag) )) } await Promise.all(tag_promises)