Fix errors on different extension or missing fields

This commit is contained in:
Mehdi Benadel 2023-07-30 20:24:12 +02:00
parent 5b9dcef126
commit 733d8df766

View file

@ -82,8 +82,8 @@ struct Meta {
}
#[derive(Serialize, Deserialize)]
struct EmojiResponse {
shortcode: String,
url: String,
shortcode: Option<String>,
url: Option<String>,
static_url: String,
category: Option<String>,
}
@ -121,6 +121,7 @@ fn getTypename(typeEnum: imghdr::Type) -> &'static str {
imghdr::Type::Rgbe => "rgbe",
imghdr::Type::Flif => "flif",
imghdr::Type::Ico => "ico",
_ => "xxx",
};
}
@ -220,8 +221,8 @@ fn get_host_emojis(host: &Url, tmpFolder: &Path) -> Vec<Emoji> {
let mut emojos = emojiRes;
emojos.iter().map(| res |
get_host_emoji_data(
Url::parse(res.url.as_str().clone()).unwrap(),
res.shortcode.clone(),
Url::parse(res.url.as_ref().unwrap().as_str().clone()).unwrap(),
res.shortcode.clone().unwrap_or_default(),
res.category.clone().unwrap_or_default(),
host.to_string().clone(),
tmpFolder,
@ -259,7 +260,7 @@ fn get_host_emoji_data(fileUrl: Url, name: String, category: String, host: Strin
fn get_image_from_url(fileUrl: &Url, tmpFolder: &Path, filename: String) -> String {
let img_bytes = reqwest::blocking::get(fileUrl.clone()).unwrap().bytes().unwrap();
let extension = getTypename(imghdr::from_bytes(img_bytes.clone()).unwrap());
let extension = getTypename(imghdr::from_bytes(img_bytes.clone()).unwrap_or(Type::Xbm));
let mut tmpFilepath: PathBuf = tmpFolder.join(filename);
tmpFilepath.set_extension(extension);