@@ -80,6 +80,7 @@ struct TrackerClaimsResponse {
8080struct TrackerUidClaimResponse {
8181 uid : String ,
8282 nickname : String ,
83+ region : String ,
8384 owner_username : Option < String > ,
8485 claim_source : String ,
8586 has_profile : bool ,
@@ -90,7 +91,8 @@ struct TrackerUidClaimResponse {
9091#[ derive( Deserialize , ToSchema ) ]
9192#[ serde( rename_all = "camelCase" ) ]
9293struct TrackerClaimUpdateRequest {
93- nickname : String ,
94+ nickname : Option < String > ,
95+ region : Option < String > ,
9496}
9597
9698#[ derive( Serialize , ToSchema ) ]
@@ -285,15 +287,30 @@ async fn put_tracker_uid_claim(
285287 let Some ( uid) = validate_tracker_uid ( & uid) else {
286288 return Ok ( HttpResponse :: BadRequest ( ) . body ( "Invalid tracker UID" ) ) ;
287289 } ;
288- let Some ( nickname) = validate_tracker_nickname ( & body. nickname ) else {
289- return Ok ( HttpResponse :: BadRequest ( ) . body ( "Invalid tracker nickname" ) ) ;
290+ let nickname = match body. nickname . as_deref ( ) {
291+ Some ( value) => match validate_tracker_nickname ( value) {
292+ Some ( value) => Some ( value) ,
293+ None => return Ok ( HttpResponse :: BadRequest ( ) . body ( "Invalid tracker nickname" ) ) ,
294+ } ,
295+ None => None ,
290296 } ;
297+ let region = match body. region . as_deref ( ) {
298+ Some ( value) => match validate_tracker_region ( value) {
299+ Some ( value) => Some ( value) ,
300+ None => return Ok ( HttpResponse :: BadRequest ( ) . body ( "Invalid tracker region" ) ) ,
301+ } ,
302+ None => None ,
303+ } ;
304+ if nickname. is_none ( ) && region. is_none ( ) {
305+ return Ok ( HttpResponse :: BadRequest ( ) . body ( "Tracker claim update is empty" ) ) ;
306+ }
291307
292308 let user_id = database:: ntehelper_tracker:: get_tracker_user_id ( & username, & pool) . await ?;
293- let claim = match database:: ntehelper_tracker:: update_tracker_claim_nickname (
309+ let claim = match database:: ntehelper_tracker:: update_tracker_claim (
294310 user_id,
295311 uid,
296312 nickname,
313+ region,
297314 & pool,
298315 )
299316 . await ?
@@ -554,6 +571,13 @@ fn validate_tracker_uid(value: &str) -> Option<i64> {
554571 trimmed. parse :: < i64 > ( ) . ok ( )
555572}
556573
574+ fn validate_tracker_region ( value : & str ) -> Option < & str > {
575+ match value. trim ( ) {
576+ "asia" | "europe" | "america" | "china" => Some ( value. trim ( ) ) ,
577+ _ => None ,
578+ }
579+ }
580+
557581fn validate_tracker_nickname ( value : & str ) -> Option < & str > {
558582 let trimmed = value. trim ( ) ;
559583 if trimmed. chars ( ) . count ( ) > TRACKER_NICKNAME_MAX_CHARS {
@@ -817,6 +841,7 @@ impl From<database::ntehelper_tracker::DbTrackerUidClaim> for TrackerUidClaimRes
817841 TrackerUidClaimResponse {
818842 uid : claim. uid . to_string ( ) ,
819843 nickname : claim. nickname ,
844+ region : claim. region ,
820845 owner_username : claim. owner_username ,
821846 claim_source : claim. claim_source ,
822847 has_profile : claim. has_profile ,
0 commit comments