feat(web): add profile management
Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
26
apps/web/server/utils/profile.ts
Normal file
26
apps/web/server/utils/profile.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
export interface ProfileRecord {
|
||||
id: string
|
||||
display_name: string
|
||||
description: string
|
||||
avatar_path: string | null
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
export function profileAvatarUrl(profile: Pick<ProfileRecord, 'avatar_path' | 'updated_at'>, supabaseUrl: string): string | null {
|
||||
if (!profile.avatar_path) return null
|
||||
const encodedPath = profile.avatar_path.split('/').map(encodeURIComponent).join('/')
|
||||
const version = encodeURIComponent(profile.updated_at)
|
||||
return `${supabaseUrl.replace(/\/$/, '')}/storage/v1/object/public/profile-avatars/${encodedPath}?v=${version}`
|
||||
}
|
||||
|
||||
export function visibleProfile(profile: ProfileRecord, supabaseUrl: string) {
|
||||
return {
|
||||
id: profile.id,
|
||||
display_name: profile.display_name,
|
||||
description: profile.description,
|
||||
avatar_url: profileAvatarUrl(profile, supabaseUrl),
|
||||
created_at: profile.created_at,
|
||||
updated_at: profile.updated_at,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user