@@ -39,6 +39,7 @@ pub fn routes() -> Vec<rocket::Route> {
39
39
api_key,
40
40
rotate_api_key,
41
41
get_known_device,
42
+ put_avatar,
42
43
]
43
44
}
44
45
@@ -228,6 +229,32 @@ async fn post_profile(data: JsonUpcase<ProfileData>, headers: Headers, mut conn:
228
229
Ok ( Json ( user. to_json ( & mut conn) . await ) )
229
230
}
230
231
232
+ #[ derive( Deserialize ) ]
233
+ #[ allow( non_snake_case) ]
234
+ struct AvatarData {
235
+ AvatarColor : Option < String > ,
236
+ }
237
+
238
+ #[ put( "/accounts/avatar" , data = "<data>" ) ]
239
+ async fn put_avatar ( data : JsonUpcase < AvatarData > , headers : Headers , mut conn : DbConn ) -> JsonResult {
240
+ let data: AvatarData = data. into_inner ( ) . data ;
241
+
242
+ // It looks like it only supports the 6 hex color format.
243
+ // If you try to add the short value it will not show that color.
244
+ // Check and force 7 chars, including the #.
245
+ if let Some ( color) = & data. AvatarColor {
246
+ if color. len ( ) != 7 {
247
+ err ! ( "The field AvatarColor must be a HTML/Hex color code with a length of 7 characters" )
248
+ }
249
+ }
250
+
251
+ let mut user = headers. user ;
252
+ user. avatar_color = data. AvatarColor ;
253
+
254
+ user. save ( & mut conn) . await ?;
255
+ Ok ( Json ( user. to_json ( & mut conn) . await ) )
256
+ }
257
+
231
258
#[ get( "/users/<uuid>/public-key" ) ]
232
259
async fn get_public_keys ( uuid : String , _headers : Headers , mut conn : DbConn ) -> JsonResult {
233
260
let user = match User :: find_by_uuid ( & uuid, & mut conn) . await {
0 commit comments