about summary refs log tree commit diff
path: root/web/atward/src/main.rs
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@tvl.su>2024-08-23T09·33+0300
committertazjin <tazjin@tvl.su>2024-08-23T11·07+0000
commit8041ce7cbd49aeddf7583001d7fd6a498db3380f (patch)
tree02a97fe4d41fa52df88ecea415bf0b62393e43d8 /web/atward/src/main.rs
parent8f6f45097e36c2cd571ce1b858fdb471697dd7e5 (diff)
chore(web/atward): remove sourcegraph support r/8552
We're moving away from sourcegraph to livegrep and so on, as Sourcegraph has
gone fully proprietary.

This removes support for redirecting to Sourcegraph.

Relates to b/290

Change-Id: I04ccf8dfef72113cd49d444151cb0c3eb834845d
Reviewed-on: https://cl.tvl.fyi/c/depot/+/12268
Reviewed-by: Profpatsch <mail@profpatsch.de>
Tested-by: BuildkiteCI
Diffstat (limited to 'web/atward/src/main.rs')
-rw-r--r--web/atward/src/main.rs48
1 files changed, 4 insertions, 44 deletions
diff --git a/web/atward/src/main.rs b/web/atward/src/main.rs
index eb2603a226c6..13aeff0e27d8 100644
--- a/web/atward/src/main.rs
+++ b/web/atward/src/main.rs
@@ -5,7 +5,6 @@
 //! browsers and attempts to send users to useful locations based on
 //! their search query (falling back to another search engine).
 use regex::Regex;
-use rouille::input::cookies;
 use rouille::{Request, Response};
 
 #[cfg(test)]
@@ -31,43 +30,14 @@ struct Handler {
 struct Query {
     /// Query string itself.
     query: String,
-
-    /// Should Sourcegraph be used instead of cgit?
-    cs: bool,
-}
-
-/// Helper function for setting a parameter based on a query
-/// parameter.
-fn query_setting(req: &Request, config: &mut bool, param: &str) {
-    match req.get_param(param) {
-        Some(s) if s == "true" => *config = true,
-        Some(s) if s == "false" => *config = false,
-        _ => {}
-    }
 }
 
 impl Query {
     fn from_request(req: &Request) -> Option<Query> {
-        // First extract the actual search query ...
-        let mut query = match req.get_param("q") {
-            Some(query) => Query { query, cs: false },
+        match req.get_param("q") {
+            Some(query) => Some(Query { query }),
             None => return None,
-        };
-
-        // ... then apply settings to it. Settings in query parameters
-        // take precedence over cookies.
-        for cookie in cookies(req) {
-            match cookie {
-                ("cs", "true") => {
-                    query.cs = true;
-                }
-                _ => {}
-            }
         }
-
-        query_setting(req, &mut query.cs, "cs");
-
-        Some(query)
     }
 }
 
@@ -76,7 +46,6 @@ impl From<&str> for Query {
     fn from(query: &str) -> Query {
         Query {
             query: query.to_string(),
-            cs: false,
         }
     }
 }
@@ -90,10 +59,6 @@ fn cgit_url(path: &str) -> String {
     }
 }
 
-/// Create a URL to a path in Sourcegraph.
-fn sourcegraph_path_url(path: &str) -> String {
-    format!("https://cs.tvl.fyi/depot/-/tree/{}", path)
-}
 /// Definition of all supported query handlers in atward.
 fn handlers() -> Vec<Handler> {
     vec![
@@ -126,16 +91,11 @@ fn handlers() -> Vec<Handler> {
         // TODO(tazjin): Add support for specifying lines in a query parameter
         Handler {
             pattern: Regex::new("^//(?P<path>[a-zA-Z].*)?$").unwrap(),
-            target: |query, captures| {
+            target: |_, captures| {
                 // Pass an empty string if the path is missing, to
                 // redirect to the depot root.
                 let path = captures.name("path").map(|m| m.as_str()).unwrap_or("");
-
-                if query.cs {
-                    Some(sourcegraph_path_url(path))
-                } else {
-                    Some(cgit_url(path))
-                }
+                Some(cgit_url(path))
             },
         },
     ]