feat(user-avatar): add support for uploading, cropping, and displaying user avatars

This commit is contained in:
yiling
2026-06-03 19:56:07 +08:00
parent ee2a7d3281
commit e65b3edbee
19 changed files with 638 additions and 54 deletions
+21
View File
@@ -0,0 +1,21 @@
import { s3Service } from '@shumai/core/src/s3/s3'
/**
* Returns the signed avatar URL if the image is an S3 key,
* or returns it directly if it's already an external URL (e.g. OAuth avatar).
*/
export async function getAvatarUrl(
imageKeyOrUrl: string | null | undefined,
): Promise<string | undefined> {
if (!imageKeyOrUrl) return undefined
if (imageKeyOrUrl.startsWith('http://') || imageKeyOrUrl.startsWith('https://')) {
return imageKeyOrUrl
}
try {
const bucket = process.env.S3_BUCKET || 'shumai'
return await s3Service.presign(bucket, imageKeyOrUrl, 'GET')
} catch (e) {
console.error(`Failed to presign avatar URL for key ${imageKeyOrUrl}:`, e)
return undefined
}
}