move from jimp to sharp

This commit is contained in:
Mystikfluu 2022-08-29 00:35:10 +02:00
parent c371d34191
commit 3fcb00fb2f
3 changed files with 646 additions and 1253 deletions

1868
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -10,9 +10,9 @@
"express-useragent": "^1.0.15", "express-useragent": "^1.0.15",
"helmet": "^5.1.1", "helmet": "^5.1.1",
"html-minifier-terser": "^7.0.0", "html-minifier-terser": "^7.0.0",
"jimp": "^0.16.1",
"lru-cache": "^7.14.0", "lru-cache": "^7.14.0",
"mysql": "^2.18.1", "mysql": "^2.18.1",
"sharp": "^0.30.7",
"spdy": "^4.0.2", "spdy": "^4.0.2",
"uglify-js": "^3.17.0", "uglify-js": "^3.17.0",
"unsafe_encrypt": "^1.0.4", "unsafe_encrypt": "^1.0.4",

View File

@ -7,11 +7,11 @@ import cookieParser from "cookie-parser";
import * as signature from "cookie-signature"; import * as signature from "cookie-signature";
import * as mysql from "mysql"; import * as mysql from "mysql";
import * as ws from "ws"; import * as ws from "ws";
import Jimp from "jimp"; 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 } from "fs"; import { readFileSync, mkdir, existsSync, appendFile, unlinkSync, writeFileSync } 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";
@ -499,22 +499,15 @@ router.post("/api/setavatar", function (req, res) {
original_log("already have file: ", filename); original_log("already have file: ", filename);
filename = genstring(96) + ".png"; filename = genstring(96) + ".png";
} }
avatar.mv(avatars + "temp_" + filename, function (err) { sharp(avatar.data).resize(100,100).toBuffer().then(function(data){
if (err) { writeFileSync(avatars + filename,data)
return res.status(500).json({ "error": "there's been an internal server error." }); let sql = `update ipost.users set User_Avatar=? where User_Name=?`;
} con.query(sql, [filename, encodeURIComponent(res.locals.username)], function (err, result) {
Jimp.read(avatars + "temp_" + filename).then(function (image) { if (err)
image.resize(100, 100); throw err;
image.write(avatars + filename); res.json({ "success": "updated avatar" });
let sql = `update ipost.users set User_Avatar=? where User_Name=?`;
con.query(sql, [filename, encodeURIComponent(res.locals.username)], function (err, result) {
if (err)
throw err;
res.json({ "success": "updated avatar" });
unlinkSync(avatars + "temp_" + filename);
});
}); });
}); })
}); });
}); });
router.get("/api/getuser", async function (req, res) { router.get("/api/getuser", async function (req, res) {