Skip to content

Commit

Permalink
Merge pull request #126 from axodotdev/remote_asset_copy_zip
Browse files Browse the repository at this point in the history
fix: better handle extensions for unrecognized mimetypes
  • Loading branch information
mistydemeo authored Jun 6, 2024
2 parents c6b66c5 + 7982777 commit fc00926
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,11 @@ impl RemoteAsset {
}
}

fn extension(mimetype: mime::Mime, origin_path: &str) -> Result<String> {
fn extension(mimetype: mime::Mime, origin_path: &str) -> Option<String> {
match mimetype.type_() {
mime::IMAGE => RemoteAsset::image_extension(mimetype, origin_path),
mime::TEXT => RemoteAsset::text_extension(mimetype, origin_path),
_ => Err(AxoassetError::RemoteAssetMimeTypeNotSupported {
origin_path: origin_path.to_string(),
mimetype: mimetype.to_string(),
}),
mime::IMAGE => RemoteAsset::image_extension(mimetype, origin_path).ok(),
mime::TEXT => RemoteAsset::text_extension(mimetype, origin_path).ok(),
_ => None,
}
}

Expand Down Expand Up @@ -179,10 +176,14 @@ impl RemoteAsset {
filestem.remove(0);
if filestem.contains('.') {
Ok(filestem)
} else if let Ok(mimetype) = RemoteAsset::mimetype(headers, origin_path) {
if let Some(extension) = RemoteAsset::extension(mimetype, origin_path) {
Ok(format!("{filestem}.{extension}"))
} else {
Ok(filestem)
}
} else {
let extension =
RemoteAsset::extension(RemoteAsset::mimetype(headers, origin_path)?, origin_path)?;
Ok(format!("{filestem}.{extension}"))
Ok(filestem)
}
}
}

0 comments on commit fc00926

Please sign in to comment.