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;
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
|
57
server.js
57
server.js
@ -11,7 +11,7 @@ import sharp from "sharp"
|
||||
import SHA from "./extra_modules/SHA.js";
|
||||
import getIP from "./extra_modules/getip.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 { setup as optionssetup } from "./routes/api/options.js";
|
||||
import { setup as allsetup } from "./routes/api/all.js";
|
||||
@ -28,8 +28,12 @@ const __dirname = dirname(__filename)
|
||||
|
||||
async function addTextOnImage(text,buf) {
|
||||
try {
|
||||
const width = text.length*30; // 10 pixels per character
|
||||
const height = 30;
|
||||
let img = await sharp(buf)
|
||||
|
||||
const metadata = await img.metadata()
|
||||
|
||||
const width = metadata.width;
|
||||
const height = metadata.height;
|
||||
|
||||
const svgImage = `
|
||||
<svg width="${width}" height="${height}">
|
||||
@ -40,13 +44,11 @@ async function addTextOnImage(text,buf) {
|
||||
</svg>
|
||||
`;
|
||||
|
||||
let img = await sharp(buf)
|
||||
|
||||
return await img
|
||||
.composite([
|
||||
{
|
||||
input: Buffer.from(svgImage),
|
||||
top: 70,
|
||||
top: 0,
|
||||
left: 0,
|
||||
},
|
||||
]).toBuffer()
|
||||
@ -436,11 +438,6 @@ app.use("/*", function (req, res, 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");
|
||||
/*
|
||||
|
||||
@ -909,30 +906,34 @@ let global_page_variables = {
|
||||
loadfile: load_var,
|
||||
getChannels: get_channels,
|
||||
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(typeof overrideurl != "string")overrideurl = undefined;
|
||||
|
||||
let originalUrl = request.originalUrl.split("?").shift();
|
||||
let originalUrl = overrideurl || request.originalUrl.split("?").shift();
|
||||
|
||||
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)) {
|
||||
path = 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")) {
|
||||
path = 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 }
|
||||
ejs.renderFile(path,global_page_variables,{async: true},async function(err,str){
|
||||
str = await str
|
||||
@ -975,14 +976,30 @@ router.get("/*", async function(request, response) {
|
||||
return
|
||||
}
|
||||
|
||||
if(originalUrl == "/api/documentation/") {
|
||||
readFile(path,function(err,res){
|
||||
response.send(res.toString())
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
console.log(5,"no file found",originalUrl);
|
||||
try {
|
||||
response.status(404).send("No file with that name found");
|
||||
} catch(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) {
|
||||
for (let i = 0; i < 10; i++) { //don't want people spam registering
|
||||
if (!increaseAPICall(req, res))
|
||||
|
@ -1,14 +1,19 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en" dir="ltr">
|
||||
<head>
|
||||
<link rel="stylesheet" href="/css/logon.css">
|
||||
<link rel="stylesheet" href="/css/global.css">
|
||||
<script src="/js/index.js" charset="utf-8"></script>
|
||||
<script src="/js/addnavbar.js" charset="utf-8"></script>
|
||||
<script src="/js/warn_message.js" charset="utf-8"></script>
|
||||
<style>
|
||||
<%- globalcss %>
|
||||
<%- loadfile("./css/logon.css") %>
|
||||
</style>
|
||||
<script async><%- loadfile("./js/index.js") %></script>
|
||||
<script async>
|
||||
<%- warnmessagejs %>
|
||||
</script>
|
||||
<%- cookiebanner %>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<%- navbar %>
|
||||
<header>
|
||||
<h1 class="noselect">IPost</h1>
|
||||
</header>
|
||||
|
@ -7,13 +7,14 @@
|
||||
<%- globalcss %>
|
||||
<%- loadfile("./css/posts.css") %>
|
||||
</style>
|
||||
<script type="text/javascript">
|
||||
<script type="text/javascript" async>
|
||||
<%- httppostjs %>
|
||||
<%- htmlescapejs %>
|
||||
<%- markdownjs %>
|
||||
<%- warnmessagejs %>
|
||||
let channels = <%- JSON.stringify(await getChannels()) %>,user = <%- JSON.stringify(user) %>,posting_id = "<%- getPID() %>"
|
||||
</script>
|
||||
<%- cookiebanner %>
|
||||
</head>
|
||||
<body>
|
||||
<%- navbar %>
|
||||
@ -35,10 +36,11 @@
|
||||
<textarea name="name" id="post-text" rows="8" cols="80"></textarea>
|
||||
<br>
|
||||
<button type="button" name="button" id="post-btn" onclick="postMessage()">Post</button>
|
||||
<div class="files" id="filesDiv"></div>
|
||||
</div>
|
||||
<div class="channelTab" id="channelTab"></div>
|
||||
<div class="posts" id="posts"></div>
|
||||
</div>
|
||||
<script><%- loadfile("./js/posts.js") %></script>
|
||||
<script async><%- loadfile("./js/posts.js") %></script>
|
||||
</body>
|
||||
</html>
|
||||
|
Loading…
x
Reference in New Issue
Block a user