Get page title and colors from database

See #18
master
Dessa Simpson 2021-02-21 20:13:47 -07:00
parent 2e5762c029
commit 1c34b3f013
5 changed files with 67 additions and 6 deletions

View File

@ -3,8 +3,10 @@ CREATE TABLE config (
normaluservotepoints int NOT NULL, normaluservotepoints int NOT NULL,
followervotepoints int NOT NULL, followervotepoints int NOT NULL,
subscribervotepoints int NOT NULL, subscribervotepoints int NOT NULL,
title varchar NOT NULL,
colors jsonb NOT NULL,
PRIMARY KEY (rowLock) PRIMARY KEY (rowLock)
); );
INSERT INTO config (normalUserVotePoints,followerVotePoints,subscriberVotePoints) INSERT INTO config (normalUserVotePoints,followerVotePoints,subscriberVotePoints,title,colors)
VALUES (10,50,100); VALUES (10,50,100,'{username}''s Learn Request Queue','{"bg": {"primary": "#444444","table": "#282828","navbar": "#666666","error": "#ff0000"},"fg": {"primary": "#dddddd","ahover": "#ffffff","title": "#eeeeee"}}');

View File

@ -302,7 +302,7 @@ app.get("/callback", async (request, response) => {
app.get("/", async (request, response) => { app.get("/", async (request, response) => {
if (request.session) await validateApiToken(request.session); if (request.session) await validateApiToken(request.session);
var streamerInfo = await db.query(queries.getStreamerInfo).then((result: pg.QueryResult) => result.rows[0]); var streamerInfo = await db.query(queries.getStreamerInfo).then((result: pg.QueryResult) => result.rows[0]);
var validStates = JSON.stringify((await db.query(queries.getValidStates).then((result: pg.QueryResult) => result.rows)).map((row: any) => row.state)); var config = await db.query(queries.getConfig).then((result: pg.QueryResult) => result.rows[0]);
if (typeof streamerInfo == 'undefined') { if (typeof streamerInfo == 'undefined') {
response.redirect(307, `https://id.twitch.tv/oauth2/authorize?client_id=${config.twitchClientId}&redirect_uri=${config.urlPrefix}/callback&response_type=code&scope=channel:read:subscriptions moderation:read`); response.redirect(307, `https://id.twitch.tv/oauth2/authorize?client_id=${config.twitchClientId}&redirect_uri=${config.urlPrefix}/callback&response_type=code&scope=channel:read:subscriptions moderation:read`);
return; return;
@ -312,22 +312,34 @@ app.get("/", async (request, response) => {
loggedIn: false, loggedIn: false,
clientId: config.twitchClientId, clientId: config.twitchClientId,
urlPrefix: config.urlPrefix, urlPrefix: config.urlPrefix,
pageTitle: config.title,
streamerName: streamerInfo['displayname'], streamerName: streamerInfo['displayname'],
streamerProfilePicture: streamerInfo['imageurl'] streamerProfilePicture: streamerInfo['imageurl']
}); });
} else { } else {
var validStates = JSON.stringify((await db.query(queries.getValidStates).then((result: pg.QueryResult) => result.rows)).map((row: any) => row.state));
response.render('main.eta', { response.render('main.eta', {
loggedIn: true, loggedIn: true,
userName: request.session.user.display_name, userName: request.session.user.display_name,
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: config.title,
streamerName: streamerInfo['displayname'], streamerName: streamerInfo['displayname'],
streamerProfilePicture: streamerInfo['imageurl'] streamerProfilePicture: streamerInfo['imageurl']
}); });
} }
}); });
app.get("/colors.css", async (_request, response) => {
var streamerInfo = await db.query(queries.getStreamerInfo).then((result: pg.QueryResult) => result.rows[0]);
var colors = await db.query(queries.getConfig).then((result: pg.QueryResult) => result.rows[0]['colors']);
console.log(colors);
if (typeof streamerInfo == 'undefined') return;
response.contentType("text/css");
response.render('colors.eta', colors);
});
// Streamer Panel // Streamer Panel
//app.get("/streamer/", async (request, response) => { //app.get("/streamer/", async (request, response) => {
// //

View File

@ -26,6 +26,11 @@ export const getStreamerInfo = {
text: "SELECT userid,displayname,imageurl FROM streamer_user_vw" text: "SELECT userid,displayname,imageurl FROM streamer_user_vw"
} }
export const getConfig = {
name: "getConfig",
text: "SELECT * FROM config"
}
export const updateStreamer = { export const updateStreamer = {
name: "updateStreamer", name: "updateStreamer",
text: "INSERT INTO streamer (userid,tokenPair) VALUES ($1,$2)\ text: "INSERT INTO streamer (userid,tokenPair) VALUES ($1,$2)\

41
views/colors.eta Normal file
View File

@ -0,0 +1,41 @@
body {
background-color: <%= it.bg.primary %>;
color: <%= it.fg.primary %>;
}
a {
color: <%= it.fg.primary %>;
}
a:hover {
color: <%= it.fg.ahover %>;
}
.error {
background-color: <%= it.bg.error %>;
}
#navbar {
background-color: <%= it.bg.navbar %>;
}
#nav-title, #nav-title a {
color: <%= it.fg.title %>;
}
#main {
background-color: <%= it.bg.table %>;
}
#modalBackground {
background-color: <%= it.bg.primary %>;
background-color: <%= it.bg.primary %>aa;
}
.modal {
background-color: <%= it.bg.primary %>;
}
#deleteRequestLink {
color: <%= it.bg.error %>;
}

View File

@ -1,8 +1,9 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<link rel=stylesheet href=style.css /> <link rel=stylesheet href=/style.css />
<title><%= it.streamerName %>'s Learn Request Queue</title> <link rel=stylesheet href=/colors.css />
<title><%= it.pageTitle.replace('{username}',it.streamerName) %></title>
<script> <script>
window.loggedIn = <%= it.loggedIn %>; window.loggedIn = <%= it.loggedIn %>;
window.validStates = <%~ it.validStates %>; window.validStates = <%~ it.validStates %>;
@ -13,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"><a href="https://twitch.tv/<%= it.streamerName %>"><%= it.streamerName %></a>'s Learn Request Queue</div> <div id="nav-title"><%~ it.pageTitle.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>