add bot identifier to posts
This commit is contained in:
parent
ae538b33af
commit
824eb99851
@ -24,6 +24,7 @@ CREATE TABLE `posts` (
|
|||||||
`post_text` varchar(4000) NOT NULL,
|
`post_text` varchar(4000) NOT NULL,
|
||||||
`post_time` bigint NOT NULL,
|
`post_time` bigint NOT NULL,
|
||||||
`post_special_text` varchar(100) DEFAULT 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`)
|
PRIMARY KEY (`post_id`)
|
||||||
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
||||||
|
@ -38,6 +38,10 @@
|
|||||||
margin-left: 5px;
|
margin-left: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.boticon {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
.mention {
|
.mention {
|
||||||
color: blue;
|
color: blue;
|
||||||
}
|
}
|
||||||
|
BIN
images/bot.png
Normal file
BIN
images/bot.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.1 KiB |
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
19
js/posts.js
19
js/posts.js
@ -41,14 +41,14 @@ async function getavatar(username) {
|
|||||||
if(user) {
|
if(user) {
|
||||||
user = "/avatars/"+user
|
user = "/avatars/"+user
|
||||||
} else {
|
} else {
|
||||||
user = "/default_avatar.png"
|
user = "/images/default_avatar.png"
|
||||||
}
|
}
|
||||||
user_cache[username]=user
|
user_cache[username]=user
|
||||||
}
|
}
|
||||||
return user
|
return user
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createPost(username,text,time,specialtext,postid) {
|
async function createPost(username,text,time,specialtext,postid,isbot) {
|
||||||
if(!specialtext)specialtext=""
|
if(!specialtext)specialtext=""
|
||||||
const newDiv = document.createElement("div");
|
const newDiv = document.createElement("div");
|
||||||
const newP = document.createElement("p");
|
const newP = document.createElement("p");
|
||||||
@ -56,6 +56,11 @@ async function createPost(username,text,time,specialtext,postid) {
|
|||||||
const newSpan2 = document.createElement("span");
|
const newSpan2 = document.createElement("span");
|
||||||
const newSpan3 = document.createElement("span");
|
const newSpan3 = document.createElement("span");
|
||||||
const avatar = document.createElement("img");
|
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);
|
const newUsername = document.createTextNode(username);
|
||||||
let timedate = new Date(time)
|
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"
|
if(timedate=="Thu Jan 01 1970 01:00:00 GMT+0100 (Central European Standard Time)")time="unknown time"
|
||||||
const newTime = document.createTextNode(time)
|
const newTime = document.createTextNode(time)
|
||||||
const newSpecialText = document.createTextNode(specialtext)
|
const newSpecialText = document.createTextNode(specialtext)
|
||||||
|
|
||||||
newDiv.classList.add("post");
|
newDiv.classList.add("post");
|
||||||
newSpan3.classList.add("specialtext")
|
newSpan3.classList.add("specialtext")
|
||||||
|
|
||||||
@ -90,6 +94,11 @@ async function createPost(username,text,time,specialtext,postid) {
|
|||||||
newP.appendChild(newSpan2)
|
newP.appendChild(newSpan2)
|
||||||
if(specialtext != "")newP.appendChild(spacerTextNode())
|
if(specialtext != "")newP.appendChild(spacerTextNode())
|
||||||
newP.appendChild(newSpan3)
|
newP.appendChild(newSpan3)
|
||||||
|
if(isbot==1){
|
||||||
|
console.log(boticon);
|
||||||
|
newP.appendChild(spacerTextNode())
|
||||||
|
newP.appendChild(boticon)
|
||||||
|
}
|
||||||
newP.appendChild(spacerTextNode())
|
newP.appendChild(spacerTextNode())
|
||||||
// |\>.</|
|
// |\>.</|
|
||||||
newP.innerHTML += `<button onclick="reply('${username}')">Reply to this Post</button>`
|
newP.innerHTML += `<button onclick="reply('${username}')">Reply to this Post</button>`
|
||||||
@ -119,9 +128,9 @@ async function main(){
|
|||||||
document.getElementById("posts").innerHTML = ""
|
document.getElementById("posts").innerHTML = ""
|
||||||
for(i in all_posts) {
|
for(i in all_posts) {
|
||||||
let item = all_posts[i]
|
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")
|
let links = document.getElementsByClassName("insertedlink")
|
||||||
for (let i = 0; i < links.length; i++) {
|
for (let i = 0; i < links.length; i++) {
|
||||||
links[i].innerText = links[i].innerText.split("\/\/")[1].split("\/")[0]
|
links[i].innerText = links[i].innerText.split("\/\/")[1].split("\/")[0]
|
||||||
|
@ -72,7 +72,7 @@ async function setuser() {
|
|||||||
if(avatar) {
|
if(avatar) {
|
||||||
avatar = "/avatars/"+avatar
|
avatar = "/avatars/"+avatar
|
||||||
} else {
|
} else {
|
||||||
avatar = "default_avatar.png"
|
avatar = "/images/default_avatar.png"
|
||||||
}
|
}
|
||||||
document.getElementById("user").innerText = `User: ${username}`;
|
document.getElementById("user").innerText = `User: ${username}`;
|
||||||
document.getElementById("bio").placeholder = decodeURIComponent(bio);
|
document.getElementById("bio").placeholder = decodeURIComponent(bio);
|
||||||
|
19
server.js
19
server.js
@ -339,6 +339,7 @@ router.use("/api/*",async function(req,res,next) {
|
|||||||
} else {
|
} else {
|
||||||
unsigned = `${req.body.user} ${SHA256(req.body.pass,req.body.user,HASHES_COOKIE)}`
|
unsigned = `${req.body.user} ${SHA256(req.body.pass,req.body.user,HASHES_COOKIE)}`
|
||||||
//basically we generate the unsigned 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 sql = `select User_Name,User_Bio,User_Avatar from zerotwohub.users where User_Name=? and User_PW=?;`
|
||||||
let values = unsigned.split(" ")
|
let values = unsigned.split(" ")
|
||||||
@ -490,8 +491,8 @@ router.post("/api/post", async function(req,res) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let sql = `insert into zerotwohub.posts (post_user_name,post_text,post_time,post_receiver_name) values (?,?,?,?);`
|
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]
|
let values = [encodeURIComponent(res.locals.username),req.body.message,Date.now(),req.body.receiver,res.locals.isbot]
|
||||||
con.query(sql, values, function (err, result) {
|
con.query(sql, values, function (err, result) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
|
||||||
@ -510,7 +511,7 @@ router.get("/api/getPosts/*", async function(req,res) {
|
|||||||
|
|
||||||
router.get("/api/getPosts", async function(req,res) {
|
router.get("/api/getPosts", async function(req,res) {
|
||||||
res.set("Access-Control-Allow-Origin","")
|
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) {
|
con.query(sql, [], function (err, result) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
res.json(result)
|
res.json(result)
|
||||||
@ -519,7 +520,7 @@ router.get("/api/getPosts", async function(req,res) {
|
|||||||
|
|
||||||
router.get("/api/getPersonalPosts", async function(req,res) {
|
router.get("/api/getPersonalPosts", async function(req,res) {
|
||||||
res.set("Access-Control-Allow-Origin","")
|
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) {
|
con.query(sql, [encodeURIComponent(res.locals.username)], function (err, result) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
res.json(result)
|
res.json(result)
|
||||||
@ -678,6 +679,16 @@ router.get("/js/*", (request, response) => {
|
|||||||
return;
|
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) => {
|
router.get("/avatars/*", (request, response, next) => {
|
||||||
if(!increaseUSERCall(request,response))return
|
if(!increaseUSERCall(request,response))return
|
||||||
let originalUrl = request.originalUrl.split("?").shift()
|
let originalUrl = request.originalUrl.split("?").shift()
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
if(avatar) {
|
if(avatar) {
|
||||||
avatar = "/avatars/"+avatar
|
avatar = "/avatars/"+avatar
|
||||||
} else {
|
} else {
|
||||||
avatar = "/default_avatar.png"
|
avatar = "/images/default_avatar.png"
|
||||||
}
|
}
|
||||||
document.getElementById("avatar").src = avatar
|
document.getElementById("avatar").src = avatar
|
||||||
if(user["error"]) {
|
if(user["error"]) {
|
||||||
|
11
views/settings.html
Normal file
11
views/settings.html
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en" dir="ltr">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>IPost | User settings</title>
|
||||||
|
<link rel="stylesheet" href="/css/global.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
x
Reference in New Issue
Block a user