fix bugs, improve loading time
This commit is contained in:
parent
988d90b46f
commit
d9fe8f2642
@ -35,7 +35,7 @@ socket.addEventListener("message", async function (event) {
|
||||
}
|
||||
}
|
||||
})
|
||||
var posting_id = undefined;
|
||||
|
||||
var cd = true //inversed "cooldown"
|
||||
|
||||
let encryption_keys = ""
|
||||
@ -57,7 +57,7 @@ function set_keys(s_key) {
|
||||
main()
|
||||
}
|
||||
|
||||
async function postMessage() {
|
||||
async function postMessage(elem) {
|
||||
let len = document.getElementById("post-text").value.length
|
||||
if(len >= 1001) {
|
||||
alert(`Your message cant contain more than 1000 characters! (${len})`)
|
||||
@ -107,8 +107,6 @@ async function update_pid() {
|
||||
console.log("Updated pid",posting_id)
|
||||
}
|
||||
|
||||
document.getElementById("post-btn").addEventListener("click",postMessage)
|
||||
|
||||
function spacerTextNode() {
|
||||
return document.createTextNode(" | ")
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ socket.addEventListener("message", async function (event) {
|
||||
}
|
||||
}
|
||||
})
|
||||
var posting_id = undefined;
|
||||
|
||||
var cd = true //inversed "cooldown"
|
||||
|
||||
async function postMessage() {
|
||||
@ -80,8 +80,6 @@ async function update_pid() {
|
||||
console.log("Updated pid",posting_id)
|
||||
}
|
||||
|
||||
document.getElementById("post-btn").addEventListener("click",postMessage)
|
||||
|
||||
function spacerTextNode() {
|
||||
return document.createTextNode(" | ")
|
||||
}
|
||||
|
@ -1,18 +1,24 @@
|
||||
import xor from "../../../extra_modules/xor.js";
|
||||
export const setup = function (router, con, server) {
|
||||
const PIDS = {}; //[pid]: true/"already_used"
|
||||
router.get("/api/dms/pid", async function (req, res) {
|
||||
res.set("Access-Control-Allow-Origin", "*");
|
||||
|
||||
function createPID(){
|
||||
let pid = server.genstring(10); //collision chance is low enough, but we'll check anyways
|
||||
while (PIDS[pid] != undefined) {
|
||||
pid = server.genstring(10);
|
||||
console.log(5, "pid collision");
|
||||
}
|
||||
PIDS[pid] = true;
|
||||
setTimeout(function () {
|
||||
setTimeout(function() {
|
||||
PIDS[pid] = undefined;
|
||||
}, 40000);
|
||||
res.json({ "pid": pid });
|
||||
return pid
|
||||
}
|
||||
|
||||
|
||||
router.get("/api/dms/pid", async function (req, res) {
|
||||
res.set("Access-Control-Allow-Origin", "*");
|
||||
res.json({ "pid": createPID() });
|
||||
});
|
||||
router.post("/api/dms/post", async function (req, res) {
|
||||
if (!req.body.message) {
|
||||
@ -90,6 +96,7 @@ export const setup = function (router, con, server) {
|
||||
console.log(5, `posted new dm by ${res.locals.username} to ${otherperson} : ${xor(encodeURIComponent(res.locals.username), otherperson)}`);
|
||||
});
|
||||
});
|
||||
return createPID
|
||||
};
|
||||
export default {
|
||||
setup
|
||||
|
@ -1,7 +1,7 @@
|
||||
export const setup = function (router, con, server) {
|
||||
const PIDS = {}; //[pid]: true/"already_used"
|
||||
router.get("/api/pid", async function (req, res) {
|
||||
res.set("Access-Control-Allow-Origin", "*");
|
||||
|
||||
function createPID(){
|
||||
let pid = server.genstring(10); //collision chance is low enough, but we'll check anyways
|
||||
while (PIDS[pid] != undefined) {
|
||||
pid = server.genstring(10);
|
||||
@ -11,7 +11,12 @@ export const setup = function (router, con, server) {
|
||||
setTimeout(function() {
|
||||
PIDS[pid] = undefined;
|
||||
}, 40000);
|
||||
res.json({ "pid": pid });
|
||||
return pid
|
||||
}
|
||||
|
||||
router.get("/api/pid", async function (req, res) {
|
||||
res.set("Access-Control-Allow-Origin", "*");
|
||||
res.json({ "pid": createPID() });
|
||||
});
|
||||
router.post("/api/post", async function (req, res) {
|
||||
if (!req.body.message) {
|
||||
@ -87,6 +92,7 @@ export const setup = function (router, con, server) {
|
||||
console.log(5, `posted new message by ${res.locals.username} : ${req.body.message}`);
|
||||
});
|
||||
});
|
||||
return createPID
|
||||
};
|
||||
export default {
|
||||
setup
|
||||
|
@ -431,9 +431,9 @@ var commonfunctions = {
|
||||
optionssetup(router, con, commonfunctions);
|
||||
allsetup(router, con, commonfunctions);
|
||||
settingshandlersetup(router, con, commonfunctions);
|
||||
postsetup(router, con, commonfunctions);
|
||||
const get_pid = postsetup(router, con, commonfunctions);
|
||||
dmsPersonalMessagessetup(router, con, commonfunctions);
|
||||
dmspostsetup(router, con, commonfunctions);
|
||||
const get_dmpid = dmspostsetup(router, con, commonfunctions);
|
||||
// const toLoad = [
|
||||
// "api/options.js",
|
||||
// "api/all.js",
|
||||
@ -874,7 +874,9 @@ let global_page_variables = {
|
||||
htmlescapejs: load_var("./js/htmlescape.js"),
|
||||
warnmessagejs: load_var("./js/warn_message.js"),
|
||||
loadfile: load_var,
|
||||
getChannels: get_channels
|
||||
getChannels: get_channels,
|
||||
getPID: get_pid,
|
||||
getDMPID: get_dmpid
|
||||
}
|
||||
|
||||
router.get("/*", async function(request, response) {
|
||||
|
@ -16,6 +16,7 @@
|
||||
<script><%- loadfile("./js/extend_key.js") %></script>
|
||||
<script type="text/javascript" src="/api/dms/encrypt.js"></script>
|
||||
<script type="text/javascript">let user = <%- JSON.stringify(user) %></script>
|
||||
<script type="text/javascript">var posting_id = "<%- getDMPID() %>"</script>
|
||||
</head>
|
||||
<body>
|
||||
<%- navbar %>
|
||||
@ -36,7 +37,7 @@
|
||||
<span id="reply" style="display:none;" class="noselect">Replying to: <b id="reply_username"></b> <small id="reply_text"></small> <button onclick="unreply()" style="color:red">X</button></span> <br>
|
||||
<textarea name="name" id="post-text" rows="8" cols="80"></textarea>
|
||||
<br>
|
||||
<button type="button" name="button" id="post-btn" onclick="postMessage()">Post</button>
|
||||
<button type="button" name="button" id="post-btn" onclick="postMessage(this)">Post</button>
|
||||
</div>
|
||||
<div class="channelTab">
|
||||
<input type="text" name="Username_input" id="Username_input" placeholder="Username" class="channel" style="font-size: 16px;" onkeypress="clickPress(event)"> <br>
|
||||
|
@ -15,6 +15,7 @@
|
||||
<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>
|
||||
<script type="text/javascript">var posting_id = "<%- getPID() %>"</script>
|
||||
|
||||
|
||||
</head>
|
||||
|
Loading…
x
Reference in New Issue
Block a user