Repo maintenance & add nowplaying
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -2,3 +2,5 @@ node_modules/
|
||||
config.json
|
||||
bun.lockb
|
||||
GITVERSION
|
||||
todo.txt
|
||||
proto.js
|
||||
@@ -9,12 +9,6 @@
|
||||
"authorization": ""
|
||||
},
|
||||
|
||||
"cider": {
|
||||
"targetHosts": ["localhost:10769"],
|
||||
|
||||
"authKeysDoc": "cider"
|
||||
},
|
||||
|
||||
"mailjet": {
|
||||
"apiKey": "",
|
||||
"senderAddress": "apinotifications@enstrayed.com",
|
||||
@@ -23,14 +17,25 @@
|
||||
"authKeysDoc": "mailjet"
|
||||
},
|
||||
|
||||
"etyd": {
|
||||
"randomHexLength": 6,
|
||||
"authKeyInDb": "apiAuthKeys.etyd"
|
||||
},
|
||||
|
||||
"blog": {
|
||||
"postsDirectory": "C:/Users/natha/Downloads/proto/posts",
|
||||
"postsDirUrl": "/posts"
|
||||
},
|
||||
|
||||
"nowplaying": {
|
||||
"lastfm": {
|
||||
"apiKey": "",
|
||||
"target": "enstrayed"
|
||||
},
|
||||
"jellyfin": {
|
||||
"apiKey": "",
|
||||
"host": "",
|
||||
"target": ""
|
||||
},
|
||||
"cider": {
|
||||
"apiKeys": [],
|
||||
"hosts": []
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
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 }
|
||||
56
package-lock.json
generated
56
package-lock.json
generated
@@ -9,22 +9,43 @@
|
||||
"version": "1.0.0",
|
||||
"license": "UNLICENSED",
|
||||
"dependencies": {
|
||||
"express": "^4.18.2",
|
||||
"typescript": "^5.4.3"
|
||||
"express": "^4.18.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/bun": "^1.0.12",
|
||||
"@types/node": "^20.12.3"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "20.12.3",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.12.3.tgz",
|
||||
"integrity": "sha512-sD+ia2ubTeWrOu+YMF+MTAB7E+O7qsMqAbMfW7DG3K1URwhZ5hN1pLlRVGbf4wDFzSfikL05M17EyorS86jShw==",
|
||||
"node_modules/@types/bun": {
|
||||
"version": "1.1.5",
|
||||
"resolved": "https://registry.npmjs.org/@types/bun/-/bun-1.1.5.tgz",
|
||||
"integrity": "sha512-7RprVDMF+1o+EWSo7F1+iJpkfNz+Ikw9K//vwambcY+D1QHXfb9l7jWY1hSBfuFEkW9yFAhkMzP2uTi1pQXoqw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"bun-types": "1.1.14"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "20.12.14",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.12.14.tgz",
|
||||
"integrity": "sha512-scnD59RpYD91xngrQQLGkE+6UrHUPzeKZWhhjBSa3HSkwjbQc38+q3RoIVEwxQGRw3M+j5hpNAM+lgV3cVormg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"undici-types": "~5.26.4"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/ws": {
|
||||
"version": "8.5.10",
|
||||
"resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.10.tgz",
|
||||
"integrity": "sha512-vmQSUcfalpIq0R9q7uTo2lXs6eGIpt9wtnLdMv9LVpIjCA/+ufZRozlVoVelIYixx1ugCBKDhn89vnsEGOCx9A==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/accepts": {
|
||||
"version": "1.3.8",
|
||||
"resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz",
|
||||
@@ -65,6 +86,17 @@
|
||||
"npm": "1.2.8000 || >= 1.4.16"
|
||||
}
|
||||
},
|
||||
"node_modules/bun-types": {
|
||||
"version": "1.1.14",
|
||||
"resolved": "https://registry.npmjs.org/bun-types/-/bun-types-1.1.14.tgz",
|
||||
"integrity": "sha512-esfxOvECTkjEuUEHBOoOo590Qggf4b9cz5h29AOB2SKt3yZwG3LbAX4iIYwWZX7GnO7vaY5hIdcQygwN0xGdNw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/node": "~20.12.8",
|
||||
"@types/ws": "~8.5.10"
|
||||
}
|
||||
},
|
||||
"node_modules/bytes": {
|
||||
"version": "3.1.2",
|
||||
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz",
|
||||
@@ -679,18 +711,6 @@
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/typescript": {
|
||||
"version": "5.4.3",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.3.tgz",
|
||||
"integrity": "sha512-KrPd3PKaCLr78MalgiwJnA25Nm8HAmdwN3mYUYZgG/wizIo9EainNVQI9/yDavtVFRN2h3k8uf3GLHuhDMgEHg==",
|
||||
"bin": {
|
||||
"tsc": "bin/tsc",
|
||||
"tsserver": "bin/tsserver"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14.17"
|
||||
}
|
||||
},
|
||||
"node_modules/undici-types": {
|
||||
"version": "5.26.5",
|
||||
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz",
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"dependencies": {
|
||||
"express": "^4.18.2"
|
||||
},
|
||||
"name": "api",
|
||||
"name": "enstrayedapi",
|
||||
"version": "1.0.0",
|
||||
"description": "api.enstrayed.com",
|
||||
"main": "index.js",
|
||||
|
||||
@@ -1,11 +1,33 @@
|
||||
const { app, globalConfig } = require("../index.js")
|
||||
const { queryLastfm } = require("../liberals/nowplaying.js")
|
||||
|
||||
var timeSinceLastLastfmQuery = Date.now()-5000
|
||||
var cachedLastfmResult = {}
|
||||
|
||||
const notPlayingAnythingPlaceholder = {
|
||||
"json": {
|
||||
"playing": false
|
||||
},
|
||||
"html": `<span>I'm not currently listening to anything.</span>`
|
||||
}
|
||||
|
||||
app.get("/nowplaying", (rreq,rres) => {
|
||||
if (rreq.query.format === "html") {
|
||||
rres.send("<span>The /nowplaying endpoint is currently under construction.</span>")
|
||||
|
||||
if (Date.now() < timeSinceLastLastfmQuery+5000) {
|
||||
rres.send(cachedLastfmResult[rreq.query.format] ?? cachedLastfmResult.json)
|
||||
} else {
|
||||
rres.send({"message":"The /nowplaying endpoint is currently under construction."})
|
||||
timeSinceLastLastfmQuery = Date.now()
|
||||
queryLastfm().then(response => {
|
||||
if (response == 1) {
|
||||
cachedLastfmResult = notPlayingAnythingPlaceholder
|
||||
} else {
|
||||
cachedLastfmResult = response
|
||||
}
|
||||
|
||||
rres.send(cachedLastfmResult[rreq.query.format] ?? cachedLastfmResult.json)
|
||||
})
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
module.exports = {app}
|
||||
Reference in New Issue
Block a user