read commit description

- webhook: added url in title
- cli: change image domain to your own (set in config)
- if the configuration file cannot be open, ask the user whether to overwrite the file instead of overwriting it without asking
- logger: max_level_debug in debug binary
This commit is contained in:
MedzikUser 2022-03-10 22:02:03 +01:00
parent 9b813457e7
commit 60b0dc0d84
No known key found for this signature in database
GPG Key ID: A5FAC1E185C112DB
7 changed files with 48 additions and 23 deletions

View File

@ -8,6 +8,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
<!-- next-header -->
## [Unreleased]
### CLI
- webhook: added url in title
- cli: change image domain to your own (set in config)
- if the configuration file cannot be open, ask the user whether to overwrite the file instead of overwriting it without asking
- logger: set `max_level_debug` in debug binary
## [0.5.1] - 2022-03-08
### Cli

View File

@ -44,7 +44,7 @@ features = ["derive", "cargo", "std"]
[dependencies.log]
version = "0.4.14"
features = ["release_max_level_info"]
features = ["release_max_level_info", "max_level_debug"]
[dependencies.simple_logger]
version = "2.1.0"

View File

@ -1,5 +1,6 @@
[imgur]
id = '3e3ce0d7ac14d56'
image_cdn = 'i.imgur.com'
[notification]
enabled = true

View File

@ -20,6 +20,8 @@ macro_rules! notify (
pub async fn upload_image(client: ImgurClient, path: &str) {
let mut image: String = path.to_string();
let config = toml::parse();
if Path::new(path).exists() {
let bytes = fs_read(path)
.map_err(|err| err.to_string())
@ -29,7 +31,7 @@ pub async fn upload_image(client: ImgurClient, path: &str) {
panic!("{path} is not a url")
}
let i = upload_img(client, &image).await.unwrap_or_else(|err| {
let mut i = upload_img(client, &image).await.unwrap_or_else(|err| {
notify!(Notification::new()
.summary("Error!")
.body(&format!("Error: {}", &err.to_string()))
@ -37,14 +39,17 @@ pub async fn upload_image(client: ImgurClient, path: &str) {
panic!("{}", err)
});
if config.imgur.image_cdn != "i.imgur.com" {
i.data.link = i.data.link.replace("i.imgur.com", "cdn.magicuser.cf")
}
print_image_info(i.clone());
let body = format!("Uploaded {}", i.data.link);
notify!(Notification::new().summary("Imgurs").body(&body));
let config = toml::parse();
if config.clipboard.enabled {
set_clipboard(i.data.link.clone())
}

View File

@ -10,11 +10,11 @@ pub async fn send_discord_webhook(
let url = toml::parse().discord_webhook.uri;
let client: WebhookClient = WebhookClient::new(&url);
let webhook = client
client
.send(|message| {
message.username("Imgurs").embed(|embed| {
embed
.title("Imgurs")
.title(&link)
.description(&format!("Delete Hash ||{deletehash}||"))
.image(&link)
.footer(
@ -26,7 +26,5 @@ pub async fn send_discord_webhook(
)
})
})
.await;
webhook
.await
}

View File

@ -13,6 +13,7 @@ pub struct Config {
#[derive(Debug, Deserialize)]
pub struct ConfigImgur {
pub id: String,
pub image_cdn: String,
}
#[derive(Debug, Deserialize)]

View File

@ -1,11 +1,12 @@
use super::Config;
use anyhow::Error;
use colored::Colorize;
use dirs::config_dir;
use log::warn;
use std::{
fs::{create_dir_all, read_to_string, File},
io::Write as _,
io::{Write as _, self},
path::Path,
};
use toml::from_str as toml_from_str;
@ -13,25 +14,39 @@ use toml::from_str as toml_from_str;
const CONFIG_DIR: &str = "/imgurs/config.toml";
pub fn parse() -> Config {
toml().unwrap_or_else(|e| {
warn!("Parse toml config: {e}! Creating config file...");
toml().unwrap_or_else(|err| {
let mut stdout = std::io::stdout();
let default_config = include_str!(concat!("../../config.toml"));
write!(stdout, "{}", "The configuration file could not be opened. Do you want to create/overwrite with DEFAULT values? (Y/n): ".yellow()).unwrap();
stdout.flush().unwrap();
let sys_config_dir = config_dir().expect("find config dir");
let config_dir = format!("{}{CONFIG_DIR}", sys_config_dir.to_string_lossy());
let config_path = Path::new(&config_dir);
let mut value = String::new();
io::stdin()
.read_line(&mut value)
.expect("failed to read line");
let prefix = config_path.parent().unwrap();
create_dir_all(prefix).expect("create config dir");
if value.to_lowercase() != "n\n" {
warn!("Parse toml config: {err}! Creating config file...");
let mut file_ref = File::create(config_path).expect("create failed");
let default_config = include_str!(concat!("../../config.toml"));
file_ref
.write_all(default_config.as_bytes())
.expect("failed write default config to file");
let sys_config_dir = config_dir().expect("find config dir");
let config_dir = format!("{}{CONFIG_DIR}", sys_config_dir.to_string_lossy());
let config_path = Path::new(&config_dir);
toml().expect("parse toml config")
let prefix = config_path.parent().unwrap();
create_dir_all(prefix).expect("create config dir");
let mut file_ref = File::create(config_path).expect("create failed");
file_ref
.write_all(default_config.as_bytes())
.expect("failed write default config to file");
toml().expect("parse toml config")
} else {
panic!("New config creation cancelled!")
}
})
}