this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Request -> Image, no more local files

+15 -12
+15 -12
emojidex
··· 6 6 //! reqwest = { version = "0.11.3", features = ["blocking", "json"] } 7 7 //! serde = { version = "1.0", features = ["derive"] } 8 8 //! viuer = "0.4.0" 9 + //! image = "0.23.14" 9 10 //! ``` 10 11 11 12 use argh::FromArgs; 13 + use image::io::Reader; 12 14 use reqwest::blocking::Client; 13 15 use serde::Deserialize; 14 16 use viuer::Config; 15 17 16 - use std::env; 17 - use std::fs::File; 18 - use std::io; 18 + use std::io::{BufReader, Cursor}; 19 19 use std::str::FromStr; 20 20 21 21 const BASE_API_URL: &str = "https://www.emojidex.com/api/v1"; ··· 167 167 images_only, 168 168 } = argh::from_env(); 169 169 170 - let tmp_dir = env::temp_dir(); 171 - 172 170 let tags = tag 173 171 .into_iter() 174 172 .map(|tag| ("tags[]", tag)) ··· 246 244 } 247 245 248 246 if resolution != Resolution::None { 249 - let filepath = tmp_dir.join(format!("{}.png", encoded_code)); 250 - let mut file = File::create(filepath.clone()).expect("should be able to create file"); 251 - 252 - let mut res = client 247 + let res = client 253 248 .get(format!( 254 249 "{}/{}/{}.png", 255 250 BASE_CDN_URL, ··· 258 253 )) 259 254 .send() 260 255 .expect("should be able to get image"); 261 - io::copy(&mut res, &mut file).expect("should be able to copy file"); 256 + 257 + let bytes = res.bytes().expect("should be able to get bytes"); 258 + let reader = Reader::new(BufReader::new(Cursor::new(bytes))) 259 + .with_guessed_format() 260 + .expect("should be able to guess format"); 261 + 262 + let image = reader 263 + .decode() 264 + .expect("should be able to interpret as image"); 262 265 263 - viuer::print_from_file( 264 - filepath.to_str().unwrap(), 266 + viuer::print( 267 + &image, 265 268 &Config { 266 269 absolute_offset: false, 267 270 ..Default::default()