feat(backend): generate presigned avatar URLs for collection and share link creators

This commit is contained in:
yiling
2026-06-06 12:25:07 +08:00
parent d3dd5f9b0c
commit 02e845ef71
2 changed files with 17 additions and 17 deletions
+9 -9
View File
@@ -2,6 +2,7 @@ import { zValidator } from '@hono/zod-validator'
import { Hono } from 'hono'
import { collectionService } from '@shumai/core/src/collection/collection'
import { authzService, Permission, ResourceType } from '@shumai/core/src/authz/authz'
import { getAvatarUrl } from '@shumai/core/src/user/avatar'
import {
createCollectionRequestSchema,
updateCollectionRequestSchema,
@@ -13,9 +14,10 @@ import type { Prisma } from '@shumai/db'
type User = Prisma.UserGetPayload<Record<string, never>>
function toCollectionInfo(
async function toCollectionInfo(
c: Prisma.CollectionGetPayload<{ include: { creator: true } }>,
): CollectionInfo {
): Promise<CollectionInfo> {
const avatarUrl = c.creator ? await getAvatarUrl(c.creator.image) : undefined
return {
id: c.id,
name: c.name,
@@ -23,9 +25,7 @@ function toCollectionInfo(
projectId: c.projectId,
createdAt: c.createdAt.toISOString(),
updatedAt: c.updatedAt.toISOString(),
creator: c.creator
? { id: c.creator.id, name: c.creator.name, image: c.creator.image ?? undefined }
: null,
creator: c.creator ? { id: c.creator.id, name: c.creator.name, image: avatarUrl } : null,
}
}
@@ -46,7 +46,7 @@ const route = new Hono<{ Variables: { user: User } }>()
})
const collection = await collectionService.createCollection(projectId, req, user.id)
return c.json(toCollectionInfo(collection))
return c.json(await toCollectionInfo(collection))
},
)
.get(
@@ -67,7 +67,7 @@ const route = new Hono<{ Variables: { user: User } }>()
const collections = await collectionService.listCollections(projectId, req)
return c.json({
// eslint-disable-next-line @typescript-eslint/no-explicit-any
data: collections.data.map((c: any) => toCollectionInfo(c)),
data: await Promise.all(collections.data.map((c: any) => toCollectionInfo(c))),
pageInfo: collections.pageInfo,
})
},
@@ -88,7 +88,7 @@ const route = new Hono<{ Variables: { user: User } }>()
return c.json({ error: 'Collection not found' }, 404)
}
return c.json(toCollectionInfo(collection))
return c.json(await toCollectionInfo(collection))
})
.patch(
'/collections/:collectionId',
@@ -106,7 +106,7 @@ const route = new Hono<{ Variables: { user: User } }>()
})
const collection = await collectionService.updateCollection(collectionId, req)
return c.json(toCollectionInfo(collection))
return c.json(await toCollectionInfo(collection))
},
)
.delete('/collections/:collectionId', async (c) => {