mirror of
https://firefish.dev/firefish/emoji-gen.git
synced 2024-09-19 11:50:21 -06:00
Fix errors on different extension or missing fields
This commit is contained in:
parent
5b9dcef126
commit
733d8df766
1 changed files with 6 additions and 5 deletions
11
src/main.rs
11
src/main.rs
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue