From 55a868eef35cc45cb32962487a9083928e084d7c Mon Sep 17 00:00:00 2001 From: oliver Date: Fri, 13 Dec 2024 18:02:22 -0700 Subject: [PATCH] updated to new storage schema --- browser/background.js | 9 +++++++-- src/main.rs | 16 +++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/browser/background.js b/browser/background.js index 32d8344..c08aef6 100644 --- a/browser/background.js +++ b/browser/background.js @@ -19,12 +19,17 @@ function handle_header(req) { let old = "" function url_redirect (req) { - let b64 = btoa(req.url) + + let url = new URL(req.url); + let path = url.pathname; + let domain = url.hostname; + + let b64 = btoa(path) if (!req.url.startsWith("http://localhost")) { old = req.url // console.debug(`Loading: ${req.url} || ${b64}`); return { - redirectUrl: `http://localhost:4433/s3/${b64}` + redirectUrl: `http://localhost:4433/s3/${domain}/${b64}` } } } diff --git a/src/main.rs b/src/main.rs index fce629b..09a1458 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,10 +21,10 @@ async fn main() { .init(); let config = Config { - s3_bucket: "b64v1", + s3_bucket: "b64v2", s3_url: "http://localhost:9000", - s3_access_key: "8UO76z8wCs9DnpxSbQUY", - s3_secret_key: "xwKVMpf2jzgprsdo85Dvo74UmO84y0aRrAUorYY5", + s3_access_key: "Eyp21VVclXP8xx49bJ6D", + s3_secret_key: "VxqU9hQ2gl7TvHIFzCM74Og6rQUZcpgYpHNUBnVm", }; let s3 = S3::connect(&config).await.expect("Failed to connect to minio, aborting."); @@ -58,13 +58,15 @@ impl<'r> FromRequest<'r> for Og{ } -#[get("/s3/")] -async fn get_s3_content(path: &str, db: &State, og: Og) -> (Status, (ContentType, String)) { +#[get("/s3//")] +async fn get_s3_content(domain: &str, file: &str, db: &State, og: Og) -> (Status, (ContentType, String)) { use base64::prelude::*; + let filename = domain.to_owned() + "/" + file; + info!("{:?}", og.og); - if let Some(resp) = db.get(&path).await { - let content_type = if let Ok(url) = BASE64_URL_SAFE.decode(path) { + if let Some(resp) = db.get(&filename).await { + let content_type = if let Ok(url) = BASE64_URL_SAFE.decode(file) { let url = url.into_iter().map(|f| f as char).collect::(); if let Some(filetype) = url.split('.').collect::>().last() { ContentType::from_extension(&filetype).unwrap_or(ContentType::HTML)