@@ -268,9 +268,13 @@ pub async fn msg_add_comment(data: &proto::client::client_to_server_cmd::AddComm
268268 // Convert data URI to bytes
269269 let img_uri = DataUrl :: process ( & d) . map_err ( |e| anyhow ! ( "Invalid drawing data URI" ) ) ?;
270270
271- if img_uri. mime_type ( ) . type_ != "image" || img_uri. mime_type ( ) . subtype != "webp" {
272- bail ! ( "Invalid mimetype in drawing: {:?}" , img_uri. mime_type( ) )
273- }
271+ let mime = img_uri. mime_type ( ) ;
272+ let ext = match ( mime. type_ . as_str ( ) , mime. subtype . as_str ( ) ) {
273+ ( "image" , "webp" ) => "webp" ,
274+ ( "image" , "jpeg" ) => "jpg" ,
275+ ( "image" , "png" ) => "png" ,
276+ _ => bail ! ( "Invalid mimetype in drawing: {:?}" , mime) ,
277+ } ;
274278 let img_data = img_uri. decode_to_vec ( ) . map_err ( |e| anyhow ! ( "Failed to decode drawing data URI: {:?}" , e) ) ?;
275279
276280 // Make up a filename
@@ -281,7 +285,7 @@ pub async fn msg_add_comment(data: &proto::client::client_to_server_cmd::AddComm
281285 hex:: encode ( result)
282286 }
283287 let short_csum = sha256hex ( img_data. 0 . as_ref ( ) ) [ ..16 ] . to_string ( ) ;
284- let fname = format ! ( "{}.webp " , short_csum) ;
288+ let fname = format ! ( "{}.{} " , short_csum, ext ) ;
285289
286290 // Write to file
287291 let drawing_path = server. media_files_dir . join ( & media_file_id) . join ( "drawings" ) . join ( & fname) ;
0 commit comments