Delete base64
This commit is contained in:
parent
bda259cf14
commit
f481105fd9
5 changed files with 266 additions and 212 deletions
442
Cargo.lock
generated
442
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -7,10 +7,9 @@ edition = "2021"
|
|||
anyhow = "1.0"
|
||||
log = "0.4"
|
||||
simplelog = "0.12"
|
||||
wry = "0.33"
|
||||
native-dialog = "0.6"
|
||||
wry = "0.34"
|
||||
native-dialog = "0.7"
|
||||
rust-embed = "8"
|
||||
bs64 = "0.1"
|
||||
directories = "5"
|
||||
clap = "4"
|
||||
warp = "0.3"
|
||||
|
|
|
@ -117,7 +117,7 @@ function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"f
|
|||
<script>
|
||||
var PSV = new PhotoSphereViewer.Viewer({
|
||||
container: 'photosphere',
|
||||
panorama: "data:image/jpg;base64,__BASE_64_IMG__",
|
||||
panorama: 'img',
|
||||
caption: 'Panorama displayed with Photo Sphere Viewer V4.7.1',
|
||||
defaultZoomLvl: 40,
|
||||
minFov: 5,
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
<script>
|
||||
var PSV = new PhotoSphereViewer.Viewer({
|
||||
container: 'photosphere',
|
||||
panorama: "data:image/jpg;base64,__BASE_64_IMG__",
|
||||
panorama: 'img',
|
||||
caption: 'Panorama displayed with Photo Sphere Viewer V4.7.1',
|
||||
defaultZoomLvl: 40,
|
||||
minFov: 5,
|
||||
|
|
27
src/main.rs
27
src/main.rs
|
@ -2,13 +2,14 @@
|
|||
|
||||
use anyhow::{anyhow, Result};
|
||||
use clap::{Arg, Command};
|
||||
use fast_image_resize as fr;
|
||||
use image::{io::Reader as ImageReader, DynamicImage};
|
||||
use log::info;
|
||||
use native_dialog::{FileDialog, MessageDialog};
|
||||
use rexiv2::Metadata;
|
||||
use rust_embed::RustEmbed;
|
||||
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 warp::Filter;
|
||||
use wry::{
|
||||
|
@ -19,7 +20,6 @@ use wry::{
|
|||
},
|
||||
webview::WebViewBuilder,
|
||||
};
|
||||
use fast_image_resize as fr;
|
||||
|
||||
#[derive(RustEmbed)]
|
||||
#[folder = "embed/"]
|
||||
|
@ -40,7 +40,11 @@ fn main() -> Result<()> {
|
|||
let tmp_dir = tempdir()?;
|
||||
|
||||
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();
|
||||
|
||||
let img_path = if let Some(img_path) = cmd.get_one::<PathBuf>("filename") {
|
||||
|
@ -106,14 +110,10 @@ fn main() -> Result<()> {
|
|||
} else {
|
||||
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");
|
||||
let html = std::str::from_utf8(Embed::get("index.html").unwrap().data.as_ref())?
|
||||
.replace("__BASE_64_IMG__", &img_base_64);
|
||||
run_server(html);
|
||||
let html = std::str::from_utf8(Embed::get("index.html").unwrap().data.as_ref())?.to_string();
|
||||
run_server(html, img_data_path);
|
||||
|
||||
info!("Create webview");
|
||||
let event_loop = EventLoop::new();
|
||||
|
@ -122,7 +122,7 @@ fn main() -> Result<()> {
|
|||
.with_maximized(true)
|
||||
.build(&event_loop)?;
|
||||
let _webview = WebViewBuilder::new(window)?
|
||||
.with_url("http://127.0.0.1:62371")?
|
||||
.with_url("http://127.0.0.1:62371/index.html")?
|
||||
.build()?;
|
||||
|
||||
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(|| {
|
||||
info!("Create runtime");
|
||||
let async_runtime = tokio::runtime::Builder::new_current_thread()
|
||||
|
@ -151,9 +151,10 @@ fn run_server(html: String) -> JoinHandle<()> {
|
|||
.build()
|
||||
.unwrap();
|
||||
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");
|
||||
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)));
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue