From 3f366c4e314bc5f3d6030073f07579591241e100 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20BERTHO?= Date: Mon, 6 Nov 2023 21:41:19 +0100 Subject: [PATCH] Remove html merge --- .gitmodules | 3 - .../css}/photo-sphere-viewer.min.css | 0 embed/index.html | 89 ++----------------- {js => embed/js}/browser.min.js | 0 {js => embed/js}/photo-sphere-viewer.min.js | 0 {js => embed/js}/three.min.js | 0 ext/htmlfilemerger | 1 - html/index.html | 63 ------------- src/main.rs | 48 ++++++++-- 9 files changed, 50 insertions(+), 154 deletions(-) rename {css => embed/css}/photo-sphere-viewer.min.css (100%) rename {js => embed/js}/browser.min.js (100%) rename {js => embed/js}/photo-sphere-viewer.min.js (100%) rename {js => embed/js}/three.min.js (100%) delete mode 160000 ext/htmlfilemerger delete mode 100644 html/index.html diff --git a/.gitmodules b/.gitmodules index bcb57ca..e69de29 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +0,0 @@ -[submodule "ext/htmlfilemerger"] - path = ext/htmlfilemerger - url = https://github.com/DarkTrick/htmlfilemerger.git diff --git a/css/photo-sphere-viewer.min.css b/embed/css/photo-sphere-viewer.min.css similarity index 100% rename from css/photo-sphere-viewer.min.css rename to embed/css/photo-sphere-viewer.min.css diff --git a/embed/index.html b/embed/index.html index f1f4ed1..eb637f8 100644 --- a/embed/index.html +++ b/embed/index.html @@ -1,24 +1,11 @@ - - + + - + Panorama viewer - + - + - - - -
- - - - - -

Panorama

> - - - - diff --git a/src/main.rs b/src/main.rs index 1ae3f93..a86c706 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ #![windows_subsystem = "windows"] -use anyhow::{anyhow, Result}; +use anyhow::{anyhow, bail, Result}; use clap::{Arg, Command}; use fast_image_resize as fr; use image::{io::Reader as ImageReader, DynamicImage}; @@ -68,9 +68,19 @@ fn main() -> Result<()> { .ok_or_else(|| anyhow!("No file"))? }; + if !img_path.exists() { + MessageDialog::new() + .set_title("Image error") + .set_text(&format!("Image `{}` does not exist", img_path.display())) + .set_type(native_dialog::MessageType::Error) + .show_alert()?; + bail!("File `{}` does not exist !", img_path.display()); + } + info!("Open `{}`", img_path.display()); let (width, height) = image::image_dimensions(&img_path)?; const MAX_IMG_SIZE: u32 = 20_000_000; + info!("Image size {} * {}", width, height); let img_data_path = if height * width > MAX_IMG_SIZE { // @todo utilisation de rfd au lieu de message_dialog // @todo Option pas de resize / taille en ligne de commande @@ -111,9 +121,8 @@ fn main() -> Result<()> { img_path }; - info!("Generate HTML"); - let html = std::str::from_utf8(Embed::get("index.html").unwrap().data.as_ref())?.to_string(); - run_server(html, img_data_path); + info!("Run server"); + run_server(img_data_path); info!("Create webview"); let event_loop = EventLoop::new(); @@ -143,7 +152,7 @@ fn main() -> Result<()> { }); } -fn run_server(html: String, img_path: PathBuf) -> JoinHandle<()> { +fn run_server(img_path: PathBuf) -> JoinHandle<()> { std::thread::spawn(|| { info!("Create runtime"); let async_runtime = tokio::runtime::Builder::new_current_thread() @@ -151,13 +160,38 @@ fn run_server(html: String, img_path: PathBuf) -> JoinHandle<()> { .build() .unwrap(); info!("Create response"); - let hello = warp::path!("index.html").map(move || warp::reply::html(html.clone())); + let index = warp::path("index.html").map(|| { + info!("Request `index.html`"); + let datas = get_file_data("index.html"); + warp::reply::html(datas) + }); + let css = warp::path!("css" / String).map(move |val: String| { + info!("Request css `{}`", &val); + let datas = get_file_data(&format!("css/{}", val)); + warp::http::Response::builder().body(datas) + }); + let js = warp::path!("js" / String).map(move |val: String| { + info!("Request js `{}`", &val); + let datas = get_file_data(&format!("js/{}", val)); + warp::http::Response::builder().body(datas) + }); let img = warp::path!("img").map(move || std::fs::read(&img_path).unwrap()); info!("Launch webserver"); - async_runtime.block_on(warp::serve(hello.or(img)).run(([127, 0, 0, 1], 62371))); + async_runtime + .block_on(warp::serve(img.or(index).or(css).or(js)).run(([127, 0, 0, 1], 62371))); }) } +fn get_file_data(filename: &str) -> String { + if let Some(file) = Embed::get(filename) { + std::str::from_utf8(file.data.as_ref()) + .unwrap_or("") + .to_string() + } else { + "".to_string() + } +} + /// Fast resize pub fn fast_image_resize( img: &DynamicImage,