From e479c96e44b21961009482523d44921ec7489d4b Mon Sep 17 00:00:00 2001 From: Anson Date: Fri, 22 Aug 2025 10:49:38 -0600 Subject: [PATCH] fix: prevent duplicate posts by using Ghost API instead of public URL check - Remove unreliable check_if_post_exists function that checked public URLs - Replace with get_existing_post_id which properly queries Ghost's Admin API - This prevents duplicate posts when public URLs are temporarily unavailable --- ghost-upload/src/main.rs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/ghost-upload/src/main.rs b/ghost-upload/src/main.rs index 399fdec..2a455ec 100644 --- a/ghost-upload/src/main.rs +++ b/ghost-upload/src/main.rs @@ -191,16 +191,7 @@ async fn extract_article_content(original_link: &str) -> String { } } -async fn check_if_post_exists(entry: &Entry) -> bool { - let posts_url = "https://notes.ansonbiggs.com/"; - let link = entry.links.first().unwrap().href.as_str(); - let slug = get_slug(link); - match reqwest::get(format!("{}{}", posts_url, slug)).await { - Ok(response) => response.status().is_success(), - Err(_) => false, - } -} #[derive(Deserialize, Debug)] struct GhostPostsResponse { @@ -354,7 +345,12 @@ async fn main() { } else { let post_exists_futures = entries.into_iter().map(|entry| { let entry_clone = entry.clone(); - async move { (entry_clone, check_if_post_exists(&entry).await) } + let token_clone = token.clone(); + async move { + let link = entry.links.first().unwrap().href.as_str(); + let slug = get_slug(link); + (entry_clone, get_existing_post_id(&slug, &token_clone).await.is_some()) + } }); let post_exists_results = join_all(post_exists_futures).await;