Compare commits

...

2 Commits

Author SHA1 Message Date
Leonora Tindall c8f236b6c0
This is 0.5.1 2022-11-03 23:34:10 -05:00
Leonora Tindall 81890b7d7d
Add better logging 2022-11-03 23:30:59 -05:00
3 changed files with 36 additions and 25 deletions

30
Cargo.lock generated
View File

@ -437,9 +437,9 @@ checksum = "3a4f925191b4367301851c6d99b09890311d74b0d43f274c0b34c86d308a3663"
[[package]]
name = "cc"
version = "1.0.73"
version = "1.0.74"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11"
checksum = "581f5dba903aac52ea3feb5ec4810848460ee833876f1f9b0fdeab1f19091574"
[[package]]
name = "cfg-if"
@ -565,7 +565,7 @@ checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc"
[[package]]
name = "corobel"
version = "0.5.0"
version = "0.5.1"
dependencies = [
"atom_syndication",
"cached",
@ -1278,9 +1278,9 @@ checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421"
[[package]]
name = "hyper"
version = "0.14.20"
version = "0.14.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02c929dc5c39e335a03c405292728118860721b10190d98c2a0f0efd5baafbac"
checksum = "abfba89e19b959ca163c7752ba59d737c1ceea53a5d31a149c805446fc958064"
dependencies = [
"bytes",
"futures-channel",
@ -1571,9 +1571,9 @@ dependencies = [
[[package]]
name = "native-tls"
version = "0.2.10"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd7e2f3618557f980e0b17e8856252eee3c97fa12c54dff0ca290fb6266ca4a9"
checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e"
dependencies = [
"lazy_static",
"libc",
@ -1624,9 +1624,9 @@ dependencies = [
[[package]]
name = "num_cpus"
version = "1.13.1"
version = "1.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1"
checksum = "f6058e64324c71e02bc2b150e4f3bc8286db6c83092132ffa3f6b1eab0f9def5"
dependencies = [
"hermit-abi",
"libc",
@ -1942,18 +1942,18 @@ dependencies = [
[[package]]
name = "ref-cast"
version = "1.0.12"
version = "1.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12a733f1746c929b4913fe48f8697fcf9c55e3304ba251a79ffb41adfeaf49c2"
checksum = "53b15debb4f9d60d767cd8ca9ef7abb2452922f3214671ff052defc7f3502c44"
dependencies = [
"ref-cast-impl",
]
[[package]]
name = "ref-cast-impl"
version = "1.0.12"
version = "1.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5887de4a01acafd221861463be6113e6e87275e79804e56779f4cdc131c60368"
checksum = "abfa8511e9e94fd3de6585a3d3cd00e01ed556dc9814829280af0e8dc72a8f36"
dependencies = [
"proc-macro2",
"quote",
@ -2173,9 +2173,9 @@ dependencies = [
[[package]]
name = "scoped-tls"
version = "1.0.0"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2"
checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294"
[[package]]
name = "scopeguard"

View File

@ -1,6 +1,6 @@
[package]
name = "corobel"
version = "0.5.0"
version = "0.5.1"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -124,7 +124,7 @@ async fn get_full_post_data(project_id: String) -> Result<CohostPostsPage, Error
// Not cached because it's never used individually.
async fn get_page_data(project_id: String, page: u64) -> Result<CohostPostsPage, ErrorResponse> {
let posts_url = cohost_posts_api_url(&project_id, page);
eprintln!("making request to {}", posts_url);
eprintln!("[INT] making request to {}", posts_url);
match CLIENT.get(posts_url).send().await {
Ok(v) => match v.status() {
StatusCode::OK => match v.json::<CohostPostsPage>().await {
@ -134,14 +134,14 @@ async fn get_page_data(project_id: String, page: u64) -> Result<CohostPostsPage,
"Couldn't deserialize Cohost posts page for '{}': {:?}",
project_id, e
);
eprintln!("{}", err);
eprintln!("[ERR] {}", err);
return Err(ErrorResponse::InternalError(err));
}
},
// TODO NORA: Handle possible redirects
s => {
let err = format!("Didn't receive status code 200 for posts for Cohost project '{}'; got {:?} instead.", page, s);
eprintln!("{}", err);
eprintln!("[ERR] {}", err);
return Err(ErrorResponse::NotFound(err));
}
},
@ -150,7 +150,7 @@ async fn get_page_data(project_id: String, page: u64) -> Result<CohostPostsPage,
"Error making request to Cohost for posts for project '{}': {:?}",
project_id, e
);
eprintln!("{}", err);
eprintln!("[ERR] {}", err);
return Err(ErrorResponse::InternalError(err));
}
}
@ -159,7 +159,7 @@ async fn get_page_data(project_id: String, page: u64) -> Result<CohostPostsPage,
#[cached(time = 60, result)]
async fn get_project_data(project_id: String) -> Result<CohostAccount, ErrorResponse> {
let project_url = format!("{}{}", COHOST_ACCOUNT_API_URL, project_id);
eprintln!("making request to {}", project_url);
eprintln!("[INT] making request to {}", project_url);
match CLIENT.get(project_url).send().await {
Ok(v) => match v.status() {
StatusCode::OK => match v.json::<CohostAccount>().await {
@ -169,7 +169,7 @@ async fn get_project_data(project_id: String) -> Result<CohostAccount, ErrorResp
"Couldn't deserialize Cohost project '{}': {:?}",
project_id, e
);
eprintln!("{}", err);
eprintln!("[ERR] {}", err);
Err(ErrorResponse::InternalError(err))
}
},
@ -179,7 +179,7 @@ async fn get_project_data(project_id: String) -> Result<CohostAccount, ErrorResp
"Didn't receive status code 200 for Cohost project '{}'; got {:?} instead.",
project_id, s
);
eprintln!("{}", err);
eprintln!("[ERR] {}", err);
Err(ErrorResponse::NotFound(err))
}
},
@ -188,7 +188,7 @@ async fn get_project_data(project_id: String) -> Result<CohostAccount, ErrorResp
"Error making request to Cohost for project '{}': {:?}",
project_id, e
);
eprintln!("{}", err);
eprintln!("[ERR] {}", err);
Err(ErrorResponse::InternalError(err))
}
}
@ -196,6 +196,7 @@ async fn get_project_data(project_id: String) -> Result<CohostAccount, ErrorResp
#[get("/<project>/originals.rss")]
async fn syndication_originals_rss_route(project: String) -> Result<RssResponse, ErrorResponse> {
eprintln!("[EXT] Request to /{}/originals.rss", project);
let project_data = get_project_data(project.clone()).await?;
let page_data = get_full_post_data(project.clone()).await?;
Ok(RssResponse {
@ -206,6 +207,7 @@ async fn syndication_originals_rss_route(project: String) -> Result<RssResponse,
#[get("/<project>/feed.rss")]
async fn syndication_rss_route(project: String) -> Result<RssResponse, ErrorResponse> {
eprintln!("[EXT] Request to /{}/feed.rss", project);
let project_data = get_project_data(project.clone()).await?;
let page_data = get_full_post_data(project.clone()).await?;
Ok(RssResponse {
@ -216,6 +218,7 @@ async fn syndication_rss_route(project: String) -> Result<RssResponse, ErrorResp
#[get("/<project>/<id>")]
async fn post_md_route(project: String, id: u64) -> Result<MdResponse, ErrorResponse> {
eprintln!("[EXT] Request to /{}/{}", project, id);
let _project_data = get_project_data(project.clone()).await?;
let post_data = get_post_from_page(project.clone(), id).await?;
Ok(MdResponse {
@ -227,12 +230,20 @@ async fn post_md_route(project: String, id: u64) -> Result<MdResponse, ErrorResp
async fn webfinger_route(
params: HashMap<String, String>,
) -> Result<Json<CohostWebfingerResource>, ErrorResponse> {
let mut url_params_string = String::new();
for (k, v) in params.iter() {
url_params_string.push_str(&format!("{}={}&", k, v));
}
eprintln!(
"[EXT] Request to /.well_known/webfinger?{}",
url_params_string
);
if params.len() != 1 {
let err = format!(
"Too may or too few parameters. Expected 1, got {}",
params.len()
);
eprintln!("{}", err);
eprintln!("[ERR] {}", err);
return Err(ErrorResponse::InternalError(err));
}
if let Some(param) = params.iter().next() {