@@ -156,50 +156,47 @@ async function lookupFedifyAccount(): Promise<string> {
156156 const handle = `testuser@${ HARNESS_HOST } ` ;
157157
158158 const searchResult = await poll ( "Fedify user resolvable" , async ( ) => {
159+ const authHeaders = { Authorization : `Bearer ${ SERVER_TOKEN } ` } ;
160+
159161 // Try /api/v1/accounts/search (Mastodon standard).
160- // Fall back to /api/v1/accounts/lookup (exact match, supported by Sharkey)
161- // if search returns 404.
162- try {
163- const results = await serverGet (
164- `/api/v1/accounts/search?q= ${
165- encodeURIComponent ( `@ ${ handle } ` )
166- } &resolve=true&limit=5` ,
167- ) as RemoteAccount [ ] ;
162+ const searchRes = await fetch (
163+ ` ${ SERVER_URL } /api/v1/accounts/ search?q= ${
164+ encodeURIComponent ( `@ ${ handle } ` )
165+ } &resolve=true&limit=5` ,
166+ { headers : authHeaders } ,
167+ ) ;
168+ if ( searchRes . ok ) {
169+ const results = await searchRes . json ( ) as RemoteAccount [ ] ;
168170 const match = results ?. find ( ( a ) =>
169171 a . acct === handle || a . acct === `@${ handle } `
170172 ) ;
171173 if ( match ) return match ;
172- } catch {
173- // Search endpoint may return 404 on some servers (e.g. Sharkey);
174- // fall through to the lookup endpoint.
175174 }
176175
177- try {
178- const account = await serverGet (
179- `/api/v1/accounts/lookup?acct=${ encodeURIComponent ( handle ) } ` ,
180- ) as RemoteAccount ;
176+ // Fall back to /api/v1/accounts/lookup (exact match, supported by
177+ // Sharkey) if search didn't return a match.
178+ const lookupRes = await fetch (
179+ `${ SERVER_URL } /api/v1/accounts/lookup?acct=${ encodeURIComponent ( handle ) } ` ,
180+ { headers : authHeaders } ,
181+ ) ;
182+ if ( lookupRes . ok ) {
183+ const account = await lookupRes . json ( ) as RemoteAccount ;
181184 if ( account ?. id ) return account ;
182- } catch {
183- // lookup also failed
184185 }
185186
186187 // Misskey-native fallback: POST /api/users/show with username + host.
187188 // Sharkey's Mastodon-compat search/lookup endpoints have bugs with
188189 // remote users, but the native API works reliably. The returned id
189190 // is the same internal ID used by the Mastodon-compat layer.
190- try {
191- const [ user , host ] = handle . split ( "@" ) ;
192- const res = await fetch ( `${ SERVER_URL } /api/users/show` , {
193- method : "POST" ,
194- headers : { "Content-Type" : "application/json" } ,
195- body : JSON . stringify ( { username : user , host } ) ,
196- } ) ;
197- if ( res . ok ) {
198- const data = await res . json ( ) as { id ?: string } ;
199- if ( data ?. id ) return { id : data . id , acct : handle } ;
200- }
201- } catch {
202- // Not a Misskey-family server
191+ const [ user , host ] = handle . split ( "@" ) ;
192+ const misskeyRes = await fetch ( `${ SERVER_URL } /api/users/show` , {
193+ method : "POST" ,
194+ headers : { "Content-Type" : "application/json" } ,
195+ body : JSON . stringify ( { username : user , host } ) ,
196+ } ) ;
197+ if ( misskeyRes . ok ) {
198+ const data = await misskeyRes . json ( ) as { id ?: string } ;
199+ if ( data ?. id ) return { id : data . id , acct : handle } ;
203200 }
204201
205202 return null ;
0 commit comments