Delete base64

This commit is contained in:
Rémi BERTHO 2023-11-05 20:57:38 +01:00
parent bda259cf14
commit f481105fd9
Signed by: dalan
GPG key ID: EE3B917931C07B64
5 changed files with 266 additions and 212 deletions

442
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -7,10 +7,9 @@ edition = "2021"
anyhow = "1.0" anyhow = "1.0"
log = "0.4" log = "0.4"
simplelog = "0.12" simplelog = "0.12"
wry = "0.33" wry = "0.34"
native-dialog = "0.6" native-dialog = "0.7"
rust-embed = "8" rust-embed = "8"
bs64 = "0.1"
directories = "5" directories = "5"
clap = "4" clap = "4"
warp = "0.3" warp = "0.3"

View file

@ -117,7 +117,7 @@ function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"f
<script> <script>
var PSV = new PhotoSphereViewer.Viewer({ var PSV = new PhotoSphereViewer.Viewer({
container: 'photosphere', container: 'photosphere',
panorama: "data:image/jpg;base64,__BASE_64_IMG__", panorama: 'img',
caption: 'Panorama displayed with Photo Sphere Viewer V4.7.1', caption: 'Panorama displayed with Photo Sphere Viewer V4.7.1',
defaultZoomLvl: 40, defaultZoomLvl: 40,
minFov: 5, minFov: 5,

View file

@ -46,7 +46,7 @@
<script> <script>
var PSV = new PhotoSphereViewer.Viewer({ var PSV = new PhotoSphereViewer.Viewer({
container: 'photosphere', container: 'photosphere',
panorama: "data:image/jpg;base64,__BASE_64_IMG__", panorama: 'img',
caption: 'Panorama displayed with Photo Sphere Viewer V4.7.1', caption: 'Panorama displayed with Photo Sphere Viewer V4.7.1',
defaultZoomLvl: 40, defaultZoomLvl: 40,
minFov: 5, minFov: 5,

View file

@ -2,13 +2,14 @@
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use clap::{Arg, Command}; use clap::{Arg, Command};
use fast_image_resize as fr;
use image::{io::Reader as ImageReader, DynamicImage}; use image::{io::Reader as ImageReader, DynamicImage};
use log::info; use log::info;
use native_dialog::{FileDialog, MessageDialog}; use native_dialog::{FileDialog, MessageDialog};
use rexiv2::Metadata; use rexiv2::Metadata;
use rust_embed::RustEmbed; use rust_embed::RustEmbed;
use simplelog::{ColorChoice, ConfigBuilder, LevelFilter, TermLogger, TerminalMode}; use simplelog::{ColorChoice, ConfigBuilder, LevelFilter, TermLogger, TerminalMode};
use std::{fs::File, io::BufWriter, path::PathBuf, thread::JoinHandle, num::NonZeroU32}; use std::{fs::File, io::BufWriter, num::NonZeroU32, path::PathBuf, thread::JoinHandle};
use tempfile::tempdir; use tempfile::tempdir;
use warp::Filter; use warp::Filter;
use wry::{ use wry::{
@ -19,7 +20,6 @@ use wry::{
}, },
webview::WebViewBuilder, webview::WebViewBuilder,
}; };
use fast_image_resize as fr;
#[derive(RustEmbed)] #[derive(RustEmbed)]
#[folder = "embed/"] #[folder = "embed/"]
@ -40,7 +40,11 @@ fn main() -> Result<()> {
let tmp_dir = tempdir()?; let tmp_dir = tempdir()?;
let cmd = Command::new("Simple panorama viewer") let cmd = Command::new("Simple panorama viewer")
.arg(Arg::new("filename").value_parser(clap::value_parser!(PathBuf)).help("Image path")) .arg(
Arg::new("filename")
.value_parser(clap::value_parser!(PathBuf))
.help("Image path"),
)
.get_matches(); .get_matches();
let img_path = if let Some(img_path) = cmd.get_one::<PathBuf>("filename") { let img_path = if let Some(img_path) = cmd.get_one::<PathBuf>("filename") {
@ -106,14 +110,10 @@ fn main() -> Result<()> {
} else { } else {
img_path img_path
}; };
let img_data = std::fs::read(&img_data_path)?;
tmp_dir.close()?;
let img_base_64 = bs64::encode(&img_data);
info!("Generate HTML"); info!("Generate HTML");
let html = std::str::from_utf8(Embed::get("index.html").unwrap().data.as_ref())? let html = std::str::from_utf8(Embed::get("index.html").unwrap().data.as_ref())?.to_string();
.replace("__BASE_64_IMG__", &img_base_64); run_server(html, img_data_path);
run_server(html);
info!("Create webview"); info!("Create webview");
let event_loop = EventLoop::new(); let event_loop = EventLoop::new();
@ -122,7 +122,7 @@ fn main() -> Result<()> {
.with_maximized(true) .with_maximized(true)
.build(&event_loop)?; .build(&event_loop)?;
let _webview = WebViewBuilder::new(window)? let _webview = WebViewBuilder::new(window)?
.with_url("http://127.0.0.1:62371")? .with_url("http://127.0.0.1:62371/index.html")?
.build()?; .build()?;
info!("Event loop"); info!("Event loop");
@ -143,7 +143,7 @@ fn main() -> Result<()> {
}); });
} }
fn run_server(html: String) -> JoinHandle<()> { fn run_server(html: String, img_path: PathBuf) -> JoinHandle<()> {
std::thread::spawn(|| { std::thread::spawn(|| {
info!("Create runtime"); info!("Create runtime");
let async_runtime = tokio::runtime::Builder::new_current_thread() let async_runtime = tokio::runtime::Builder::new_current_thread()
@ -151,9 +151,10 @@ fn run_server(html: String) -> JoinHandle<()> {
.build() .build()
.unwrap(); .unwrap();
info!("Create response"); info!("Create response");
let hello = warp::any().map(move || warp::reply::html(html.clone())); let hello = warp::path!("index.html").map(move || warp::reply::html(html.clone()));
let img = warp::path!("img").map(move || std::fs::read(&img_path).unwrap());
info!("Launch webserver"); info!("Launch webserver");
async_runtime.block_on(warp::serve(hello).run(([127, 0, 0, 1], 62371))); async_runtime.block_on(warp::serve(hello.or(img)).run(([127, 0, 0, 1], 62371)));
}) })
} }