From aed9113b8d5b7e81d9d652fe736101235964b872 Mon Sep 17 00:00:00 2001 From: MeowcaTheoRange Date: Thu, 22 Feb 2024 08:29:31 -0600 Subject: [PATCH] Allow webhook connections --- notification-server.js | 18 ++++++++++++++++++ package.json | 1 + 2 files changed, 19 insertions(+) diff --git a/notification-server.js b/notification-server.js index c7c1db3..8e4c86f 100644 --- a/notification-server.js +++ b/notification-server.js @@ -2,6 +2,7 @@ require('dotenv').config(); const express = require('express'); const { createServer } = require('node:http'); const { Server } = require('socket.io'); +const { fork } = require("child_process"); const app = express(); const server = createServer(app); @@ -15,6 +16,23 @@ io.on('connection', (socket) => { }) }); +app.get("/webscrobbler", (req, res) => { + res.status(204).end(); +}) + +app.post("/webscrobbler", (req, res) => { + if (req.query.password === process.env.NOTIFICATION_SERVER_PASSWORD) { + const process = fork("./index.js"); + process.on('error', function (err) { + res.status(500).end(); + }); + process.on('exit', function (code) { + res.status(204).end(); + }); + } + else res.status(403).end(); +}) + server.listen(process.env.NOTIFICATION_SERVER_PORT, () => { console.log(`server running on port ${process.env.NOTIFICATION_SERVER_PORT}`); }); \ No newline at end of file diff --git a/package.json b/package.json index cdf4569..fd103e6 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "author": "abtmtr.link", "license": "KKPL-2.2", "dependencies": { + "child_process": "^1.0.2", "commander": "^12.0.0", "dotenv": "^16.4.4", "express": "^4.18.2",