fix and improve various things
This commit is contained in:
parent
4342f8a69c
commit
ef3d5b3817
Binary file not shown.
Before Width: | Height: | Size: 212 B After Width: | Height: | Size: 517 B |
@ -369,6 +369,12 @@ function addFile(file) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
files[files.length]=file
|
files[files.length]=file
|
||||||
|
const fileimg = createElement("img")
|
||||||
|
console.log(file.name,file.name.lastIndexOf("\."),file.name.substring(file.name.lastIndexOf("\.")+1));
|
||||||
|
fileimg.src = "/api/getFileIcon/"+file.name.substring(file.name.lastIndexOf("\.")+1)
|
||||||
|
|
||||||
|
getById("filesDiv").appendChild(fileimg)
|
||||||
|
//filesDiv
|
||||||
console.log("File added: ", file.name, file.type, file.size);
|
console.log("File added: ", file.name, file.type, file.size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
59
server.js
59
server.js
@ -11,7 +11,7 @@ import sharp from "sharp"
|
|||||||
import SHA from "./extra_modules/SHA.js";
|
import SHA from "./extra_modules/SHA.js";
|
||||||
import getIP from "./extra_modules/getip.js";
|
import getIP from "./extra_modules/getip.js";
|
||||||
import unsign from "./extra_modules/unsign.js";
|
import unsign from "./extra_modules/unsign.js";
|
||||||
import { readFileSync, mkdir, existsSync, appendFile, unlinkSync, writeFileSync } from "fs";
|
import { readFileSync, mkdir, existsSync, appendFile, unlinkSync, writeFileSync, readFile } from "fs";
|
||||||
import { format } from "util";
|
import { format } from "util";
|
||||||
import { setup as optionssetup } from "./routes/api/options.js";
|
import { setup as optionssetup } from "./routes/api/options.js";
|
||||||
import { setup as allsetup } from "./routes/api/all.js";
|
import { setup as allsetup } from "./routes/api/all.js";
|
||||||
@ -28,8 +28,12 @@ const __dirname = dirname(__filename)
|
|||||||
|
|
||||||
async function addTextOnImage(text,buf) {
|
async function addTextOnImage(text,buf) {
|
||||||
try {
|
try {
|
||||||
const width = text.length*30; // 10 pixels per character
|
let img = await sharp(buf)
|
||||||
const height = 30;
|
|
||||||
|
const metadata = await img.metadata()
|
||||||
|
|
||||||
|
const width = metadata.width;
|
||||||
|
const height = metadata.height;
|
||||||
|
|
||||||
const svgImage = `
|
const svgImage = `
|
||||||
<svg width="${width}" height="${height}">
|
<svg width="${width}" height="${height}">
|
||||||
@ -40,13 +44,11 @@ async function addTextOnImage(text,buf) {
|
|||||||
</svg>
|
</svg>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
let img = await sharp(buf)
|
|
||||||
|
|
||||||
return await img
|
return await img
|
||||||
.composite([
|
.composite([
|
||||||
{
|
{
|
||||||
input: Buffer.from(svgImage),
|
input: Buffer.from(svgImage),
|
||||||
top: 70,
|
top: 0,
|
||||||
left: 0,
|
left: 0,
|
||||||
},
|
},
|
||||||
]).toBuffer()
|
]).toBuffer()
|
||||||
@ -436,11 +438,6 @@ app.use("/*", function (req, res, next) {
|
|||||||
}
|
}
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
router.get("/", function (req, res) {
|
|
||||||
if (!increaseUSERCall(req, res))
|
|
||||||
return;
|
|
||||||
res.sendFile(dir + "views/index.html");
|
|
||||||
});
|
|
||||||
console.log(5, "finished loading user routes, starting with api routes");
|
console.log(5, "finished loading user routes, starting with api routes");
|
||||||
/*
|
/*
|
||||||
|
|
||||||
@ -909,30 +906,34 @@ let global_page_variables = {
|
|||||||
loadfile: load_var,
|
loadfile: load_var,
|
||||||
getChannels: get_channels,
|
getChannels: get_channels,
|
||||||
getPID: get_pid,
|
getPID: get_pid,
|
||||||
getDMPID: get_dmpid
|
getDMPID: get_dmpid,
|
||||||
|
cookiebanner: `<script id="cookieyes" type="text/javascript" src="https://cdn-cookieyes.com/client_data/3cf33f6b631f3587bf83813b/script.js"></script>`
|
||||||
}
|
}
|
||||||
|
|
||||||
router.get("/*", async function(request, response) {
|
async function handleUserFiles(request, response, overrideurl) {
|
||||||
if (!increaseUSERCall(request, response))return;
|
if (!increaseUSERCall(request, response))return;
|
||||||
|
if(typeof overrideurl != "string")overrideurl = undefined;
|
||||||
let originalUrl = request.originalUrl.split("?").shift();
|
|
||||||
|
let originalUrl = overrideurl || request.originalUrl.split("?").shift();
|
||||||
|
|
||||||
let path = ""
|
let path = ""
|
||||||
|
|
||||||
if (existsSync(dir + "views/" + originalUrl + ".html")) {
|
|
||||||
path = dir + "views/" + originalUrl + ".html"
|
|
||||||
//return response.sendFile(dir + "views/" + originalUrl + ".html");
|
|
||||||
}
|
|
||||||
if (existsSync(dir + "views" + originalUrl)) {
|
if (existsSync(dir + "views" + originalUrl)) {
|
||||||
path = dir + "views" + originalUrl
|
path = dir + "views" + originalUrl
|
||||||
//return response.sendFile(dir + "views" + originalUrl);
|
//return response.sendFile(dir + "views" + originalUrl);
|
||||||
}
|
}
|
||||||
|
if (existsSync(dir + "views/" + originalUrl + "index.html")) {
|
||||||
|
path = dir + "views/" + originalUrl + "index.html"
|
||||||
|
}
|
||||||
|
if (existsSync(dir + "views/" + originalUrl + ".html")) {
|
||||||
|
path = dir + "views/" + originalUrl + ".html"
|
||||||
|
//return response.sendFile(dir + "views/" + originalUrl + ".html");
|
||||||
|
}
|
||||||
if (existsSync(dir + "views" + originalUrl + ".html")) {
|
if (existsSync(dir + "views" + originalUrl + ".html")) {
|
||||||
path = dir + "views" + originalUrl + ".html"
|
path = dir + "views" + originalUrl + ".html"
|
||||||
//return response.sendFile(dir + "views" + originalUrl + ".html");
|
//return response.sendFile(dir + "views" + originalUrl + ".html");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(path != "" && originalUrl != "/favicon.ico") {
|
if(path != "" && originalUrl != "/favicon.ico" && originalUrl != "/api/documentation/") {
|
||||||
global_page_variables.user = { "username": response.locals.username, "bio": response.locals.bio, "avatar": response.locals.avatar }
|
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){
|
ejs.renderFile(path,global_page_variables,{async: true},async function(err,str){
|
||||||
str = await str
|
str = await str
|
||||||
@ -975,14 +976,30 @@ router.get("/*", async function(request, response) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(originalUrl == "/api/documentation/") {
|
||||||
|
readFile(path,function(err,res){
|
||||||
|
response.send(res.toString())
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
console.log(5,"no file found",originalUrl);
|
console.log(5,"no file found",originalUrl);
|
||||||
try {
|
try {
|
||||||
response.status(404).send("No file with that name found");
|
response.status(404).send("No file with that name found");
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
router.get("/", function (req, res) {
|
||||||
|
// if (!increaseUSERCall(req, res))
|
||||||
|
// return;
|
||||||
|
handleUserFiles(req,res,"/index")
|
||||||
|
//res.sendFile(dir + "views/index.html");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
router.get("/*", handleUserFiles);
|
||||||
|
|
||||||
router.post("/register", async function (req, res) {
|
router.post("/register", async function (req, res) {
|
||||||
for (let i = 0; i < 10; i++) { //don't want people spam registering
|
for (let i = 0; i < 10; i++) { //don't want people spam registering
|
||||||
if (!increaseAPICall(req, res))
|
if (!increaseAPICall(req, res))
|
||||||
|
@ -1,14 +1,19 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en" dir="ltr">
|
<html lang="en" dir="ltr">
|
||||||
<head>
|
<head>
|
||||||
<link rel="stylesheet" href="/css/logon.css">
|
<style>
|
||||||
<link rel="stylesheet" href="/css/global.css">
|
<%- globalcss %>
|
||||||
<script src="/js/index.js" charset="utf-8"></script>
|
<%- loadfile("./css/logon.css") %>
|
||||||
<script src="/js/addnavbar.js" charset="utf-8"></script>
|
</style>
|
||||||
<script src="/js/warn_message.js" charset="utf-8"></script>
|
<script async><%- loadfile("./js/index.js") %></script>
|
||||||
|
<script async>
|
||||||
|
<%- warnmessagejs %>
|
||||||
|
</script>
|
||||||
|
<%- cookiebanner %>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
<%- navbar %>
|
||||||
<header>
|
<header>
|
||||||
<h1 class="noselect">IPost</h1>
|
<h1 class="noselect">IPost</h1>
|
||||||
</header>
|
</header>
|
||||||
|
@ -7,13 +7,14 @@
|
|||||||
<%- globalcss %>
|
<%- globalcss %>
|
||||||
<%- loadfile("./css/posts.css") %>
|
<%- loadfile("./css/posts.css") %>
|
||||||
</style>
|
</style>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript" async>
|
||||||
<%- httppostjs %>
|
<%- httppostjs %>
|
||||||
<%- htmlescapejs %>
|
<%- htmlescapejs %>
|
||||||
<%- markdownjs %>
|
<%- markdownjs %>
|
||||||
<%- warnmessagejs %>
|
<%- warnmessagejs %>
|
||||||
let channels = <%- JSON.stringify(await getChannels()) %>,user = <%- JSON.stringify(user) %>,posting_id = "<%- getPID() %>"
|
let channels = <%- JSON.stringify(await getChannels()) %>,user = <%- JSON.stringify(user) %>,posting_id = "<%- getPID() %>"
|
||||||
</script>
|
</script>
|
||||||
|
<%- cookiebanner %>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<%- navbar %>
|
<%- navbar %>
|
||||||
@ -35,10 +36,11 @@
|
|||||||
<textarea name="name" id="post-text" rows="8" cols="80"></textarea>
|
<textarea name="name" id="post-text" rows="8" cols="80"></textarea>
|
||||||
<br>
|
<br>
|
||||||
<button type="button" name="button" id="post-btn" onclick="postMessage()">Post</button>
|
<button type="button" name="button" id="post-btn" onclick="postMessage()">Post</button>
|
||||||
|
<div class="files" id="filesDiv"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="channelTab" id="channelTab"></div>
|
<div class="channelTab" id="channelTab"></div>
|
||||||
<div class="posts" id="posts"></div>
|
<div class="posts" id="posts"></div>
|
||||||
</div>
|
</div>
|
||||||
<script><%- loadfile("./js/posts.js") %></script>
|
<script async><%- loadfile("./js/posts.js") %></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user