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:
Yiling-J
2026-09-04 16:39:19 +08:00
committed by GitHub
parent dd0ea05a88
commit 1e60933cdb
15 changed files with 545 additions and 42 deletions
+34
View File
@@ -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()
})
})
+1 -5
View File
@@ -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 {