2022-01-22 21:02:51 +00:00
|
|
|
pub mod credits;
|
|
|
|
pub mod delete_image;
|
2022-01-23 12:05:32 +00:00
|
|
|
pub mod info_image;
|
2022-01-22 22:10:11 +00:00
|
|
|
pub mod parse;
|
2022-01-22 21:14:26 +00:00
|
|
|
pub mod upload_image;
|
2022-01-23 12:05:32 +00:00
|
|
|
|
|
|
|
use chrono::prelude::DateTime;
|
|
|
|
use chrono::Utc;
|
2022-01-24 19:40:08 +00:00
|
|
|
use log::{error, info};
|
2022-01-23 12:05:32 +00:00
|
|
|
use std::time::{Duration, UNIX_EPOCH};
|
|
|
|
|
|
|
|
use imgurs::api::ImageInfo;
|
|
|
|
|
2022-01-24 19:39:33 +00:00
|
|
|
use notify_rust::Notification;
|
|
|
|
use std::process::exit;
|
|
|
|
|
2022-01-24 19:48:24 +00:00
|
|
|
use crate::config::toml::parse;
|
|
|
|
|
2022-01-24 19:39:33 +00:00
|
|
|
pub fn print_image_info(i: ImageInfo, notify: bool) {
|
2022-01-23 12:05:32 +00:00
|
|
|
let d = UNIX_EPOCH + Duration::from_secs(i.data.datetime.try_into().unwrap());
|
|
|
|
let datetime = DateTime::<Utc>::from(d);
|
|
|
|
let timestamp_str = datetime.format("%Y-%m-%d %H:%M:%S").to_string();
|
|
|
|
|
|
|
|
if i.data.title != None {
|
|
|
|
info!(
|
|
|
|
"Title {}",
|
2022-01-23 13:33:24 +00:00
|
|
|
i.data.title.unwrap_or_else(|| "unknown".to_string())
|
2022-01-23 12:05:32 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
if i.data.description != None {
|
|
|
|
info!(
|
|
|
|
"Description {}",
|
2022-01-23 13:33:24 +00:00
|
|
|
i.data.description.unwrap_or_else(|| "unknown".to_string())
|
2022-01-23 12:05:32 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
if i.data.deletehash != None {
|
|
|
|
info!(
|
|
|
|
"Deletehash {}",
|
2022-01-23 13:33:24 +00:00
|
|
|
i.data.deletehash.unwrap_or_else(|| "unknown".to_string())
|
2022-01-23 12:05:32 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
info!("ID {}", i.data.id);
|
|
|
|
info!("Upload Date {} (UTC)", timestamp_str);
|
|
|
|
info!("Type {}", i.data.img_type);
|
|
|
|
info!("Width {}", i.data.width);
|
|
|
|
info!("Height {}", i.data.height);
|
|
|
|
info!("File Size {} KB", i.data.size / 1000);
|
|
|
|
info!("Views {}", i.data.views);
|
|
|
|
info!("Bandwidth {}", i.data.bandwidth);
|
|
|
|
info!("Link {}", i.data.link);
|
2022-01-24 19:39:33 +00:00
|
|
|
|
2022-01-24 22:15:55 +00:00
|
|
|
let config = parse();
|
2022-01-24 19:48:24 +00:00
|
|
|
|
2022-01-24 22:15:55 +00:00
|
|
|
if notify && config.notification.enabled {
|
2022-01-24 19:39:33 +00:00
|
|
|
Notification::new()
|
|
|
|
.summary("Imgurs")
|
|
|
|
.body(&format!("Uploaded {}", i.data.link))
|
2022-01-24 19:40:08 +00:00
|
|
|
.show()
|
|
|
|
.unwrap_or_else(|e| {
|
2022-01-24 19:39:33 +00:00
|
|
|
error!("send notification: {}", e);
|
|
|
|
|
|
|
|
exit(2)
|
|
|
|
});
|
|
|
|
}
|
2022-01-23 12:05:32 +00:00
|
|
|
}
|