@@ -121,7 +121,9 @@ impl MisskeyClient {
121121 mut params : Value ,
122122 ) -> Result < Value , NoteDeckError > {
123123 if let Some ( obj) = params. as_object_mut ( ) {
124- obj. insert ( "i" . to_string ( ) , json ! ( token) ) ;
124+ if !token. is_empty ( ) {
125+ obj. insert ( "i" . to_string ( ) , json ! ( token) ) ;
126+ }
125127 }
126128
127129 let res = self
@@ -1935,146 +1937,6 @@ impl MisskeyClient {
19351937 Ok ( meta)
19361938 }
19371939
1938- // --- Anonymous (token-free) API methods ---
1939-
1940- /// Send a request without authentication token.
1941- /// Used for public endpoints (users/show, notes/show, etc.)
1942- pub async fn request_anonymous (
1943- & self ,
1944- host : & str ,
1945- endpoint : & str ,
1946- params : Value ,
1947- ) -> Result < Value , NoteDeckError > {
1948- let res = self
1949- . client
1950- . post ( self . api_url ( host, endpoint) )
1951- . json ( & params)
1952- . send ( )
1953- . await ?;
1954-
1955- if !res. status ( ) . is_success ( ) {
1956- let status = res. status ( ) . as_u16 ( ) ;
1957- let detail = match res. json :: < Value > ( ) . await {
1958- Ok ( body) => body
1959- . pointer ( "/error/message" )
1960- . or_else ( || body. pointer ( "/error/code" ) )
1961- . and_then ( |v| v. as_str ( ) )
1962- . map ( String :: from) ,
1963- Err ( _) => None ,
1964- } ;
1965- let message = match detail {
1966- Some ( d) => format ! ( "{endpoint}: {d}" ) ,
1967- None => format ! ( "{endpoint} ({status})" ) ,
1968- } ;
1969- return Err ( NoteDeckError :: Api {
1970- endpoint : endpoint. to_string ( ) ,
1971- status,
1972- message,
1973- } ) ;
1974- }
1975-
1976- let text = Self :: read_body_limited ( res, endpoint) . await ?;
1977- if text. is_empty ( ) {
1978- Ok ( Value :: Null )
1979- } else {
1980- serde_json:: from_str ( & text) . map_err ( NoteDeckError :: from)
1981- }
1982- }
1983-
1984- pub async fn get_timeline_anonymous (
1985- & self ,
1986- host : & str ,
1987- account_id : & str ,
1988- timeline_type : TimelineType ,
1989- options : TimelineOptions ,
1990- ) -> Result < Vec < NormalizedNote > , NoteDeckError > {
1991- let endpoint = timeline_type. api_endpoint ( ) ;
1992- let mut params = json ! ( { "limit" : options. limit( ) } ) ;
1993- apply_pagination ( & mut params, options. since_id . as_deref ( ) , options. until_id . as_deref ( ) ) ;
1994- if let Some ( ref f) = options. filters {
1995- if let Some ( v) = f. with_renotes {
1996- params[ "withRenotes" ] = json ! ( v) ;
1997- }
1998- if let Some ( v) = f. with_replies {
1999- params[ "withReplies" ] = json ! ( v) ;
2000- }
2001- if let Some ( v) = f. with_files {
2002- params[ "withFiles" ] = json ! ( v) ;
2003- }
2004- if let Some ( v) = f. with_bots {
2005- params[ "withBots" ] = json ! ( v) ;
2006- params[ "excludeBots" ] = json ! ( !v) ;
2007- }
2008- if let Some ( v) = f. with_sensitive {
2009- params[ "withSensitive" ] = json ! ( v) ;
2010- params[ "excludeNsfw" ] = json ! ( !v) ;
2011- }
2012- }
2013- if let Some ( ref id) = options. list_id {
2014- params[ "listId" ] = json ! ( id) ;
2015- }
2016-
2017- let data = self . request_anonymous ( host, & endpoint, params) . await ?;
2018- let raw: Vec < RawNote > = serde_json:: from_value ( data) ?;
2019- Ok ( raw
2020- . into_iter ( )
2021- . map ( |n| n. normalize ( account_id, host) )
2022- . collect ( ) )
2023- }
2024-
2025- pub async fn get_user_anonymous (
2026- & self ,
2027- host : & str ,
2028- user_id : & str ,
2029- ) -> Result < NormalizedUser , NoteDeckError > {
2030- let data = self
2031- . request_anonymous ( host, "users/show" , json ! ( { "userId" : user_id } ) )
2032- . await ?;
2033- let raw: RawUser = serde_json:: from_value ( data) ?;
2034- Ok ( raw. into ( ) )
2035- }
2036-
2037- pub async fn get_user_detail_anonymous (
2038- & self ,
2039- host : & str ,
2040- user_id : & str ,
2041- ) -> Result < NormalizedUserDetail , NoteDeckError > {
2042- let data = self
2043- . request_anonymous ( host, "users/show" , json ! ( { "userId" : user_id } ) )
2044- . await ?;
2045- let raw: RawUserDetail = serde_json:: from_value ( data) ?;
2046- Ok ( raw. normalize ( ) )
2047- }
2048-
2049- pub async fn get_user_notes_anonymous (
2050- & self ,
2051- host : & str ,
2052- account_id : & str ,
2053- user_id : & str ,
2054- options : TimelineOptions ,
2055- ) -> Result < Vec < NormalizedNote > , NoteDeckError > {
2056- let mut params = json ! ( { "userId" : user_id, "limit" : options. limit( ) } ) ;
2057- apply_pagination ( & mut params, options. since_id . as_deref ( ) , options. until_id . as_deref ( ) ) ;
2058- let data = self . request_anonymous ( host, "users/notes" , params) . await ?;
2059- let raw: Vec < RawNote > = serde_json:: from_value ( data) ?;
2060- Ok ( raw
2061- . into_iter ( )
2062- . map ( |n| n. normalize ( account_id, host) )
2063- . collect ( ) )
2064- }
2065-
2066- pub async fn get_note_anonymous (
2067- & self ,
2068- host : & str ,
2069- account_id : & str ,
2070- note_id : & str ,
2071- ) -> Result < NormalizedNote , NoteDeckError > {
2072- let data = self
2073- . request_anonymous ( host, "notes/show" , json ! ( { "noteId" : note_id } ) )
2074- . await ?;
2075- let raw: RawNote = serde_json:: from_value ( data) ?;
2076- Ok ( raw. normalize ( account_id, host) )
2077- }
20781940}
20791941
20801942#[ cfg( test) ]
0 commit comments