almost woring

This commit is contained in:
Oliver Atkinson 2024-12-13 13:27:33 -07:00
parent 55ef1a788f
commit b5e30e467b
3 changed files with 8 additions and 11 deletions

1
Cargo.lock generated
View File

@ -1187,7 +1187,6 @@ dependencies = [
"tokio", "tokio",
"tracing", "tracing",
"tracing-subscriber", "tracing-subscriber",
"url",
] ]
[[package]] [[package]]

View File

@ -8,5 +8,4 @@ rocket = {path = "../Rocket/core/lib"}
tokio = { version = "1.40.0", features = ["full"] } tokio = { version = "1.40.0", features = ["full"] }
tracing = "0.1.40" tracing = "0.1.40"
tracing-subscriber = "0.3.18" tracing-subscriber = "0.3.18"
url = "2.5.2"
minio = {git="https://github.com/minio/minio-rs.git", rev = "c28f576"} minio = {git="https://github.com/minio/minio-rs.git", rev = "c28f576"}

View File

@ -1,7 +1,6 @@
use rocket::{fairing::{Fairing, Info, Kind}, fs::FileServer, get, http::Header, routes, Request, Response, State}; use rocket::{fairing::{Fairing, Info, Kind}, fs::FileServer, get, http::Header, routes, Request, Response, State};
use s3::S3; use s3::S3;
use tracing::{info, Level}; use tracing::{info, Level};
use url::Url;
mod s3; mod s3;
@ -21,7 +20,7 @@ async fn main() {
.init(); .init();
let config = Config { let config = Config {
s3_bucket: "v1.10", s3_bucket: "b64v1",
s3_url: "http://localhost:9000", s3_url: "http://localhost:9000",
s3_access_key: "8UO76z8wCs9DnpxSbQUY", s3_access_key: "8UO76z8wCs9DnpxSbQUY",
s3_secret_key: "xwKVMpf2jzgprsdo85Dvo74UmO84y0aRrAUorYY5", s3_secret_key: "xwKVMpf2jzgprsdo85Dvo74UmO84y0aRrAUorYY5",
@ -42,14 +41,12 @@ async fn main() {
} }
#[get("/s3/<path>")] #[get("/s3/<path>")]
async fn get_s3_content(path: &str, db: &State<S3>) -> String { async fn get_s3_content(path: &str, db: &State<S3>) -> Option<String> {
info!(path); if let Some(resp) = db.get(&path).await {
// TODO this is just pseudo-code return Some(resp)
let url = "en.wikipedia.org/wiki/CNBC";
if let Some(resp) = db.get(&url).await {
return resp
} }
"Hello world.".to_owned() // instead of some/none I would rather this be 200/404
None
} }
// CORS, to allow other sites to request this from their front-end // CORS, to allow other sites to request this from their front-end
@ -69,5 +66,7 @@ impl Fairing for CORS {
response.set_header(Header::new("Access-Control-Allow-Methods", "POST, GET, PATCH, OPTIONS")); response.set_header(Header::new("Access-Control-Allow-Methods", "POST, GET, PATCH, OPTIONS"));
response.set_header(Header::new("Access-Control-Allow-Headers", "*")); response.set_header(Header::new("Access-Control-Allow-Headers", "*"));
response.set_header(Header::new("Access-Control-Allow-Credentials", "true")); response.set_header(Header::new("Access-Control-Allow-Credentials", "true"));
// TODO set this automatically like how Rocket/core/lib/src/fs/server.rs does (bottom of file)
response.set_header(Header::new("Content-Type", "text/html"));
} }
} }