@@ -18,11 +18,11 @@ import {
1818import { USER_PROFILES_SCHEMA_SQL } from "./user-profiles-schema.js" ;
1919
2020export const MAX_USER_PROFILE_AVATAR_BYTES = 512 * 1024 ;
21- export const USER_PROFILE_AVATAR_MIME_TYPES = [ "image/png" , "image/jpeg" , "image/webp" ] as const ;
21+ const USER_PROFILE_AVATAR_MIME_TYPES = [ "image/png" , "image/jpeg" , "image/webp" ] as const ;
2222
23- export type UserProfileAvatarMime = ( typeof USER_PROFILE_AVATAR_MIME_TYPES ) [ number ] ;
23+ type UserProfileAvatarMime = ( typeof USER_PROFILE_AVATAR_MIME_TYPES ) [ number ] ;
2424
25- export type UserProfile = {
25+ type UserProfile = {
2626 id : string ;
2727 displayName : string | null ;
2828 avatarMime : UserProfileAvatarMime | null ;
@@ -31,19 +31,19 @@ export type UserProfile = {
3131 updatedAt : number ;
3232} ;
3333
34- export type UserProfileListItem = UserProfile & {
34+ type UserProfileListItem = UserProfile & {
3535 emails : string [ ] ;
3636 hasAvatar : boolean ;
3737} ;
3838
39- export type UserProfileAvatar = {
39+ type UserProfileAvatar = {
4040 bytes : Uint8Array ;
4141 mime : UserProfileAvatarMime ;
4242 sha256 : string ;
4343 updatedAt : number ;
4444} ;
4545
46- export type UserProfileAvatarError =
46+ type UserProfileAvatarError =
4747 | { code : "avatar_too_large" ; maxBytes : number }
4848 | { code : "unsupported_avatar_mime" ; mime : string } ;
4949
@@ -81,7 +81,7 @@ type UserProfileListRow = Pick<
8181 UserProfileRow ,
8282 "id" | "display_name" | "avatar_mime" | "merged_into" | "created_at" | "updated_at"
8383> & {
84- has_avatar : number ;
84+ has_avatar : unknown ;
8585} ;
8686
8787const ensuredDatabases = new WeakSet < DatabaseSync > ( ) ;
@@ -146,6 +146,10 @@ function toUserProfileListItem(row: UserProfileListRow, emails: string[]): UserP
146146 } ;
147147}
148148
149+ function hasAvatarColumn ( ) {
150+ return sql `CASE WHEN avatar IS NULL THEN 0 ELSE 1 END` . as ( "has_avatar" ) ;
151+ }
152+
149153function selectUserProfileListItemById ( db : DatabaseSync , profileId : string ) : UserProfileListItem {
150154 const kysely = profileDb ( db ) ;
151155 const profile = executeSqliteQueryTakeFirstSync (
@@ -159,7 +163,7 @@ function selectUserProfileListItemById(db: DatabaseSync, profileId: string): Use
159163 "merged_into" ,
160164 "created_at" ,
161165 "updated_at" ,
162- sql < number > `CASE WHEN avatar IS NULL THEN 0 ELSE 1 END` . as ( "has_avatar" ) ,
166+ hasAvatarColumn ( ) ,
163167 ] )
164168 . where ( "id" , "=" , profileId ) ,
165169 ) ;
@@ -461,7 +465,7 @@ export function listProfiles(options: OpenClawStateDatabaseOptions = {}): UserPr
461465 "merged_into" ,
462466 "created_at" ,
463467 "updated_at" ,
464- sql < number > `CASE WHEN avatar IS NULL THEN 0 ELSE 1 END` . as ( "has_avatar" ) ,
468+ hasAvatarColumn ( ) ,
465469 ] )
466470 . orderBy ( "created_at" , "asc" )
467471 . orderBy ( "id" , "asc" ) ,
0 commit comments