mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 08:13:56 +10:00
27 lines
512 B
TypeScript
27 lines
512 B
TypeScript
import sharp from 'sharp';
|
|
|
|
import { prisma } from '@documenso/prisma';
|
|
|
|
export type GetAvatarImageOptions = {
|
|
id: string;
|
|
};
|
|
|
|
export const getAvatarImage = async ({ id }: GetAvatarImageOptions) => {
|
|
const avatarImage = await prisma.avatarImage.findFirst({
|
|
where: {
|
|
id,
|
|
},
|
|
});
|
|
|
|
if (!avatarImage) {
|
|
return null;
|
|
}
|
|
|
|
const bytes = Buffer.from(avatarImage.bytes, 'base64');
|
|
|
|
return {
|
|
contentType: 'image/jpeg',
|
|
content: await sharp(bytes).toFormat('jpeg').toBuffer(),
|
|
};
|
|
};
|