diff --git a/db/95-procedures.sql b/db/95-procedures.sql index f2427bf..28ec802 100644 --- a/db/95-procedures.sql +++ b/db/95-procedures.sql @@ -36,3 +36,11 @@ CREATE OR REPLACE PROCEDURE update_request_score_modifier(updateurl varchar, sco UPDATE scores SET scoreModifier = scoreModifier + scoreDiff WHERE url = updateurl; CALL update_scores(); $$; + +CREATE OR REPLACE PROCEDURE update_vote_points(normaluser int, follower int, subscriber int) + LANGUAGE SQL + AS $$ + UPDATE config SET normaluservotepoints = normaluser, + followervotepoints = follower, subscribervotepoints = subscriber; + CALL update_scores(); + $$; diff --git a/public/main.js b/public/main.js index 48d4a06..73559b2 100644 --- a/public/main.js +++ b/public/main.js @@ -318,12 +318,27 @@ function updateColors(colors) { }); } +function updateVotePoints(user,follower,subscriber) { + streamerSettingsErrReset(); + fetch("/api/updateVotePoints", { method: 'POST', body: new URLSearchParams({ + user: user, + follower: follower, + subscriber: subscriber + })}) + .then(response => { + if (response.ok) { + location.reload(); + } else { + response.text().then(streamerSettingsErr); + } + }); +} + updateTable(); document.addEventListener("keydown", function onEvent(event) { if (event.key === "Escape") { - closeMessageModal(); - closeAddRequestModal(); + closeAllModals(); } }); document.getElementById("modalBackground").addEventListener("click", (e) => { if (e.target === e.currentTarget) closeAllModals();}); diff --git a/public/style.css b/public/style.css index c25812e..5ff0029 100644 --- a/public/style.css +++ b/public/style.css @@ -185,3 +185,14 @@ div#nav-userpic { #deleteRequestLink { color: #f00; } + +#streamerSettingsMain { + max-height: 65vh; + overflow-y: scroll; +} + +#votepoints { + padding: 0 1.5em; + display: flex; + justify-content: space-between; +} diff --git a/src/app.ts b/src/app.ts index 0a417fa..3e931ce 100644 --- a/src/app.ts +++ b/src/app.ts @@ -285,6 +285,44 @@ app.post("/api/updateColors", async (request, response) => { response.send('Successfully updated colors'); }); +app.post("/api/updateVotePoints", async (request, response) => { + if (request.session) await validateApiToken(request.session); + if (!request.session || !request.session.user) { + response.status(401); + response.send("Session expired; please log in again"); + return; + } + var streamerid = await db.query(queries.getStreamerId).then((result: pg.QueryResult) => result.rows[0]['userid']); + if (request.session.user.id != streamerid) { + response.status(401); + response.send("You are not the streamer"); + return; + } + if (!request.body.user) { + response.status(400); + response.send("Missing user"); + return; + } + if (!request.body.follower) { + response.status(400); + response.send("Missing follower"); + return; + } + if (!request.body.subscriber) { + response.status(400); + response.send("Missing subscriber"); + return; + } + var user = request.body.user as number; + var follower = request.body.follower as number; + var subscriber = request.body.subscriber as number; + response.type('text/plain'); + await db.query(Object.assign(queries.updateVotePoints,{ values: [user,follower,subscriber] })) + .catch((e: any) => errorHandler(request,response,e)); + response.status(200); + response.send('Successfully updated page title'); +}); + app.post("/api/deleteRequest", async (request, response) => { if (request.session) await validateApiToken(request.session); if (!request.session || !request.session.user) { @@ -439,10 +477,9 @@ app.get("/", async (request, response) => { loggedIn: false, clientId: config.twitchClientId, urlPrefix: config.urlPrefix, - pageTitle: streamerConfig.title, streamerName: streamerInfo['displayname'], streamerProfilePicture: streamerInfo['imageurl'], - colors: streamerConfig.colors + config: streamerConfig, }); } else { var validStates = JSON.stringify((await db.query(queries.getValidStates).then((result: pg.QueryResult) => result.rows)).map((row: any) => row.state)); @@ -452,10 +489,9 @@ app.get("/", async (request, response) => { userProfilePicture: request.session.user.profile_image_url, validStates: validStates, isStreamer: streamerInfo['userid'] == request.session.user.id, - pageTitle: streamerConfig.title, streamerName: streamerInfo['displayname'], streamerProfilePicture: streamerInfo['imageurl'], - colors: streamerConfig.colors + config: streamerConfig, }); } }); diff --git a/src/queries.ts b/src/queries.ts index 407dbc0..5c7c7fd 100644 --- a/src/queries.ts +++ b/src/queries.ts @@ -47,6 +47,11 @@ export const updateColors = { text: "UPDATE config SET colors = $1" } +export const updateVotePoints = { + name: "updateVotePoints", + text: "CALL update_vote_points($1,$2,$3)" +} + // Request-related queries export const getRequests = { name: "getRequests", diff --git a/views/main.eta b/views/main.eta index ea7fd32..f17520c 100644 --- a/views/main.eta +++ b/views/main.eta @@ -3,7 +3,7 @@
-