fixed the title generation
This commit is contained in:
parent
241eec2b09
commit
e54d16c7a4
2 changed files with 19 additions and 11 deletions
16
src/main.rs
16
src/main.rs
|
@ -28,6 +28,9 @@ struct Cli {
|
|||
/// Sets a custom config file
|
||||
#[arg(short, long, value_name = "FILE")]
|
||||
config: Option<String>,
|
||||
|
||||
#[arg(short, long, value_name = "private")]
|
||||
visibility: Option<String>,
|
||||
}
|
||||
|
||||
|
||||
|
@ -109,14 +112,19 @@ fn get_jpeg_files(directory: &str) -> Vec<String> {
|
|||
match args.config {
|
||||
Some(configstring) => { my_config = configstring},
|
||||
None => {my_config = "config.json".to_string()},
|
||||
|
||||
}
|
||||
println!("effictive config file: {}", my_config);
|
||||
println!("effective config file: {}", my_config);
|
||||
|
||||
|
||||
let config = load_config(my_config).unwrap();
|
||||
let mut config = load_config(my_config).unwrap();
|
||||
println!("Config OK? true");
|
||||
|
||||
|
||||
// Overwrite config values with command line arguments
|
||||
match args.visibility {
|
||||
Some(visibility) => { config.pixelfed_visibility = visibility},
|
||||
None => {}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -132,7 +140,7 @@ fn get_jpeg_files(directory: &str) -> Vec<String> {
|
|||
// now iterate over all images in batches of batch_size
|
||||
for (i, chunk) in images.chunks(config.pixelfed_batch_size).enumerate() {
|
||||
println!("{}", i.clone());
|
||||
pixelfed::bulk_upload_images(&config, chunk, i + 1, total_batches, &title, &args.mode);
|
||||
let _ =pixelfed::bulk_upload_images(&config, chunk, i + 1, total_batches, &title, &args.mode);
|
||||
}
|
||||
println!("All images uploaded successfully.");
|
||||
Ok(())
|
||||
|
|
|
@ -25,7 +25,7 @@ pub fn bulk_upload_images(config: &super::Config, images: &[String], batch_num:
|
|||
pixelfed_access_token: config.pixelfed_access_token.clone(),
|
||||
pixelfed_visibility: config.pixelfed_visibility.clone(),
|
||||
pixelfed_default_text: config.pixelfed_default_text.clone(),
|
||||
pixelfed_batch_size: config.pixelfed_batch_size,
|
||||
pixelfed_batch_size: config.pixelfed_batch_size.clone(),
|
||||
};
|
||||
let url = format!("{}/api/v1/media", config.pixelfed_url.clone());
|
||||
|
||||
|
@ -70,7 +70,7 @@ pub fn bulk_upload_images(config: &super::Config, images: &[String], batch_num:
|
|||
.file("file", image_path)?;
|
||||
// upload the form to Pixelfed
|
||||
let res = client.post(&url)
|
||||
.bearer_auth(&config.pixelfed_access_token)
|
||||
.bearer_auth(&pxl_config.pixelfed_access_token)
|
||||
.multipart(form)
|
||||
.send();
|
||||
|
||||
|
@ -80,20 +80,20 @@ pub fn bulk_upload_images(config: &super::Config, images: &[String], batch_num:
|
|||
}
|
||||
|
||||
if !media_ids.is_empty() {
|
||||
let post_url = format!("{}/api/v1/statuses", config.pixelfed_url);
|
||||
let post_text = format_post_text(&config.pixelfed_default_text, batch_num, total_batches, title);
|
||||
let post_url = format!("{}/api/v1/statuses", pxl_config.pixelfed_url);
|
||||
let post_text = format_post_text(&pxl_config.pixelfed_default_text, batch_num, total_batches, title);
|
||||
let body = serde_json::json!({
|
||||
"status": post_text,
|
||||
"media_ids": media_ids,
|
||||
"alt_texts": media_descriptions,
|
||||
"visibility": config.pixelfed_visibility,
|
||||
"visibility": pxl_config.pixelfed_visibility,
|
||||
});
|
||||
println!("Body: \n{}", body.to_string());
|
||||
println!("MediaIDs: {}", media_ids.len());
|
||||
println!("Alt_texts: {}", media_descriptions.len());
|
||||
println!("Posting batch {} out of {} with media {}", batch_num, total_batches, media_ids.len());
|
||||
client.post(&post_url)
|
||||
.bearer_auth(&config.pixelfed_access_token)
|
||||
let res = client.post(&post_url)
|
||||
.bearer_auth(&pxl_config.pixelfed_access_token)
|
||||
.json(&body)
|
||||
.send();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue