From c4738888f012f8cff7bd88b9b26e1e49b71130e7 Mon Sep 17 00:00:00 2001 From: Mark Powers Date: Sat, 20 Jul 2024 14:37:12 -0500 Subject: Update soundboard with docker --- index.js | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'index.js') 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 += `
${item.name}
${tags}
\n` } catch (error) { console.log(error) - } + } }) html += `` }) @@ -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") }) -- cgit v1.2.3