Merge pull request #4 from Enstrayed/main
Merge changes into new auth branch
This commit was merged in pull request #4.
This commit is contained in:
@@ -1,11 +1,7 @@
|
||||
const { globalConfig } = require("../index.js")
|
||||
|
||||
async function checkAuthorization(documentToUse,keyToCheck) {
|
||||
return await fetch(`http://${globalConfig.couchdb.host}/apiauthkeys/${documentToUse}`, {
|
||||
headers: {
|
||||
"Authorization": `Basic ${btoa(globalConfig.couchdb.authorization)}`
|
||||
}
|
||||
}).then(fetchRes => {
|
||||
return await fetch(`${globalConfig.couchdbHost}/apiauthkeys/${documentToUse}`).then(fetchRes => {
|
||||
|
||||
if (fetchRes.status === 404) { // If document doesnt exist fail gracefully
|
||||
|
||||
|
||||
26
liberals/nowplaying.js
Normal file
26
liberals/nowplaying.js
Normal file
@@ -0,0 +1,26 @@
|
||||
const { globalConfig } = require("../index.js")
|
||||
|
||||
async function queryLastfm() {
|
||||
return await fetch(`https://ws.audioscrobbler.com/2.0/?format=json&method=user.getrecenttracks&limit=1&api_key=${globalConfig.nowplaying.lastfm.apiKey}&user=${globalConfig.nowplaying.lastfm.target}`).then(response => response.json()).then(response => {
|
||||
if (response["recenttracks"] == undefined) {
|
||||
return 1
|
||||
} else {
|
||||
if (response.recenttracks.track[0]["@attr"] == undefined) {
|
||||
return 1
|
||||
} else {
|
||||
return {
|
||||
"json": {
|
||||
"songName": response.recenttracks.track[0].name,
|
||||
"artistName": response.recenttracks.track[0].artist["#text"],
|
||||
"albumName": response.recenttracks.track[0].album["#text"],
|
||||
"artUrl": response.recenttracks.track[0].image[3]["#text"],
|
||||
"link": response.recenttracks.track[0].url
|
||||
},
|
||||
"html": `<img src="${response.recenttracks.track[0].image[3]["#text"]}" alt="Album Art" style="width: 10em;"> <div class="textlist"> <p>I'm listening to</p> <h3>${response.recenttracks.track[0].name} by ${response.recenttracks.track[0].artist["#text"]}</h3> <p>from ${response.recenttracks.track[0].album["#text"]}</p> <a href="${response.recenttracks.track[0].url}" class="noindent">View on Last.fm</a></div>`
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = { queryLastfm }
|
||||
Reference in New Issue
Block a user