feat: add i18n and avatar upload
This commit is contained in:
@@ -25,6 +25,20 @@ export async function saveUploadedImage(
|
||||
return { imageUrl: relative };
|
||||
}
|
||||
|
||||
export async function saveUploadedAvatar(
|
||||
userId: string,
|
||||
mime: string,
|
||||
buffer: Buffer,
|
||||
): Promise<{ imageUrl: string }> {
|
||||
const ext = MIME_TO_EXT[mime];
|
||||
if (!ext) throw new ValidationError('Unsupported image type');
|
||||
const filename = `${userId}-${nanoid(8)}.${ext}`;
|
||||
const relative = `/uploads/avatar/${filename}`;
|
||||
const absPath = resolve(env.UPLOADS_DIR, 'avatar', filename);
|
||||
await writeFile(absPath, buffer);
|
||||
return { imageUrl: relative };
|
||||
}
|
||||
|
||||
export async function deleteLocalImageIfAny(imageUrl: string | null): Promise<void> {
|
||||
if (!imageUrl) return;
|
||||
if (!imageUrl.startsWith('/uploads/')) return;
|
||||
|
||||
Reference in New Issue
Block a user