mirror of
https://gitlab.com/Anson-Projects/projects.git
synced 2025-09-14 09:35:04 +00:00
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
This commit is contained in:
@@ -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;
|
||||
|
Reference in New Issue
Block a user