Allow streamer to set vote point values
parent
fcd8f2b197
commit
60defb7ea6
|
@ -36,3 +36,11 @@ CREATE OR REPLACE PROCEDURE update_request_score_modifier(updateurl varchar, sco
|
||||||
UPDATE scores SET scoreModifier = scoreModifier + scoreDiff WHERE url = updateurl;
|
UPDATE scores SET scoreModifier = scoreModifier + scoreDiff WHERE url = updateurl;
|
||||||
CALL update_scores();
|
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();
|
||||||
|
$$;
|
||||||
|
|
|
@ -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();
|
updateTable();
|
||||||
|
|
||||||
document.addEventListener("keydown", function onEvent(event) {
|
document.addEventListener("keydown", function onEvent(event) {
|
||||||
if (event.key === "Escape") {
|
if (event.key === "Escape") {
|
||||||
closeMessageModal();
|
closeAllModals();
|
||||||
closeAddRequestModal();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
document.getElementById("modalBackground").addEventListener("click", (e) => { if (e.target === e.currentTarget) closeAllModals();});
|
document.getElementById("modalBackground").addEventListener("click", (e) => { if (e.target === e.currentTarget) closeAllModals();});
|
||||||
|
|
|
@ -185,3 +185,14 @@ div#nav-userpic {
|
||||||
#deleteRequestLink {
|
#deleteRequestLink {
|
||||||
color: #f00;
|
color: #f00;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#streamerSettingsMain {
|
||||||
|
max-height: 65vh;
|
||||||
|
overflow-y: scroll;
|
||||||
|
}
|
||||||
|
|
||||||
|
#votepoints {
|
||||||
|
padding: 0 1.5em;
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
44
src/app.ts
44
src/app.ts
|
@ -285,6 +285,44 @@ app.post("/api/updateColors", async (request, response) => {
|
||||||
response.send('Successfully updated colors');
|
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) => {
|
app.post("/api/deleteRequest", async (request, response) => {
|
||||||
if (request.session) await validateApiToken(request.session);
|
if (request.session) await validateApiToken(request.session);
|
||||||
if (!request.session || !request.session.user) {
|
if (!request.session || !request.session.user) {
|
||||||
|
@ -439,10 +477,9 @@ app.get("/", async (request, response) => {
|
||||||
loggedIn: false,
|
loggedIn: false,
|
||||||
clientId: config.twitchClientId,
|
clientId: config.twitchClientId,
|
||||||
urlPrefix: config.urlPrefix,
|
urlPrefix: config.urlPrefix,
|
||||||
pageTitle: streamerConfig.title,
|
|
||||||
streamerName: streamerInfo['displayname'],
|
streamerName: streamerInfo['displayname'],
|
||||||
streamerProfilePicture: streamerInfo['imageurl'],
|
streamerProfilePicture: streamerInfo['imageurl'],
|
||||||
colors: streamerConfig.colors
|
config: streamerConfig,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
var validStates = JSON.stringify((await db.query(queries.getValidStates).then((result: pg.QueryResult) => result.rows)).map((row: any) => row.state));
|
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,
|
userProfilePicture: request.session.user.profile_image_url,
|
||||||
validStates: validStates,
|
validStates: validStates,
|
||||||
isStreamer: streamerInfo['userid'] == request.session.user.id,
|
isStreamer: streamerInfo['userid'] == request.session.user.id,
|
||||||
pageTitle: streamerConfig.title,
|
|
||||||
streamerName: streamerInfo['displayname'],
|
streamerName: streamerInfo['displayname'],
|
||||||
streamerProfilePicture: streamerInfo['imageurl'],
|
streamerProfilePicture: streamerInfo['imageurl'],
|
||||||
colors: streamerConfig.colors
|
config: streamerConfig,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -47,6 +47,11 @@ export const updateColors = {
|
||||||
text: "UPDATE config SET colors = $1"
|
text: "UPDATE config SET colors = $1"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const updateVotePoints = {
|
||||||
|
name: "updateVotePoints",
|
||||||
|
text: "CALL update_vote_points($1,$2,$3)"
|
||||||
|
}
|
||||||
|
|
||||||
// Request-related queries
|
// Request-related queries
|
||||||
export const getRequests = {
|
export const getRequests = {
|
||||||
name: "getRequests",
|
name: "getRequests",
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
<head>
|
<head>
|
||||||
<link rel=stylesheet href=/style.css />
|
<link rel=stylesheet href=/style.css />
|
||||||
<link rel=stylesheet href=/colors.css />
|
<link rel=stylesheet href=/colors.css />
|
||||||
<title><%~ it.pageTitle.replace('{username}',it.streamerName) %></title>
|
<title><%~ it.config.title.replace('{username}',it.streamerName) %></title>
|
||||||
<script>
|
<script>
|
||||||
window.loggedIn = <%= it.loggedIn %>;
|
window.loggedIn = <%= it.loggedIn %>;
|
||||||
window.validStates = <%~ it.validStates %>;
|
window.validStates = <%~ it.validStates %>;
|
||||||
|
@ -14,7 +14,7 @@
|
||||||
<body>
|
<body>
|
||||||
<div id="navbar">
|
<div id="navbar">
|
||||||
<div id="nav-streamerpic"><a href="https://twitch.tv/<%= it.streamerName %>"><img src="<%= it.streamerProfilePicture %>" /></a></div>
|
<div id="nav-streamerpic"><a href="https://twitch.tv/<%= it.streamerName %>"><img src="<%= it.streamerProfilePicture %>" /></a></div>
|
||||||
<div id="nav-title"><%~ it.pageTitle.replace('{username}',`<a href="https://twitch.tv/${it.streamerName}">${it.streamerName}</a>`) %></div>
|
<div id="nav-title"><%~ it.config.title.replace('{username}',`<a href="https://twitch.tv/${it.streamerName}">${it.streamerName}</a>`) %></div>
|
||||||
<div id="nav-requests"><a href="/">Requests</a></div>
|
<div id="nav-requests"><a href="/">Requests</a></div>
|
||||||
<%- if (it.loggedIn) { -%>
|
<%- if (it.loggedIn) { -%>
|
||||||
<div id="nav-addrequest"><a href="#" onclick="openAddRequestModal()">Add Request</a></div>
|
<div id="nav-addrequest"><a href="#" onclick="openAddRequestModal()">Add Request</a></div>
|
||||||
|
@ -120,36 +120,56 @@
|
||||||
<h2>Streamer Settings</h2>
|
<h2>Streamer Settings</h2>
|
||||||
<div class="error" id="streamerSettingsError"></div>
|
<div class="error" id="streamerSettingsError"></div>
|
||||||
<br>
|
<br>
|
||||||
<div>
|
<div id="streamerSettingsMain">
|
||||||
<h3 style='margin-bottom: 0.5em'>Customization</h3>
|
<div>
|
||||||
<p>
|
<h3 style='margin-bottom: 0.5em'>Vote Point Values</h3>
|
||||||
Page Title:
|
<p>
|
||||||
<input type="text" id="pageTitle" style="width: 15em" value="<%~ it.pageTitle %>"></input>
|
<div id="votepoints">
|
||||||
<button onclick="updatePageTitle(document.getElementById('pageTitle').value)">Submit</button>
|
<div style="display: inline-block">User: <input type="number" id="userVotePoints" style="width: 3em" value="<%~ it.config.normaluservotepoints %>"></input></div>
|
||||||
<button onclick="updatePageTitle('{username}\'s Learn Request Queue')">Reset</button>
|
<div style="display: inline-block">Follower: <input type="number" id="followerVotePoints" style="width: 3em" value="<%~ it.config.followervotepoints %>"></input></div>
|
||||||
</p>
|
<div style="display: inline-block">Subscriber: <input type="number" id="subscriberVotePoints" style="width: 3em" value="<%~ it.config.subscribervotepoints %>"></input></div>
|
||||||
<p>
|
</div>
|
||||||
<h3>Colors:</h3>
|
<br>
|
||||||
<p>Click a color to change it</p>
|
<button onclick="updateVotePoints(
|
||||||
<b>Background:</b><br>
|
document.getElementById('userVotePoints').value,
|
||||||
Primary: <input type="color" id="color-bg-primary" value="<%= it.colors.bg.primary %>"></input><br>
|
document.getElementById('followerVotePoints').value,
|
||||||
Table: <input type="color" id="color-bg-table" value="<%= it.colors.bg.table %>"></input><br>
|
document.getElementById('subscriberVotePoints').value
|
||||||
Navbar: <input type="color" id="color-bg-navbar" value="<%= it.colors.bg.navbar %>"></input><br>
|
)">Submit</button>
|
||||||
Error: <input type="color" id="color-bg-error" value="<%= it.colors.bg.error %>"></input><br>
|
<button onclick="updateVotePoints(10,50,100)">Reset</button>
|
||||||
<br>
|
</p>
|
||||||
<b>Foreground:</b><br>
|
</div>
|
||||||
Primary: <input type="color" id="color-fg-primary" value="<%= it.colors.fg.primary %>"></input><br>
|
<hr>
|
||||||
Link Hover: <input type="color" id="color-fg-ahover" value="<%= it.colors.fg.ahover %>"></input><br>
|
<div>
|
||||||
Title: <input type="color" id="color-fg-title" value="<%= it.colors.fg.title %>"></input><br>
|
<h3 style='margin-bottom: 0.5em'>Customization</h3>
|
||||||
<br>
|
<p>
|
||||||
<button onclick="updateColors(getColorObject())">Submit</button>
|
Page Title:
|
||||||
<button onclick="updateColors({bg:{error: '#ff0000',table: '#282828',navbar: '#666666',primary: '#444444'},fg: { title: '#eeeeee', ahover: '#ffffff', primary: '#dddddd'}})">Reset</button>
|
<input type="text" id="pageTitle" style="width: 15em" value="<%~ it.config.title %>"></input>
|
||||||
</p>
|
<button onclick="updatePageTitle(document.getElementById('pageTitle').value)">Submit</button>
|
||||||
</div>
|
<button onclick="updatePageTitle('{username}\'s Learn Request Queue')">Reset</button>
|
||||||
<hr>
|
</p>
|
||||||
<div>
|
<p>
|
||||||
<h3 style='margin-bottom: 0.5em'>Batch Jobs</h3>
|
<h3>Colors:</h3>
|
||||||
<a href="#" onclick="cronRequest('processBans')">Force Refresh Banned Users (NYI)</a>
|
<p>Click a color to change it</p>
|
||||||
|
<b>Background:</b><br>
|
||||||
|
Primary: <input type="color" id="color-bg-primary" value="<%= it.config.colors.bg.primary %>"></input><br>
|
||||||
|
Table: <input type="color" id="color-bg-table" value="<%= it.config.colors.bg.table %>"></input><br>
|
||||||
|
Navbar: <input type="color" id="color-bg-navbar" value="<%= it.config.colors.bg.navbar %>"></input><br>
|
||||||
|
Error: <input type="color" id="color-bg-error" value="<%= it.config.colors.bg.error %>"></input><br>
|
||||||
|
<br>
|
||||||
|
<b>Foreground:</b><br>
|
||||||
|
Primary: <input type="color" id="color-fg-primary" value="<%= it.config.colors.fg.primary %>"></input><br>
|
||||||
|
Link Hover: <input type="color" id="color-fg-ahover" value="<%= it.config.colors.fg.ahover %>"></input><br>
|
||||||
|
Title: <input type="color" id="color-fg-title" value="<%= it.config.colors.fg.title %>"></input><br>
|
||||||
|
<br>
|
||||||
|
<button onclick="updateColors(getColorObject())">Submit</button>
|
||||||
|
<button onclick="updateColors({bg:{error: '#ff0000',table: '#282828',navbar: '#666666',primary: '#444444'},fg: { title: '#eeeeee', ahover: '#ffffff', primary: '#dddddd'}})">Reset</button>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<hr>
|
||||||
|
<div>
|
||||||
|
<h3 style='margin-bottom: 0.5em'>Batch Jobs</h3>
|
||||||
|
<a href="#" onclick="cronRequest('processBans')">Force Refresh Banned Users (NYI)</a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue