Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temporarily drop support for remote URLs #63

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
/test-package/assets
/cli-support/assets
/dist
.DS_Store
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ infer = "0.11.0"

# Remote assets
url = { version = "2.4.0", features = ["serde"] }
reqwest = { version = "0.12.5", features = ["blocking"] }
tracing = "0.1.40"

[features]
Expand Down
57 changes: 8 additions & 49 deletions common/src/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,34 +81,15 @@ impl AssetSource {
pub fn extension(&self) -> Option<String> {
match self {
Self::Local(path) => path.extension().map(|e| e.to_str().unwrap().to_string()),
Self::Remote(url) => reqwest::blocking::get(url.as_str())
.ok()
.and_then(|request| {
request
.headers()
.get("content-type")
.and_then(|content_type| {
content_type
.to_str()
.ok()
.map(|ty| ext_of_mime(ty).to_string())
})
}),
Self::Remote(_url) => unimplemented!("no more remote urls!"),
}
}

/// Attempts to get the mime type of the file source
pub fn mime_type(&self) -> Option<String> {
match self {
Self::Local(path) => get_mime_from_path(path).ok().map(|mime| mime.to_string()),
Self::Remote(url) => reqwest::blocking::get(url.as_str())
.ok()
.and_then(|request| {
request
.headers()
.get("content-type")
.and_then(|content_type| Some(content_type.to_str().ok()?.to_string()))
}),
Self::Remote(_url) => unimplemented!("no more remote urls!"),
}
}

Expand All @@ -127,19 +108,7 @@ impl AssetSource {
.map(|created| format!("{:?}", created))
})
}),
Self::Remote(url) => reqwest::blocking::get(url.as_str())
.ok()
.and_then(|request| {
request
.headers()
.get("last-modified")
.and_then(|last_modified| {
last_modified
.to_str()
.ok()
.map(|last_modified| last_modified.to_string())
})
}),
Self::Remote(_url) => unimplemented!("no more remote urls!"),
}
}

Expand All @@ -149,13 +118,7 @@ impl AssetSource {
AssetSource::Local(path) => Ok(std::fs::read_to_string(path).with_context(|| {
format!("Failed to read file from location: {}", path.display())
})?),
AssetSource::Remote(url) => {
let response = reqwest::blocking::get(url.as_str())
.with_context(|| format!("Failed to asset from url: {}", url.as_str()))?;
Ok(response.text().with_context(|| {
format!("Failed to read text for asset from url: {}", url.as_str())
})?)
}
AssetSource::Remote(_url) => unimplemented!("no more remote urls!"),
}
}

Expand All @@ -165,19 +128,15 @@ impl AssetSource {
AssetSource::Local(path) => Ok(std::fs::read(path).with_context(|| {
format!("Failed to read file from location: {}", path.display())
})?),
AssetSource::Remote(url) => {
let response = reqwest::blocking::get(url.as_str())
.with_context(|| format!("Failed to asset from url: {}", url.as_str()))?;
Ok(response.bytes().map(|b| b.to_vec()).with_context(|| {
format!("Failed to read text for asset from url: {}", url.as_str())
})?)
AssetSource::Remote(_url) => {
unimplemented!("no more remote urls!")
}
}
}
}

/// Get the mime type from a URI using its extension
fn ext_of_mime(mime: &str) -> &str {
fn _ext_of_mime(mime: &str) -> &str {
let mime = mime.split(';').next().unwrap_or_default();
match mime.trim() {
"application/octet-stream" => "bin",
Expand Down Expand Up @@ -296,7 +255,7 @@ impl Display for AssetError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
AssetError::NotFoundRelative(manifest_dir, path) =>
write!(f,"cannot find file `{}` in `{}`, please make sure it exists.\nAny relative paths are resolved relative to the manifest directory.",
write!(f,"cannot find file `{}` in `{}`, please make sure it exists.\nAny relative paths are resolved relative to the manifest directory.",
path,
manifest_dir.display()
),
Expand Down
10 changes: 5 additions & 5 deletions test-package/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ const ALL_ASSETS: &[&str] = &[
VIDEO_FILE,
TEXT_FILE,
TEXT_ASSET,
IMAGE_ASSET,
HTML_ASSET,
// IMAGE_ASSET,
// HTML_ASSET,
CSS_ASSET,
PNG_ASSET,
RESIZED_PNG_ASSET.path(),
Expand All @@ -22,9 +22,9 @@ const ALL_ASSETS: &[&str] = &[
RESIZED_AVIF_ASSET.path(),
WEBP_ASSET.path(),
RESIZED_WEBP_ASSET.path(),
ROBOTO_FONT,
COMFORTAA_FONT,
ROBOTO_FONT_LIGHT_FONT,
// ROBOTO_FONT,
// COMFORTAA_FONT,
// ROBOTO_FONT_LIGHT_FONT,
SCRIPT,
DATA,
FOLDER,
Expand Down
6 changes: 3 additions & 3 deletions test-package/test-package-dependency/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ pub static FORCE_IMPORT: u32 = 0;

const _: &str = manganis::classes!("flex flex-col p-5");
pub const TEXT_ASSET: &str = manganis::mg!("./src/asset.txt");
pub const IMAGE_ASSET: &str =
manganis::mg!("https://rustacean.net/assets/rustacean-flat-happy.png");
pub const HTML_ASSET: &str = manganis::mg!("https://github.com/DioxusLabs/dioxus");
// pub const IMAGE_ASSET: &str =
// manganis::mg!("https://rustacean.net/assets/rustacean-flat-happy.png");
// pub const HTML_ASSET: &str = manganis::mg!("https://github.com/DioxusLabs/dioxus");
24 changes: 12 additions & 12 deletions test-package/test-package-nested-dependency/src/font.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
pub const ROBOTO_FONT: &str = manganis::mg!(font()
.families(["Roboto"])
.weights([400])
.text("hello world"));
pub const COMFORTAA_FONT: &str = manganis::mg!(font()
.families(["Comfortaa"])
.weights([400])
.text("hello world"));
pub const ROBOTO_FONT_LIGHT_FONT: &str = manganis::mg!(font()
.families(["Roboto"])
.weights([200])
.text("hello world"));
// pub const ROBOTO_FONT: &str = manganis::mg!(font()
// .families(["Roboto"])
// .weights([400])
// .text("hello world"));
// pub const COMFORTAA_FONT: &str = manganis::mg!(font()
// .families(["Comfortaa"])
// .weights([400])
// .text("hello world"));
// pub const ROBOTO_FONT_LIGHT_FONT: &str = manganis::mg!(font()
// .families(["Roboto"])
// .weights([200])
// .text("hello world"));
Loading