1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use thiserror::Error;

use crate::{
    internal::{conversion::IntoBindgen, wit},
    prelude::EntityId,
};

#[derive(Error, Debug)]
/// Errors that can occur when resolving an asset URL.
pub enum UrlError {
    #[error("Invalid URL: {0}")]
    /// The URL is invalid.
    InvalidUrl(String),
}
impl From<wit::asset::UrlError> for UrlError {
    fn from(value: wit::asset::UrlError) -> Self {
        match value {
            wit::asset::UrlError::InvalidUrl(err) => UrlError::InvalidUrl(err),
        }
    }
}

/// Resolves a asset path for an Ambient asset to an absolute URL.
#[doc(hidden)]
pub fn url_for_package_asset(package_id: EntityId, path: &str) -> Result<String, UrlError> {
    Ok(wit::asset::url(package_id.into_bindgen(), path)?)
}