use crate::{image, notification, text, ServiceKind};
use imgur;
use open;
use std::fs::File;
use std::io::Read;
pub fn send() {
let tmp = image::temp_dir();
let mut file = match File::open(tmp.clone()) {
Ok(ok) => ok,
Err(_) => {
eprintln!("{}", text::message(28));
notification::error(28);
text::exit()
}
};
let mut image = Vec::new();
if file.read_to_end(&mut image).is_err() {
eprintln!("{}", text::message(28));
notification::error(28);
text::exit();
};
let mut copy_link = String::new();
let handle = imgur::Handle::new(String::from("37562f83e04fd66"));
match handle.upload(&image) {
Ok(info) => match info.link() {
Some(link) => copy_link.push_str(link),
None => {
eprintln!("{}", text::message(20));
notification::error(20);
text::exit()
}
},
Err(_) => {
eprintln!("{}", text::message(17));
notification::error(17);
text::exit()
}
}
notification::image_sent(ServiceKind::Imgur, ©_link, tmp.to_str().unwrap());
if open::that(copy_link).is_err() {
eprintln!("{}", text::message(19));
notification::error(19);
text::exit();
};
}