add channels & current user in template
This commit is contained in:
parent
72f8d36654
commit
87b81cef81
@ -1,4 +1,3 @@
|
|||||||
let user
|
|
||||||
let username
|
let username
|
||||||
|
|
||||||
const wss_server = "wss://ipost.tk"
|
const wss_server = "wss://ipost.tk"
|
||||||
@ -339,7 +338,6 @@ function switchChannel(channelname) {
|
|||||||
async function loadChannels() {
|
async function loadChannels() {
|
||||||
// <!-- <p class="channel">- Channel Name -</p> -->
|
// <!-- <p class="channel">- Channel Name -</p> -->
|
||||||
|
|
||||||
let channels = await (await fetch("/api/getChannels")).json()
|
|
||||||
let tab = document.getElementById("channelTab")
|
let tab = document.getElementById("channelTab")
|
||||||
tab.innerHTML = ""
|
tab.innerHTML = ""
|
||||||
for (let i = 0; i < channels.length; i++) {
|
for (let i = 0; i < channels.length; i++) {
|
||||||
@ -367,7 +365,7 @@ async function loadChannels() {
|
|||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
setInterval(update_pid,30000)
|
setInterval(update_pid,30000)
|
||||||
update_pid()
|
if(posting_id=="")update_pid()
|
||||||
main()
|
main()
|
||||||
firstAsk()
|
firstAsk()
|
||||||
loadChannels()
|
loadChannels()
|
||||||
|
@ -6,19 +6,12 @@ const HASHES_DB = config.cookies.server_hashes;
|
|||||||
const HASHES_COOKIE = config.cookies.client_hashes;
|
const HASHES_COOKIE = config.cookies.client_hashes;
|
||||||
const HASHES_DIFF = HASHES_DB - HASHES_COOKIE;
|
const HASHES_DIFF = HASHES_DB - HASHES_COOKIE;
|
||||||
export const setup = function (router, con, server) {
|
export const setup = function (router, con, server) {
|
||||||
router.use("/api/*", async function (req, res, next) {
|
router.use("/*", async function (req, res, next) {
|
||||||
res.set("Access-Control-Allow-Origin", "*"); //we'll allow it for now
|
res.set("Access-Control-Allow-Origin", "*"); //we'll allow it for now
|
||||||
if (config["allow_getotheruser_without_cookie"] && req.originalUrl.split("\?")[0] == "/api/getotheruser") {
|
|
||||||
next();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!server.increaseAPICall(req, res))
|
|
||||||
return;
|
|
||||||
let unsigned;
|
let unsigned;
|
||||||
if (req.body.user == undefined || req.body.pass == undefined) {
|
if (req.body.user == undefined || req.body.pass == undefined) {
|
||||||
unsigned = unsign.getunsigned(req, res);
|
unsigned = unsign.getunsigned(req, res);
|
||||||
if (!unsigned)
|
if (!unsigned)next()
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
unsigned = `${req.body.user} ${SHA.SHA256(req.body.pass, req.body.user, HASHES_COOKIE)}`;
|
unsigned = `${req.body.user} ${SHA.SHA256(req.body.pass, req.body.user, HASHES_COOKIE)}`;
|
||||||
@ -43,14 +36,28 @@ export const setup = function (router, con, server) {
|
|||||||
res.locals.settings = {};
|
res.locals.settings = {};
|
||||||
if (res.locals.settings == null)
|
if (res.locals.settings == null)
|
||||||
res.locals.settings = {};
|
res.locals.settings = {};
|
||||||
next();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
res.status(400);
|
|
||||||
res.json({ "error": "you cannot access the api without being logged in" });
|
|
||||||
}
|
}
|
||||||
|
next()
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
router.use("/api/*", async function (req, res, next) {
|
||||||
|
res.set("Access-Control-Allow-Origin", "*"); //we'll allow it for now
|
||||||
|
if (config["allow_getotheruser_without_cookie"] && req.originalUrl.split("\?")[0] == "/api/getotheruser") {
|
||||||
|
next();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!server.increaseAPICall(req, res))return;
|
||||||
|
|
||||||
|
if (res.locals.username != undefined) {
|
||||||
|
next();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
res.status(400);
|
||||||
|
res.json({ "error": "you cannot access the api without being logged in" });
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
export default {
|
export default {
|
||||||
setup
|
setup
|
||||||
|
19
server.js
19
server.js
@ -856,15 +856,25 @@ function load_var(fina) {
|
|||||||
import {minify as min_js} from "uglify-js"
|
import {minify as min_js} from "uglify-js"
|
||||||
import Clean from 'clean-css';
|
import Clean from 'clean-css';
|
||||||
|
|
||||||
|
function get_channels(){
|
||||||
|
return new Promise(function(resolve, reject) {
|
||||||
|
let sql = `select post_receiver_name from ipost.posts where post_is_private = '0' group by post_receiver_name;`;
|
||||||
|
con.query(sql, [], function (err, result) {
|
||||||
|
if (err)reject(err)
|
||||||
|
resolve(result)
|
||||||
|
});
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const global_page_variables = {
|
let global_page_variables = {
|
||||||
globalcss: load_var("./css/global.css"),
|
globalcss: load_var("./css/global.css"),
|
||||||
httppostjs: load_var("./js/httppost.js"),
|
httppostjs: load_var("./js/httppost.js"),
|
||||||
navbar: load_var("./extra_modules/navbar.html"),
|
navbar: load_var("./extra_modules/navbar.html"),
|
||||||
markdownjs: load_var("./js/markdown.js"),
|
markdownjs: load_var("./js/markdown.js"),
|
||||||
htmlescapejs: load_var("./js/htmlescape.js"),
|
htmlescapejs: load_var("./js/htmlescape.js"),
|
||||||
warnmessagejs: load_var("./js/warn_message.js"),
|
warnmessagejs: load_var("./js/warn_message.js"),
|
||||||
loadfile: load_var
|
loadfile: load_var,
|
||||||
|
getChannels: get_channels
|
||||||
}
|
}
|
||||||
|
|
||||||
router.get("/*", async function(request, response) {
|
router.get("/*", async function(request, response) {
|
||||||
@ -892,7 +902,10 @@ router.get("/*", async function(request, response) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(path != "") {
|
if(path != "") {
|
||||||
ejs.renderFile(path,global_page_variables,async function(err,str){
|
global_page_variables.user = { "username": response.locals.username, "bio": response.locals.bio, "avatar": response.locals.avatar }
|
||||||
|
ejs.renderFile(path,global_page_variables,{async: true},async function(err,str){
|
||||||
|
str = await str
|
||||||
|
err = await err
|
||||||
if(err) {
|
if(err) {
|
||||||
console.log(1,err)
|
console.log(1,err)
|
||||||
response.status(500)
|
response.status(500)
|
||||||
|
@ -13,6 +13,10 @@
|
|||||||
<script type="text/javascript"><%- htmlescapejs %></script>
|
<script type="text/javascript"><%- htmlescapejs %></script>
|
||||||
<script type="text/javascript"><%- markdownjs %></script>
|
<script type="text/javascript"><%- markdownjs %></script>
|
||||||
<script type="text/javascript"><%- warnmessagejs %></script>
|
<script type="text/javascript"><%- warnmessagejs %></script>
|
||||||
|
<script type="text/javascript">let channels = <%- JSON.stringify(await getChannels()) %></script>
|
||||||
|
<script type="text/javascript">let user = <%- JSON.stringify(user) %></script>
|
||||||
|
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<%- navbar %>
|
<%- navbar %>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user