about summary refs log tree commit diff
path: root/src/frontend
diff options
context:
space:
mode:
Diffstat (limited to 'src/frontend')
-rw-r--r--src/frontend/mod.rs32
1 files changed, 15 insertions, 17 deletions
diff --git a/src/frontend/mod.rs b/src/frontend/mod.rs
index eefc257..029c5dc 100644
--- a/src/frontend/mod.rs
+++ b/src/frontend/mod.rs
@@ -8,25 +8,24 @@ static POSTS_PER_PAGE: usize = 20;
 
 mod templates {
     use super::IndiewebEndpoints;
-    use chrono;
     use ellipse::Ellipse;
     use http_types::StatusCode;
     use log::error;
 
     /// Return a pretty location specifier from a geo: URI.
     fn decode_geo_uri(uri: &str) -> String {
-        if let Some(part) = uri.split(":").collect::<Vec<_>>().get(1) {
-            if let Some(part) = part.split(";").next() {
-                let mut parts = part.split(",");
+        if let Some(part) = uri.split(':').collect::<Vec<_>>().get(1) {
+            if let Some(part) = part.split(';').next() {
+                let mut parts = part.split(',');
                 let lat = parts.next().unwrap();
                 let lon = parts.next().unwrap();
                 // TODO - format them as proper latitude and longitude
                 return format!("{}, {}", lat, lon);
             } else {
-                return uri.to_string();
+                uri.to_string()
             }
         } else {
-            return uri.to_string();
+            uri.to_string()
         }
     }
 
@@ -379,7 +378,7 @@ mod templates {
                         @markup::raw(post["properties"]["content"][0]["html"].as_str().unwrap().trim())
                     }
                 }
-                @WebInteractions { post: post }
+                @WebInteractions { post }
             }
         }
         PhotoGallery<'a>(photos: Option<&'a Vec<serde_json::Value>>) {
@@ -689,11 +688,11 @@ pub async fn onboarding_receiver<S: Storage>(mut req: Request<ApplicationState<S
     #[cfg(all(debug_assertions, not(test)))]
     let me = url::Url::parse("http://localhost:8080/").unwrap();
 
-    if let Ok(_) = get_post_from_database(backend, me.as_str(), None, &None).await {
-        Err(FrontendError::with_code(
+    if get_post_from_database(backend, me.as_str(), None, &None).await.is_ok() {
+        return Err(FrontendError::with_code(
             StatusCode::Forbidden,
             "Onboarding is over. Are you trying to take over somebody's website?!",
-        ))?
+        ).into())
     }
     info!("Onboarding new user: {}", me);
 
@@ -704,10 +703,10 @@ pub async fn onboarding_receiver<S: Storage>(mut req: Request<ApplicationState<S
         .await?;
 
     if body.user["type"][0] != "h-card" || body.first_post["type"][0] != "h-entry" {
-        Err(FrontendError::with_code(
+        return Err(FrontendError::with_code(
             StatusCode::BadRequest,
             "user and first_post should be h-card and h-entry",
-        ))?
+        ).into())
     }
     info!("Validated body.user and body.first_post as microformats2");
 
@@ -748,8 +747,7 @@ pub async fn coffee<S: Storage>(_: Request<ApplicationState<S>>) -> Result {
     Err(FrontendError::with_code(
         StatusCode::ImATeapot,
         "Someone asked this website to brew them some coffee...",
-    ))?;
-    return Ok(Response::builder(500).build()); // unreachable
+    ).into())
 }
 
 pub async fn mainpage<S: Storage>(req: Request<ApplicationState<S>>) -> Result {
@@ -796,7 +794,7 @@ pub async fn mainpage<S: Storage>(req: Request<ApplicationState<S>>) -> Result {
                 )
                 .build())
         } else {
-            Err(feed_err)?
+            return Err(feed_err.into())
         }
     } else {
         Ok(Response::builder(200)
@@ -850,10 +848,10 @@ pub async fn render_post<S: Storage>(req: Request<ApplicationState<S>>) -> Resul
         "h-entry" => templates::Entry { post: &post }.to_string(),
         "h-card" => templates::VCard { card: &post }.to_string(),
         "h-feed" => templates::Feed { feed: &post }.to_string(),
-        _ => Err(FrontendError::with_code(
+        _ => return Err(FrontendError::with_code(
             StatusCode::InternalServerError,
             "Couldn't render an unknown type",
-        ))?,
+        ).into()),
     };
 
     Ok(Response::builder(200)