make compatible with caddy reverse proxy for local https
This commit is contained in:
@@ -4,6 +4,7 @@ use crate::hooks::use_user_context;
|
||||
use gloo_net::http::Request;
|
||||
|
||||
use js_sys::Array;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use wasm_bindgen::{prelude::wasm_bindgen, JsCast, JsValue};
|
||||
use web_sys::{DataTransferItemList, File, FileSystemDirectoryEntry, FileSystemEntry};
|
||||
use weblog::console_log;
|
||||
@@ -12,6 +13,15 @@ use yew_hooks::prelude::*;
|
||||
|
||||
use common::OutputPicture;
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct PhotosWrapper {
|
||||
photos: Vec<String>,
|
||||
}
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct PhotosUrlsWrapper {
|
||||
photos: Vec<(String, String)>,
|
||||
}
|
||||
|
||||
#[function_component(Home)]
|
||||
pub fn home() -> Html {
|
||||
let user_ctx = use_user_context();
|
||||
@@ -92,7 +102,7 @@ pub fn home() -> Html {
|
||||
let uiae: Vec<String> = files
|
||||
.iter()
|
||||
.map(|x| {
|
||||
if let Ok(filepath) = js_sys::Reflect::get(&x, &JsValue::from_str("filepath")) {
|
||||
if let Ok(filepath) = js_sys::Reflect::get(x, &JsValue::from_str("filepath")) {
|
||||
filepath.as_string().unwrap_or("".to_string())
|
||||
} else {
|
||||
"".to_string()
|
||||
@@ -100,6 +110,17 @@ pub fn home() -> Html {
|
||||
})
|
||||
.collect();
|
||||
console_log!("end", uiae.join("\n"));
|
||||
let url = "/api/photos/upload";
|
||||
let photos: PhotosUrlsWrapper = Request::post(url)
|
||||
.json(&PhotosWrapper { photos: uiae })
|
||||
.unwrap()
|
||||
.send()
|
||||
.await
|
||||
.unwrap()
|
||||
.json()
|
||||
.await
|
||||
.unwrap();
|
||||
console_log!("{}", serde_json::to_string(&photos).unwrap());
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -19,6 +19,9 @@ pub fn grid(props: &GridProps) -> Html {
|
||||
let target_height = 100;
|
||||
let container_width = if props.width == 0 { 0 } else { props.width - 4 };
|
||||
let margin = 2;
|
||||
if container_width == 0 {
|
||||
return html! {};
|
||||
}
|
||||
let dimensions = compute_row_layout(
|
||||
container_width,
|
||||
target_height,
|
||||
|
||||
@@ -9,7 +9,6 @@ use gloo_storage::{LocalStorage, Storage};
|
||||
use lazy_static::lazy_static;
|
||||
use parking_lot::RwLock;
|
||||
|
||||
const API_ROOT: &str = dotenv!("API_ROOT");
|
||||
const TOKEN_KEY: &str = "jheuel-token";
|
||||
|
||||
lazy_static! {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use super::API_ROOT;
|
||||
use crate::error::Error;
|
||||
use crate::types;
|
||||
use gloo_net::http::{Method, Request as GlooRequest};
|
||||
@@ -7,7 +6,6 @@ use weblog::console_log;
|
||||
pub struct Request(Option<GlooRequest>);
|
||||
|
||||
fn request<B: serde::Serialize>(method: gloo_net::http::Method, url: &str, body: &B) -> Request {
|
||||
let url = format!("{}{}", API_ROOT, url);
|
||||
let builder = GlooRequest::new(&url)
|
||||
.method(method)
|
||||
.header("Content-Type", "application/json");
|
||||
@@ -56,12 +54,10 @@ impl Request {
|
||||
}
|
||||
|
||||
pub fn request_delete(url: &str) -> Request {
|
||||
let url = format!("{}{}", API_ROOT, url);
|
||||
Request(Some(GlooRequest::new(&url).method(Method::DELETE))).set_token()
|
||||
}
|
||||
|
||||
pub fn request_get(url: &str) -> Request {
|
||||
let url = format!("{}{}", API_ROOT, url);
|
||||
Request(Some(GlooRequest::new(&url).method(Method::GET))).set_token()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user