@ -3,7 +3,7 @@ use std::collections::HashMap;
use std ::error ::Error ;
#[ macro_use ]
extern crate rocket ;
use reqwest ::StatusCode ;
use reqwest ::{ Client , StatusCode } ;
use rocket ::response ::content ::RawHtml ;
use rocket ::serde ::json ::Json ;
@ -30,6 +30,15 @@ fn default_base_url() -> String {
"/" . into ( )
}
fn user_agent ( ) -> String {
format ! (
"{}/{} (RSS feed converter) on {}" ,
env ! ( "CARGO_PKG_NAME" ) ,
env ! ( "CARGO_PKG_VERSION" ) ,
& ARGS . domain
)
}
static ARGS : once_cell ::sync ::Lazy < Args > = once_cell ::sync ::Lazy ::new ( | | Args ::parse ( ) ) ;
#[ get( " / " ) ]
@ -61,8 +70,17 @@ async fn syndication_rss_route(
let project_url = format ! ( "{}{}" , COHOST_ACCOUNT_API_URL , project ) ;
let posts_url = cohost_posts_api_url ( project , page ) ;
let client = match Client ::builder ( ) . user_agent ( user_agent ( ) ) . build ( ) {
Ok ( v ) = > v ,
Err ( e ) = > {
let err = format ! ( "Couldn't build a reqwest client: {:?}" , e ) ;
eprintln ! ( "{}" , err ) ;
return Err ( ErrorResponse ::InternalError ( err ) ) ;
}
} ;
eprintln ! ( "making request to {}" , project_url ) ;
let project_data : CohostAccount = match reqwest ::get ( project_url ) . await {
let project_data : CohostAccount = match client . get ( project_url ) . send ( ) . await {
Ok ( v ) = > match v . status ( ) {
StatusCode ::OK = > match v . json ::< CohostAccount > ( ) . await {
Ok ( a ) = > a ,
@ -93,7 +111,7 @@ async fn syndication_rss_route(
} ;
eprintln ! ( "making request to {}" , posts_url ) ;
match reqwest ::get ( posts_url ) . await {
match client . get ( posts_url ) . send ( ) . await {
Ok ( v ) = > match v . status ( ) {
StatusCode ::OK = > match v . json ::< CohostPostsPage > ( ) . await {
Ok ( page_data ) = > {
@ -143,10 +161,18 @@ async fn webfinger_route(params: HashMap<String, String>) -> Option<Json<CohostW
) ;
return None ;
}
let client = match Client ::builder ( ) . user_agent ( user_agent ( ) ) . build ( ) {
Ok ( v ) = > v ,
Err ( e ) = > {
let err = format ! ( "Couldn't build a reqwest client: {:?}" , e ) ;
eprintln ! ( "{}" , err ) ;
return None ;
}
} ;
if let Some ( param ) = params . iter ( ) . next ( ) {
let url = format ! ( "{}{}" , COHOST_ACCOUNT_API_URL , param . 0 ) ;
eprintln ! ( "making request to {}" , url ) ;
match reqwest ::get ( url ) . await {
match client . get ( url ) . send ( ) . await {
Ok ( v ) = > {
match v . status ( ) {
StatusCode ::OK = > match v . json ::< CohostAccount > ( ) . await {