mirror of https://github.com/MedzikUser/imgurs
update config
This commit is contained in:
parent
4fc60d8bbe
commit
605e051cdb
|
@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|||
- when the image uploaded, send a notification (can be turn off in config)
|
||||
|
||||
### Library
|
||||
- change openssl to rustls
|
||||
- change OpenSSL to RusTLS
|
||||
|
||||
## [0.1.0] - 2022-01-23
|
||||
### CLI
|
||||
|
|
|
@ -2,4 +2,4 @@
|
|||
id = '3e3ce0d7ac14d56'
|
||||
|
||||
[notification]
|
||||
enable = true
|
||||
enabled = true
|
||||
|
|
|
@ -3,6 +3,8 @@ use serde_derive::{Deserialize, Serialize};
|
|||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct ImageInfo {
|
||||
pub data: ImageInfoData,
|
||||
pub success: bool,
|
||||
pub status: i32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
|
|
|
@ -50,9 +50,9 @@ pub fn print_image_info(i: ImageInfo, notify: bool) {
|
|||
info!("Bandwidth {}", i.data.bandwidth);
|
||||
info!("Link {}", i.data.link);
|
||||
|
||||
let config = parse().unwrap();
|
||||
let config = parse();
|
||||
|
||||
if notify && config.notification.enable {
|
||||
if notify && config.notification.enabled {
|
||||
Notification::new()
|
||||
.summary("Imgurs")
|
||||
.body(&format!("Uploaded {}", i.data.link))
|
||||
|
|
|
@ -1 +1,19 @@
|
|||
use serde_derive::Deserialize;
|
||||
|
||||
pub mod toml;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct Config {
|
||||
pub imgur: ConfigImgur,
|
||||
pub notification: ConfigNotification,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct ConfigImgur {
|
||||
pub id: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct ConfigNotification {
|
||||
pub enabled: bool,
|
||||
}
|
||||
|
|
|
@ -1,26 +1,45 @@
|
|||
use dirs::config_dir;
|
||||
use serde_derive::Deserialize;
|
||||
use std::fs::read_to_string;
|
||||
use toml::from_str;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct Config {
|
||||
pub imgur: ConfigImgur,
|
||||
pub notification: ConfigNotification,
|
||||
use super::Config;
|
||||
use log::{error, warn};
|
||||
|
||||
use std::{
|
||||
fs::{create_dir_all, read_to_string, File},
|
||||
io::Write as _,
|
||||
path::Path,
|
||||
process::exit,
|
||||
};
|
||||
|
||||
pub fn parse() -> Config {
|
||||
toml().unwrap_or_else(|error| {
|
||||
warn!("Parse toml config: {}! Creating config file...", error);
|
||||
|
||||
let default_config = include_str!(concat!("../../config.toml"));
|
||||
|
||||
let sys_config_dir = config_dir().unwrap();
|
||||
let config_dir = format!("{}/imgurs/config.toml", sys_config_dir.to_string_lossy());
|
||||
let config_path = Path::new(&config_dir);
|
||||
|
||||
let prefix = config_path.parent().unwrap();
|
||||
create_dir_all(prefix).unwrap();
|
||||
|
||||
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().unwrap_or_else(|error| {
|
||||
error!("parse toml config: {}", error);
|
||||
exit(2);
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct ConfigImgur {
|
||||
pub id: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct ConfigNotification {
|
||||
pub enable: bool,
|
||||
}
|
||||
|
||||
pub fn parse() -> Result<Config, String> {
|
||||
fn toml() -> Result<Config, String> {
|
||||
let config_dir = config_dir().unwrap();
|
||||
|
||||
let file_dir: String = String::from(config_dir.to_string_lossy()) + "/imgurs/config.toml";
|
||||
|
||||
let toml_str = read_to_string(file_dir).map_err(|err| err.to_string())?;
|
||||
|
|
27
src/main.rs
27
src/main.rs
|
@ -3,13 +3,7 @@ mod config;
|
|||
|
||||
use cli::parse::parse;
|
||||
|
||||
use dirs::config_dir;
|
||||
use log::warn;
|
||||
use simple_logger::SimpleLogger;
|
||||
use std::{fs::create_dir_all, path::Path};
|
||||
|
||||
use std::fs::File;
|
||||
use std::io::Write as _;
|
||||
|
||||
use imgurs::api::ImgurHandle;
|
||||
|
||||
|
@ -17,26 +11,7 @@ use imgurs::api::ImgurHandle;
|
|||
async fn main() {
|
||||
SimpleLogger::new().init().unwrap();
|
||||
|
||||
let config = config::toml::parse().unwrap_or_else(|error| {
|
||||
warn!("Parse toml config: {}! Creating config file...", error);
|
||||
|
||||
let default_config = include_str!(concat!("../config.toml"));
|
||||
|
||||
let sys_config_dir = config_dir().unwrap();
|
||||
let config_dir = format!("{}/imgurs/config.toml", sys_config_dir.to_string_lossy());
|
||||
let config_path = Path::new(&config_dir);
|
||||
|
||||
let prefix = config_path.parent().unwrap();
|
||||
create_dir_all(prefix).unwrap();
|
||||
|
||||
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");
|
||||
|
||||
config::toml::parse().unwrap()
|
||||
});
|
||||
let config = config::toml::parse();
|
||||
|
||||
let client = ImgurHandle::new((&config.imgur.id).to_string());
|
||||
|
||||
|
|
Loading…
Reference in New Issue