Skip to content

Commit

Permalink
Merge pull request #34 from ThomasVille/main
Browse files Browse the repository at this point in the history
Allow URLs without any extension
  • Loading branch information
johanhelsing authored Sep 16, 2024
2 parents 0cd8096 + 6e33601 commit 01dbfc7
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions src/web_asset_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,12 @@ impl WebAssetReader {
}

/// See [bevy::asset::io::get_meta_path]
fn make_meta_uri(&self, path: &Path) -> PathBuf {
fn make_meta_uri(&self, path: &Path) -> Option<PathBuf> {
let mut uri = self.make_uri(path);
let mut extension = path
.extension()
.expect("asset paths must have extensions")
.to_os_string();
let mut extension = path.extension()?.to_os_string();
extension.push(".meta");
uri.set_extension(extension);
uri
Some(uri)
}
}

Expand Down Expand Up @@ -160,11 +157,13 @@ impl AssetReader for WebAssetReader {
get(self.make_uri(path))
}

fn read_meta<'a>(
&'a self,
path: &'a Path,
) -> impl ConditionalSendFuture<Output = Result<Box<Reader<'a>>, AssetReaderError>> {
get(self.make_meta_uri(path))
async fn read_meta<'a>(&'a self, path: &'a Path) -> Result<Box<Reader<'a>>, AssetReaderError> {
match self.make_meta_uri(path) {
Some(uri) => get(uri).await,
None => Err(AssetReaderError::NotFound(
"source path has no extension".into(),
)),
}
}

async fn is_directory<'a>(&'a self, _path: &'a Path) -> Result<bool, AssetReaderError> {
Expand Down Expand Up @@ -210,6 +209,7 @@ mod tests {
assert_eq!(
WebAssetReader::Http
.make_meta_uri(Path::new("s3.johanhelsing.studio/dump/favicon.png"))
.expect("cannot create meta uri")
.to_str()
.unwrap(),
"http://s3.johanhelsing.studio/dump/favicon.png.meta"
Expand All @@ -221,9 +221,18 @@ mod tests {
assert_eq!(
WebAssetReader::Https
.make_meta_uri(Path::new("s3.johanhelsing.studio/dump/favicon.png"))
.expect("cannot create meta uri")
.to_str()
.unwrap(),
"https://s3.johanhelsing.studio/dump/favicon.png.meta"
);
}

#[test]
fn make_https_without_extension_meta_uri() {
assert_eq!(
WebAssetReader::Https.make_meta_uri(Path::new("s3.johanhelsing.studio/dump/favicon")),
None
);
}
}

0 comments on commit 01dbfc7

Please sign in to comment.