This repository has been archived by the owner on Feb 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
imgur.rs
executable file
·58 lines (51 loc) · 1.51 KB
/
imgur.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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();
// Opens file for use
let mut file = match File::open(tmp.clone()) {
Ok(ok) => ok,
Err(_) => {
eprintln!("{}", text::message(28));
notification::error(28);
text::exit()
}
};
// Stores image in a Vector
let mut image = Vec::new();
if file.read_to_end(&mut image).is_err() {
eprintln!("{}", text::message(28));
notification::error(28);
text::exit();
};
// Creates Imgur Applications for sending to Imgur API
let mut copy_link = String::new();
let handle = imgur::Handle::new(String::from("37562f83e04fd66"));
// Uploads file to Imgur API
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()
}
}
// Send notification
notification::image_sent(ServiceKind::Imgur, ©_link, tmp.to_str().unwrap());
// Opens url
if open::that(copy_link).is_err() {
eprintln!("{}", text::message(19));
notification::error(19);
text::exit();
};
}