mirror of
https://git.waldn.net/git/knotteye/satyr.git
synced 2025-10-20 11:41:10 +00:00
Big commit. Implement handlers for everything that's currently rendered server side in the client-side frontend.
Add compiled templates file to .gitignore, will work out a system for making sure templates are compiled later. Fix a couple bugs in the API and templates. TODO for client-side rendering: Make sure templates get compiled before running the server. Add a config option to switch between server-side and client-side rendering Fancy SPA stuff like intercepting links to render changes without a page-reload
This commit is contained in:
@@ -87,9 +87,11 @@ async function getConfig(username: string, all?: boolean): Promise<object>{
|
||||
let users = await db.query('SELECT stream_key,record_flag FROM users WHERE username='+db.raw.escape(username));
|
||||
if(users[0]) Object.assign(t, users[0]);
|
||||
let usermeta = await db.query('SELECT title,about FROM user_meta WHERE username='+db.raw.escape(username));
|
||||
if(usermeta[0]) Object.assign(t, users[0]);
|
||||
if(usermeta[0]) Object.assign(t, usermeta[0]);
|
||||
let ci = await db.query('SELECT irc,xmpp,twitch,discord FROM chat_integration WHERE username='+db.raw.escape(username));
|
||||
if(ci[0]) Object.assign(t, ci[0]);
|
||||
let tw = await db.query('SELECT enabled,twitch_key FROM twitch_mirror WHERE username='+db.raw.escape(username));
|
||||
if(tw[0]) t['twitch_mirror'] = Object.assign({}, tw[0]);
|
||||
}
|
||||
else {
|
||||
let um = await db.query('SELECT title,about FROM user_meta WHERE username='+db.raw.escape(username));
|
||||
|
11
src/http.ts
11
src/http.ts
@@ -75,6 +75,15 @@ async function init(){
|
||||
}
|
||||
|
||||
async function initFE(){
|
||||
app.get('/', (req, res) => {
|
||||
res.redirect(config['satyr']['rootredirect']);
|
||||
});
|
||||
app.get('/nunjucks-slim.js', (req, res) => {
|
||||
res.sendFile(process.cwd()+'/node_modules/nunjucks/browser/nunjucks-slim.js');
|
||||
});
|
||||
app.get('/chat', (req, res) => {
|
||||
res.sendFile(process.cwd()+'/templates/chat.html');
|
||||
});
|
||||
app.get('*', (req, res) => {
|
||||
res.sendFile(process.cwd()+'/'+config['http']['directory']+'/index.html');
|
||||
});
|
||||
@@ -368,6 +377,7 @@ async function initAPI() {
|
||||
if(req.cookies.Authorization) validToken(req.cookies.Authorization).then((t) => {
|
||||
if(t) {
|
||||
if(t['exp'] - 86400 < Math.floor(Date.now() / 1000)){
|
||||
res.cookie('X-Auth-As', t['username'], {maxAge: 604800000, httpOnly: false, sameSite: 'Lax'});
|
||||
return genToken(t['username']).then((t) => {
|
||||
res.cookie('Authorization', t, {maxAge: 604800000, httpOnly: true, sameSite: 'Lax'});
|
||||
res.json({success:""});
|
||||
@@ -389,6 +399,7 @@ async function initAPI() {
|
||||
if(!result){
|
||||
genToken(req.body.username).then((t) => {
|
||||
res.cookie('Authorization', t, {maxAge: 604800000, httpOnly: true, sameSite: 'Lax'});
|
||||
res.cookie('X-Auth-As', req.body.username, {maxAge: 604800000, httpOnly: false, sameSite: 'Lax'});
|
||||
res.json({success:""});
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user