diff --git a/createSchema.sql b/createSchema.sql index 4466d32..30f123d 100644 --- a/createSchema.sql +++ b/createSchema.sql @@ -24,6 +24,7 @@ CREATE TABLE `posts` ( `post_text` varchar(4000) NOT NULL, `post_time` bigint NOT NULL, `post_special_text` varchar(100) DEFAULT NULL, - `post_ip` varchar(12) DEFAULT NULL, + `post_receiver_name` varchar(100) DEFAULT NULL, + `post_from_bot` tinyint DEFAULT '0', PRIMARY KEY (`post_id`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; diff --git a/css/posts.css b/css/posts.css index 460ed02..521be95 100644 --- a/css/posts.css +++ b/css/posts.css @@ -38,6 +38,10 @@ margin-left: 5px; } +.boticon { + +} + .mention { color: blue; } diff --git a/images/bot.png b/images/bot.png new file mode 100644 index 0000000..5825567 Binary files /dev/null and b/images/bot.png differ diff --git a/views/default_avatar.png b/images/default_avatar.png similarity index 100% rename from views/default_avatar.png rename to images/default_avatar.png diff --git a/js/posts.js b/js/posts.js index 724aec0..225487a 100644 --- a/js/posts.js +++ b/js/posts.js @@ -41,14 +41,14 @@ async function getavatar(username) { if(user) { user = "/avatars/"+user } else { - user = "/default_avatar.png" + user = "/images/default_avatar.png" } user_cache[username]=user } return user } -async function createPost(username,text,time,specialtext,postid) { +async function createPost(username,text,time,specialtext,postid,isbot) { if(!specialtext)specialtext="" const newDiv = document.createElement("div"); const newP = document.createElement("p"); @@ -56,6 +56,11 @@ async function createPost(username,text,time,specialtext,postid) { const newSpan2 = document.createElement("span"); const newSpan3 = document.createElement("span"); const avatar = document.createElement("img"); + const boticon = document.createElement("img") + boticon.src = "/images/bot.png" + boticon.height = 25 + boticon.width = 25 + boticon.classList.add("boticon") const newUsername = document.createTextNode(username); let timedate = new Date(time) @@ -66,7 +71,6 @@ async function createPost(username,text,time,specialtext,postid) { if(timedate=="Thu Jan 01 1970 01:00:00 GMT+0100 (Central European Standard Time)")time="unknown time" const newTime = document.createTextNode(time) const newSpecialText = document.createTextNode(specialtext) - newDiv.classList.add("post"); newSpan3.classList.add("specialtext") @@ -90,6 +94,11 @@ async function createPost(username,text,time,specialtext,postid) { newP.appendChild(newSpan2) if(specialtext != "")newP.appendChild(spacerTextNode()) newP.appendChild(newSpan3) + if(isbot==1){ + console.log(boticon); + newP.appendChild(spacerTextNode()) + newP.appendChild(boticon) + } newP.appendChild(spacerTextNode()) // |\>.Reply to this Post` @@ -119,9 +128,9 @@ async function main(){ document.getElementById("posts").innerHTML = "" for(i in all_posts) { let item = all_posts[i] - await createPost(decodeURIComponent(item.post_user_name),decodeURIComponent(item.post_text),item.post_time,item.post_special_text,item.post_id) + await createPost(decodeURIComponent(item.post_user_name),decodeURIComponent(item.post_text),item.post_time,item.post_special_text,item.post_id,item.post_from_bot) } - + let links = document.getElementsByClassName("insertedlink") for (let i = 0; i < links.length; i++) { links[i].innerText = links[i].innerText.split("\/\/")[1].split("\/")[0] diff --git a/js/user.js b/js/user.js index 3c6183f..a6a4c21 100644 --- a/js/user.js +++ b/js/user.js @@ -72,7 +72,7 @@ async function setuser() { if(avatar) { avatar = "/avatars/"+avatar } else { - avatar = "default_avatar.png" + avatar = "/images/default_avatar.png" } document.getElementById("user").innerText = `User: ${username}`; document.getElementById("bio").placeholder = decodeURIComponent(bio); diff --git a/server.js b/server.js index 938184f..19e8afc 100644 --- a/server.js +++ b/server.js @@ -339,6 +339,7 @@ router.use("/api/*",async function(req,res,next) { } else { unsigned = `${req.body.user} ${SHA256(req.body.pass,req.body.user,HASHES_COOKIE)}` //basically we generate the unsigned cookie + res.locals.isbot = true //only bots use user+pass } let sql = `select User_Name,User_Bio,User_Avatar from zerotwohub.users where User_Name=? and User_PW=?;` let values = unsigned.split(" ") @@ -490,8 +491,8 @@ router.post("/api/post", async function(req,res) { return } - let sql = `insert into zerotwohub.posts (post_user_name,post_text,post_time,post_receiver_name) values (?,?,?,?);` - let values = [encodeURIComponent(res.locals.username),req.body.message,Date.now(),req.body.receiver] + let sql = `insert into zerotwohub.posts (post_user_name,post_text,post_time,post_receiver_name,post_from_bot) values (?,?,?,?,?);` + let values = [encodeURIComponent(res.locals.username),req.body.message,Date.now(),req.body.receiver,res.locals.isbot] con.query(sql, values, function (err, result) { if (err) throw err; @@ -510,7 +511,7 @@ router.get("/api/getPosts/*", async function(req,res) { router.get("/api/getPosts", async function(req,res) { res.set("Access-Control-Allow-Origin","") - let sql = `select post_user_name,post_text,post_time,post_special_text,post_id from zerotwohub.posts where (post_receiver_name is null or post_receiver_name = 'everyone') order by post_id desc;` + let sql = `select post_user_name,post_text,post_time,post_special_text,post_id,post_from_bot from zerotwohub.posts where (post_receiver_name is null or post_receiver_name = 'everyone') order by post_id desc;` con.query(sql, [], function (err, result) { if (err) throw err; res.json(result) @@ -519,7 +520,7 @@ router.get("/api/getPosts", async function(req,res) { router.get("/api/getPersonalPosts", async function(req,res) { res.set("Access-Control-Allow-Origin","") - let sql = `select post_user_name,post_text,post_time,post_special_text,post_id from zerotwohub.posts where (post_receiver_name = ?) order by post_id desc;` + let sql = `select post_user_name,post_text,post_time,post_special_text,post_id,post_from_bot from zerotwohub.posts where (post_receiver_name = ?) order by post_id desc;` con.query(sql, [encodeURIComponent(res.locals.username)], function (err, result) { if (err) throw err; res.json(result) @@ -678,6 +679,16 @@ router.get("/js/*", (request, response) => { return; }); +router.get("/images/*", (request, response) => { + if(!increaseUSERCall(request,response))return + if(fs.existsSync(__dirname + request.originalUrl)){ + response.sendFile(__dirname + request.originalUrl); + } else { + response.status(404).send("no file with that name found") + } + return; +}); + router.get("/avatars/*", (request, response, next) => { if(!increaseUSERCall(request,response))return let originalUrl = request.originalUrl.split("?").shift() diff --git a/views/otheruser.html b/views/otheruser.html index 793567c..0ccc352 100644 --- a/views/otheruser.html +++ b/views/otheruser.html @@ -36,7 +36,7 @@ if(avatar) { avatar = "/avatars/"+avatar } else { - avatar = "/default_avatar.png" + avatar = "/images/default_avatar.png" } document.getElementById("avatar").src = avatar if(user["error"]) { diff --git a/views/settings.html b/views/settings.html new file mode 100644 index 0000000..48fe786 --- /dev/null +++ b/views/settings.html @@ -0,0 +1,11 @@ + + + + + IPost | User settings + + + + + +