mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 16:23:06 +10:00
feat: avatar images
This commit is contained in:
26
packages/lib/server-only/profile/get-avatar-image.ts
Normal file
26
packages/lib/server-only/profile/get-avatar-image.ts
Normal file
@ -0,0 +1,26 @@
|
||||
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(),
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user