mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-26 03:57:58 +00:00
feat(agent): store preset avatars as real files in s3 storage (#381)
* feat(agent): store preset avatars as real files in s3 storage * fix(agent): use inline base64 previews in dialog and remove static avatar files * feat(agent): add 4 avatar presets and track avatarPreset in agent config * refactor(agent): consolidate preset avatar base64 data in dtos
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { getAvatarUrl } from './avatar'
|
||||
import { s3Service } from '@shumai/core/src/s3/s3'
|
||||
|
||||
describe('getAvatarUrl', () => {
|
||||
it('returns undefined when imageKeyOrUrl is falsy', async () => {
|
||||
expect(await getAvatarUrl(null)).toBeUndefined()
|
||||
expect(await getAvatarUrl(undefined)).toBeUndefined()
|
||||
expect(await getAvatarUrl('')).toBeUndefined()
|
||||
})
|
||||
|
||||
it('returns http/https URLs directly', async () => {
|
||||
expect(await getAvatarUrl('http://example.com/avatar.png')).toBe(
|
||||
'http://example.com/avatar.png',
|
||||
)
|
||||
expect(await getAvatarUrl('https://example.com/avatar.png')).toBe(
|
||||
'https://example.com/avatar.png',
|
||||
)
|
||||
})
|
||||
|
||||
it('presigns S3 keys', async () => {
|
||||
const presignSpy = vi
|
||||
.spyOn(s3Service, 'presign')
|
||||
.mockResolvedValue('http://s3.local/presigned-url')
|
||||
const url = await getAvatarUrl('files/01JXYZ1234567890ABCDEFGHJK.webp')
|
||||
expect(url).toBe('http://s3.local/presigned-url')
|
||||
expect(presignSpy).toHaveBeenCalledWith(
|
||||
expect.any(String),
|
||||
'files/01JXYZ1234567890ABCDEFGHJK.webp',
|
||||
'GET',
|
||||
)
|
||||
presignSpy.mockRestore()
|
||||
})
|
||||
})
|
||||
@@ -8,11 +8,7 @@ export async function getAvatarUrl(
|
||||
imageKeyOrUrl: string | null | undefined,
|
||||
): Promise<string | undefined> {
|
||||
if (!imageKeyOrUrl) return undefined
|
||||
if (
|
||||
imageKeyOrUrl.startsWith('data:') ||
|
||||
imageKeyOrUrl.startsWith('http://') ||
|
||||
imageKeyOrUrl.startsWith('https://')
|
||||
) {
|
||||
if (imageKeyOrUrl.startsWith('http://') || imageKeyOrUrl.startsWith('https://')) {
|
||||
return imageKeyOrUrl
|
||||
}
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user