diff options
author | Mark Powers <mark@marks.kitchen> | 2024-07-20 14:37:12 -0500 |
---|---|---|
committer | Mark Powers <mark@marks.kitchen> | 2024-07-20 14:37:12 -0500 |
commit | c4738888f012f8cff7bd88b9b26e1e49b71130e7 (patch) | |
tree | 4a7dbd3a7e462bc5ece89142485eef43d3943b47 /index.js | |
parent | f2386bf9931f4f812ff81fdc5ea2ddebe14b4500 (diff) |
Diffstat (limited to 'index.js')
-rw-r--r-- | index.js | 20 |
1 files changed, 9 insertions, 11 deletions
@@ -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") }) |