added ability to replace batch in description
This commit is contained in:
parent
8a6883a0ab
commit
43f921fcd4
1 changed files with 7 additions and 2 deletions
|
@ -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<String> {
|
|||
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<dyn Error>> {
|
||||
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,
|
||||
|
|
Loading…
Reference in a new issue