diff options
author | Daniel García <[email protected]> | 2021-11-07 18:53:39 +0100 |
---|---|---|
committer | Daniel García <[email protected]> | 2022-02-27 21:36:31 +0100 |
commit | 0b7d6bf6df5a83dcc95d063baa04d8818eb9d7db (patch) | |
tree | b2f8eb96a8d9053dbbbdcbae94dbd3b45e1c298d /src/api/web.rs | |
parent | 89fe05b6ccfa577c8348f788a8e700e2b7247e77 (diff) | |
download | vaultwarden-0b7d6bf6df5a83dcc95d063baa04d8818eb9d7db.tar.gz vaultwarden-0b7d6bf6df5a83dcc95d063baa04d8818eb9d7db.zip |
Update to rocket 0.5 and made code async, missing updating all db calls, that are currently blocking
Diffstat (limited to 'src/api/web.rs')
-rw-r--r-- | src/api/web.rs | 49 |
1 files changed, 22 insertions, 27 deletions
diff --git a/src/api/web.rs b/src/api/web.rs index 9a5f74cc..f911436a 100644 --- a/src/api/web.rs +++ b/src/api/web.rs @@ -1,7 +1,7 @@ use std::path::{Path, PathBuf}; -use rocket::{http::ContentType, response::content::Content, response::NamedFile, Route}; -use rocket_contrib::json::Json; +use rocket::serde::json::Json; +use rocket::{fs::NamedFile, http::ContentType, Route}; use serde_json::Value; use crate::{ @@ -21,16 +21,16 @@ pub fn routes() -> Vec<Route> { } #[get("/")] -fn web_index() -> Cached<Option<NamedFile>> { - Cached::short(NamedFile::open(Path::new(&CONFIG.web_vault_folder()).join("index.html")).ok(), false) +async fn web_index() -> Cached<Option<NamedFile>> { + Cached::short(NamedFile::open(Path::new(&CONFIG.web_vault_folder()).join("index.html")).await.ok(), false) } #[get("/app-id.json")] -fn app_id() -> Cached<Content<Json<Value>>> { +fn app_id() -> Cached<(ContentType, Json<Value>)> { let content_type = ContentType::new("application", "fido.trusted-apps+json"); Cached::long( - Content( + ( content_type, Json(json!({ "trustedFacets": [ @@ -58,13 +58,13 @@ fn app_id() -> Cached<Content<Json<Value>>> { } #[get("/<p..>", rank = 10)] // Only match this if the other routes don't match -fn web_files(p: PathBuf) -> Cached<Option<NamedFile>> { - Cached::long(NamedFile::open(Path::new(&CONFIG.web_vault_folder()).join(p)).ok(), true) +async fn web_files(p: PathBuf) -> Cached<Option<NamedFile>> { + Cached::long(NamedFile::open(Path::new(&CONFIG.web_vault_folder()).join(p)).await.ok(), true) } #[get("/attachments/<uuid>/<file_id>")] -fn attachments(uuid: SafeString, file_id: SafeString) -> Option<NamedFile> { - NamedFile::open(Path::new(&CONFIG.attachments_folder()).join(uuid).join(file_id)).ok() +async fn attachments(uuid: SafeString, file_id: SafeString) -> Option<NamedFile> { + NamedFile::open(Path::new(&CONFIG.attachments_folder()).join(uuid).join(file_id)).await.ok() } // We use DbConn here to let the alive healthcheck also verify the database connection. @@ -78,25 +78,20 @@ fn alive(_conn: DbConn) -> Json<String> { } #[get("/vw_static/<filename>")] -fn static_files(filename: String) -> Result<Content<&'static [u8]>, Error> { +fn static_files(filename: String) -> Result<(ContentType, &'static [u8]), Error> { match filename.as_ref() { - "mail-github.png" => Ok(Content(ContentType::PNG, include_bytes!("../static/images/mail-github.png"))), - "logo-gray.png" => Ok(Content(ContentType::PNG, include_bytes!("../static/images/logo-gray.png"))), - "error-x.svg" => Ok(Content(ContentType::SVG, include_bytes!("../static/images/error-x.svg"))), - "hibp.png" => Ok(Content(ContentType::PNG, include_bytes!("../static/images/hibp.png"))), - "vaultwarden-icon.png" => { - Ok(Content(ContentType::PNG, include_bytes!("../static/images/vaultwarden-icon.png"))) - } - - "bootstrap.css" => Ok(Content(ContentType::CSS, include_bytes!("../static/scripts/bootstrap.css"))), - "bootstrap-native.js" => { - Ok(Content(ContentType::JavaScript, include_bytes!("../static/scripts/bootstrap-native.js"))) - } - "identicon.js" => Ok(Content(ContentType::JavaScript, include_bytes!("../static/scripts/identicon.js"))), - "datatables.js" => Ok(Content(ContentType::JavaScript, include_bytes!("../static/scripts/datatables.js"))), - "datatables.css" => Ok(Content(ContentType::CSS, include_bytes!("../static/scripts/datatables.css"))), + "mail-github.png" => Ok((ContentType::PNG, include_bytes!("../static/images/mail-github.png"))), + "logo-gray.png" => Ok((ContentType::PNG, include_bytes!("../static/images/logo-gray.png"))), + "error-x.svg" => Ok((ContentType::SVG, include_bytes!("../static/images/error-x.svg"))), + "hibp.png" => Ok((ContentType::PNG, include_bytes!("../static/images/hibp.png"))), + "vaultwarden-icon.png" => Ok((ContentType::PNG, include_bytes!("../static/images/vaultwarden-icon.png"))), + "bootstrap.css" => Ok((ContentType::CSS, include_bytes!("../static/scripts/bootstrap.css"))), + "bootstrap-native.js" => Ok((ContentType::JavaScript, include_bytes!("../static/scripts/bootstrap-native.js"))), + "identicon.js" => Ok((ContentType::JavaScript, include_bytes!("../static/scripts/identicon.js"))), + "datatables.js" => Ok((ContentType::JavaScript, include_bytes!("../static/scripts/datatables.js"))), + "datatables.css" => Ok((ContentType::CSS, include_bytes!("../static/scripts/datatables.css"))), "jquery-3.6.0.slim.js" => { - Ok(Content(ContentType::JavaScript, include_bytes!("../static/scripts/jquery-3.6.0.slim.js"))) + Ok((ContentType::JavaScript, include_bytes!("../static/scripts/jquery-3.6.0.slim.js"))) } _ => err!(format!("Static file not found: {}", filename)), } |