diff --git a/src/main.rs b/src/main.rs index 8d03240..48ec0f8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ use std::fs; -use serde::Deserialize; +use std::path::Path; +use serde::{Deserialize, Serialize}; use reqwest::blocking::Client; use std::error::Error; @@ -32,6 +33,10 @@ fn get_jpeg_files(directory: &str) -> Vec { images } +fn format_post_text(template: &str, batch_num: usize, total_batches: usize) -> String { + template.replace("@batch@", &format!("Batch {} out of {}", batch_num, total_batches)) +} + fn upload_images_batch(client: &Client, config: &Config, images: &[String], batch_num: usize, total_batches: usize) -> Result<(), Box> { let url = format!("{}/api/v1/media", config.pixelfed_url); let mut media_ids = Vec::new(); @@ -53,7 +58,7 @@ fn upload_images_batch(client: &Client, config: &Config, images: &[String], batc if !media_ids.is_empty() { let post_url = format!("{}/api/v1/statuses", config.pixelfed_url); - let post_text = format!("{} (Batch {} out of {})", config.default_text, batch_num, total_batches); + let post_text = format_post_text(&config.default_text, batch_num, total_batches); let body = serde_json::json!({ "status": post_text, "media_ids": media_ids,