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
extern crate json;
extern crate reqwest;
mod file;
use self::file::HastebinFile;
use reqwest::Client;
use std::fs;
use std::io::Read;
pub fn upload_buffer<'a>(
file_name: &'a str,
max_chars: Option<&'a str>,
) -> std::io::Result<String> {
let hastebin_file = read_file(file_name)?;
if hastebin_file.is_too_big() {
println!("Error: File is too big, 50MB max.");
std::process::exit(0);
} else {
let client = Client::new();
let mut response = client
.post("https://hastebin.com/documents")
.body(hastebin_file.get_buffer())
.send()
.expect("Cannot send the response");
let res_json = json::parse(&response.text().unwrap()).unwrap();
let url = format!("https://hastebin.com/{}", res_json["key"].to_string());
Ok(url)
}
}
fn read_file(path: &str) -> std::io::Result<HastebinFile> {
let mut file: fs::File = fs::File::open(path)?;
let mut buffer = String::new();
file.read_to_string(&mut buffer)?;
Ok(HastebinFile::new(buffer, String::from(path)))
}
pub enum Os {
Window,
Linux,
Macos,
Unknow,
}