From 4342f8a69c0b00964984ded18c3b457b6490d6db Mon Sep 17 00:00:00 2001 From: Mystikfluu Date: Tue, 30 Aug 2022 02:41:53 +0200 Subject: [PATCH] add new api endpoint --- images/empty_file.png | Bin 0 -> 212 bytes server.js | 46 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 images/empty_file.png diff --git a/images/empty_file.png b/images/empty_file.png new file mode 100644 index 0000000000000000000000000000000000000000..e5e75eb81646672c72fbea19bf62c9d74630b656 GIT binary patch literal 212 zcmeAS@N?(olHy`uVBq!ia0vp^DL_1pi5WOJ zDbKv%_gn4tyS`kkI=i>%%1Sl9ootKrR42XL + + ${text} + + `; + + let img = await sharp(buf) + + return await img + .composite([ + { + input: Buffer.from(svgImage), + top: 70, + left: 0, + }, + ]).toBuffer() + } catch (error) { + console.log(error); + } +} + /** * makes sure that a given folder exists, if it doesn't it creates one for you * @param {string} path the path of the folder @@ -434,6 +463,18 @@ const get_pid = postsetup(router, con, commonfunctions); dmsPersonalMessagessetup(router, con, commonfunctions); const get_dmpid = dmspostsetup(router, con, commonfunctions); +router.get("/api/getFileIcon/*",async function(req,res){ + let path = req.path.split("/api/getFileIcon/")[1] + if(path.length > 4) { + res.status(400).json({"error":"file ending is too long"}) + return; + } + addTextOnImage(path,await sharp("./images/empty_file.png").toBuffer()).then(buf => { + res.set("content-type","image/png") + res.send(buf) + }) +}) + router.get("/api/search", async function (req, res) { res.set("Access-Control-Allow-Origin", ""); let type = req.query.type; @@ -499,7 +540,10 @@ router.post("/api/setavatar", function (req, res) { original_log("already have file: ", filename); filename = genstring(96) + ".png"; } - sharp(avatar.data).resize(100,100).toBuffer().then(function(data){ + sharp(avatar.data).resize({ + width: 100, + height: 100 + }).toBuffer().then(function(data){ writeFileSync(avatars + filename,data) let sql = `update ipost.users set User_Avatar=? where User_Name=?`; con.query(sql, [filename, encodeURIComponent(res.locals.username)], function (err, result) {