@@ -3,8 +3,10 @@ use crate::account_manager::AccountManager;
33use crate :: apis:: com:: atproto:: server:: get_keys_from_private_key_str;
44use crate :: auth_verifier:: AccessStandardCheckTakedown ;
55use crate :: common:: env:: env_str;
6+ use crate :: config:: ServerConfig ;
7+ use crate :: handle:: { normalize_and_validate_handle, HandleValidationContext , HandleValidationOpts } ;
68use crate :: models:: { ErrorCode , ErrorMessageResponse } ;
7- use crate :: { plc, SharedSequencer } ;
9+ use crate :: { plc, SharedIdResolver , SharedSequencer } ;
810use anyhow:: { bail, Result } ;
911use rocket:: http:: Status ;
1012use rocket:: response:: status;
@@ -16,12 +18,28 @@ use std::env;
1618async fn inner_update_handle (
1719 body : Json < UpdateHandleInput > ,
1820 sequencer : & State < SharedSequencer > ,
21+ server_config : & State < ServerConfig > ,
22+ id_resolver : & State < SharedIdResolver > ,
1923 auth : AccessStandardCheckTakedown ,
2024) -> Result < ( ) > {
2125 let UpdateHandleInput { handle } = body. into_inner ( ) ;
2226 let requester = auth. access . credentials . unwrap ( ) . did . unwrap ( ) ;
2327
24- // @TODO: Implement normalizeAndValidateHandle()
28+ // Use the new normalize and validate function
29+ let validation_ctx = HandleValidationContext {
30+ server_config,
31+ id_resolver,
32+ } ;
33+ let handle = normalize_and_validate_handle (
34+ HandleValidationOpts {
35+ handle,
36+ did : Some ( requester. clone ( ) ) ,
37+ allow_reserved : None ,
38+ } ,
39+ validation_ctx,
40+ )
41+ . await ?;
42+
2543 let account = AccountManager :: get_account (
2644 & handle,
2745 Some ( AvailabilityFlags {
@@ -51,24 +69,14 @@ async fn inner_update_handle(
5169 . await
5270 {
5371 Ok ( _) => ( ) ,
54- Err ( error) => eprintln ! (
55- "Error: {}; DID: {}; Handle: {}" ,
56- error. to_string( ) ,
57- & requester,
58- & handle
59- ) ,
72+ Err ( error) => eprintln ! ( "Error: {}; DID: {}; Handle: {}" , error, & requester, & handle) ,
6073 } ;
6174 match lock
6275 . sequence_handle_update ( requester. clone ( ) , handle. clone ( ) )
6376 . await
6477 {
6578 Ok ( _) => ( ) ,
66- Err ( error) => eprintln ! (
67- "Error: {}; DID: {}; Handle: {}" ,
68- error. to_string( ) ,
69- & requester,
70- & handle
71- ) ,
79+ Err ( error) => eprintln ! ( "Error: {}; DID: {}; Handle: {}" , error, & requester, & handle) ,
7280 } ;
7381 Ok ( ( ) )
7482}
@@ -81,20 +89,22 @@ async fn inner_update_handle(
8189pub async fn update_handle (
8290 body : Json < UpdateHandleInput > ,
8391 sequencer : & State < SharedSequencer > ,
92+ server_config : & State < ServerConfig > ,
93+ id_resolver : & State < SharedIdResolver > ,
8494 auth : AccessStandardCheckTakedown ,
8595) -> Result < ( ) , status:: Custom < Json < ErrorMessageResponse > > > {
86- match inner_update_handle ( body, sequencer, auth) . await {
96+ match inner_update_handle ( body, sequencer, server_config , id_resolver , auth) . await {
8797 Ok ( _) => Ok ( ( ) ) ,
8898 Err ( error) => {
8999 eprintln ! ( "@LOG: ERROR: {error}" ) ;
90100 let internal_error = ErrorMessageResponse {
91101 code : Some ( ErrorCode :: InternalServerError ) ,
92102 message : Some ( error. to_string ( ) ) ,
93103 } ;
94- return Err ( status:: Custom (
104+ Err ( status:: Custom (
95105 Status :: InternalServerError ,
96106 Json ( internal_error) ,
97- ) ) ;
107+ ) )
98108 }
99109 }
100110}
0 commit comments