Skip to content

Commit

Permalink
feat(version): 0.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
developerfred committed Nov 24, 2024
1 parent 3c96d55 commit 20453a9
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 82 deletions.
8 changes: 8 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[build]
rustflags = ["--cfg", "procmacro2_semver_exempt"]

[target.'cfg(all())']
rustflags = ["--cfg", "procmacro2_semver_exempt"]

[unstable]
proc-macro = true
7 changes: 6 additions & 1 deletion Cargo.lock

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

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
dioxus-native = { git = "https://github.com/DioxusLabs/blitz", branch = "main" }
reqwest = { version = "0.11", features = ["blocking"] }
hyper = { version = "1.0", features = ["full"] }

[dev-dependencies]
tokio-test = "0.4"
tokio-test = "0.4"
tower = { version = "0.4", features = ["util"] }
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[toolchain]
channel = "nightly-2024-03-20"
channel = "nightly"
components = ["rustfmt", "clippy"]
targets = ["x86_64-unknown-linux-gnu"]
38 changes: 14 additions & 24 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use base64::{engine::general_purpose::URL_SAFE, Engine};
use dioxus_native::Config;
use serde::Deserialize;
use std::{net::SocketAddr, time::Instant};
use tokio::task::block_in_place;
use tower_http::trace::TraceLayer;
use tracing::{info, Level};
use url::Url;
Expand All @@ -25,22 +26,22 @@ fn validate_url(url_str: &str) -> Result<Url, String> {
Url::parse(url_str).map_err(|_| "Invalid URL".to_string())
}

async fn render_html(url: &Url) -> Result<Vec<u8>, String> {
async fn render_html(url: &Url, _width: u32, _height: u32) -> Result<Vec<u8>, String> {
let html_content = reqwest::blocking::get(url.as_str())
.and_then(|response| response.text())
.map_err(|e| format!("Failed to fetch URL: {}", e))?;

let config = Config {
stylesheets: Vec::new(),
base_url: Some(url.to_string()),
..Default::default()
};

let html_content = reqwest::blocking::get(url.as_str())
.and_then(|response| response.text())
.map_err(|e| format!("Failed to fetch URL: {}", e))?;

tokio::task::spawn_blocking(move || {
dioxus_native::launch_static_html_cfg(&html_content, config)
tokio::task::spawn_blocking(move || {
dioxus_native::launch_static_html_cfg(&html_content, config);
Ok(Vec::new())
})
.await
.map_err(|e| format!("Render failed: {}", e))?
.map_err(|e| format!("Task failed: {}", e))?
}

async fn render_url(Query(params): Query<RenderParams>) -> impl IntoResponse {
Expand All @@ -51,9 +52,8 @@ async fn render_url(Query(params): Query<RenderParams>) -> impl IntoResponse {
.and_then(|url| {
info!("Starting render for URL: {}", url);

let load_start = Instant::now();
let result = tokio::block_in_place(|| {
tokio::runtime::Handle::current().block_on(render_html(&url))
let result = block_in_place(|| {
tokio::runtime::Handle::current().block_on(render_html(&url, params.w, params.h))
});

let total_time = start.elapsed();
Expand All @@ -73,8 +73,7 @@ async fn health_check() -> impl IntoResponse {
}

#[tokio::main]
async fn main() {
// Initialize logging
async fn main() {
tracing_subscriber::fmt()
.with_target(false)
.with_level(true)
Expand Down Expand Up @@ -131,13 +130,4 @@ mod tests {
let response = health_check().await.into_response();
assert_eq!(response.status(), StatusCode::OK);
}

#[test]
fn test_render_params_deserialization() {
let json = r#"{"url":"aHR0cHM6Ly9nb29nbGUuY29t","w":800,"h":600}"#;
let params: RenderParams = serde_json::from_str(json).unwrap();
assert_eq!(params.url, "aHR0cHM6Ly9nb29nbGUuY29t");
assert_eq!(params.w, 800);
assert_eq!(params.h, 600);
}
}
}
55 changes: 0 additions & 55 deletions tests/integration_tests.rs

This file was deleted.

0 comments on commit 20453a9

Please sign in to comment.