mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-27 19:34:38 +00:00
feat(backend): generate presigned avatar URLs for collection and share link creators
This commit is contained in:
@@ -8,6 +8,7 @@ import {
|
||||
AddAssetToShareRequest,
|
||||
} from '@shumai/dtos'
|
||||
import { PaginatedData, paginateQuery } from '@shumai/core/src/pagination'
|
||||
import { getAvatarUrl } from '@shumai/core/src/user/avatar'
|
||||
|
||||
export class ShareService {
|
||||
async createShareLink(
|
||||
@@ -64,7 +65,7 @@ export class ShareService {
|
||||
include: { creator: true },
|
||||
})
|
||||
|
||||
return this.toShareLinkInfo(shareLink)
|
||||
return await this.toShareLinkInfo(shareLink)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -95,7 +96,7 @@ export class ShareService {
|
||||
})
|
||||
}
|
||||
|
||||
return this.toShareLinkInfo(updated)
|
||||
return await this.toShareLinkInfo(updated)
|
||||
}
|
||||
|
||||
async deleteShareLink(shareLinkId: string): Promise<void> {
|
||||
@@ -128,7 +129,7 @@ export class ShareService {
|
||||
take,
|
||||
orderBy: { createdAt: 'desc' },
|
||||
})
|
||||
return links.map((l) => this.toShareLinkInfo(l))
|
||||
return await Promise.all(links.map((l) => this.toShareLinkInfo(l)))
|
||||
},
|
||||
() => prisma.shareLink.count({ where }),
|
||||
req,
|
||||
@@ -141,7 +142,7 @@ export class ShareService {
|
||||
include: { creator: true },
|
||||
})
|
||||
if (!shareLink) throw new Error('Share link not found')
|
||||
return this.toShareLinkInfo(shareLink)
|
||||
return await this.toShareLinkInfo(shareLink)
|
||||
}
|
||||
|
||||
async addAssetToShare(shareLinkId: string, req: AddAssetToShareRequest): Promise<number> {
|
||||
@@ -289,8 +290,9 @@ export class ShareService {
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
private toShareLinkInfo(l: any): ShareLinkInfo {
|
||||
private async toShareLinkInfo(l: any): Promise<ShareLinkInfo> {
|
||||
const isExpired = l.expireAt ? new Date(l.expireAt) < new Date() : false
|
||||
const avatarUrl = l.creator ? await getAvatarUrl(l.creator.image) : undefined
|
||||
return {
|
||||
id: l.id,
|
||||
name: l.name,
|
||||
@@ -304,9 +306,7 @@ export class ShareService {
|
||||
isExpired,
|
||||
createdAt: l.createdAt.toISOString(),
|
||||
updatedAt: l.updatedAt.toISOString(),
|
||||
creator: l.creator
|
||||
? { id: l.creator.id, name: l.creator.name, image: l.creator.image ?? undefined }
|
||||
: null,
|
||||
creator: l.creator ? { id: l.creator.id, name: l.creator.name, image: avatarUrl } : null,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user