summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Dockerfile7
-rw-r--r--index.js20
2 files changed, 16 insertions, 11 deletions
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..da0262a
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,7 @@
+FROM node:20-slim
+
+COPY ./ .
+
+RUN npm install
+
+CMD node .
diff --git a/index.js b/index.js
index 3fe01cc..e8aed23 100644
--- a/index.js
+++ b/index.js
@@ -10,6 +10,11 @@ server.use((req, res, next) => {
next()
})
+server.use((err, req, res, next) => {
+ console.error(err.stack)
+ res.status(500).send('Something broke! Try again!')
+})
+
const credentials = Buffer.from(`${config.user}:${config.pass}`).toString('base64')
const authorization = `Basic ${credentials}`
@@ -45,20 +50,13 @@ async function fetch_page(page){
return fetch_library(page).then(data => data.items)
}
-function enqueue(id){
+async function enqueue(id){
fetch(`${config.baseURL}/post`, {
"credentials": "include",
"headers": headers(),
"body": `add_item_next=${id}`,
"method": "POST",
- }).then(response => {
- try {
- return response.json()
- } catch (error) {
- return {}
- }
})
- .then(data => console.log(`Added ${id} to queue`));
}
function set_volume(value){
@@ -223,7 +221,7 @@ server.get('/', async (req, res) => {
html += `<div class="btn" onclick="enqueue(['${item.id}'])"><div>${item.name}</div>${tags}</div>\n`
} catch (error) {
console.log(error)
- }
+ }
})
html += `</div>`
})
@@ -247,7 +245,7 @@ server.get('/random', async (req, res, next) => {
return item.type == "file" && !item.path.startsWith("uploads/")
})
let rand_sound = filtered_sounds[Math.floor(Math.random() * filtered_sounds.length)]
- enqueue(rand_sound.id)
+ await enqueue(rand_sound.id)
res.send("ok")
})
@@ -282,7 +280,7 @@ server.get('/volume/:val', async (req, res, next) => {
})
server.get('/:id', async (req, res, next) => {
- enqueue(req.params.id)
+ await enqueue(req.params.id)
res.send("ok")
})