Preparations so public API can use tRPC procedures

This commit is contained in:
zomars committed 2022-11-18 16:36:32 -07:00
1 parent b201067f86
commit 030f1c6990
5 files changed
+7 -8

No files matched your search

-1
View File
@@ -73,7 +73,6 @@
"handlebars": "^4.7.7",
"ical.js": "^1.4.0",
"ics": "^2.37.0",
"jimp": "^0.16.1",
"kbar": "^0.1.0-beta.36",
"libphonenumber-js": "^1.10.12",
"lodash": "^4.17.21",
-36
View File
@@ -1,36 +0,0 @@
import jimp from "jimp";
export async function resizeBase64Image(
base64OrUrl: string,
opts?: {
maxSize?: number;
}
) {
if (!base64OrUrl.startsWith("data:")) {
// might be a `https://` or something
return base64OrUrl;
}
const mimeMatch = base64OrUrl.match(/^data:(\w+\/\w+);/);
const mimetype = mimeMatch?.[1];
if (!mimetype) {
throw new Error(`Could not distinguish mimetype`);
}
const buffer = Buffer.from(base64OrUrl.replace(/^data:image\/\w+;base64,/, ""), "base64");
const {
// 96px is the height of the image on https://cal.com/peer
maxSize = 96 * 4,
} = opts ?? {};
const image = await jimp.read(buffer);
if (image.getHeight() !== image.getHeight()) {
// this could be handled later
throw new Error("Image is not a square");
}
const currentSize = Math.max(image.getWidth(), image.getHeight());
if (currentSize > maxSize) {
image.resize(jimp.AUTO, maxSize);
}
const newBuffer = await image.getBufferAsync(mimetype);
return `data:${mimetype};base64,${newBuffer.toString("base64")}`;
}