]> git.puffer.fish Git - matthieu/gru.git/commitdiff
secure the api calling for the phonemizer service
authorMatthieu Pignolet <m@mpgn.dev>
Thu, 30 Jan 2025 15:23:03 +0000 (19:23 +0400)
committerMatthieu Pignolet <m@mpgn.dev>
Thu, 30 Jan 2025 15:23:03 +0000 (19:23 +0400)
autofeur_db/src/bin/generate.rs
autofeur_db/src/inference.rs
autofeur_db/src/trie.rs

index 7f85f419bd92b0edf152aa2cefcb648945904d46..f4996c6b0d44c3b3b2e283418d39e3195399173d 100644 (file)
@@ -4,7 +4,6 @@ use autofeur::save::Save;
 use kdam::tqdm;
 
 #[tokio::main]
-/// Generates the DB file foe easy usage.
 async fn main() {
     let mut save = Save::default();
 
index f681cd06a0287dc6617b44f2df8cdf7325921fad..f54d15e6ef1ca24ed3ae1816fe430afec6276624 100644 (file)
@@ -1,4 +1,7 @@
-use std::{env, ops::Add};
+use std::{
+    env::{self, VarError},
+    ops::Add,
+};
 
 use anyhow::anyhow;
 use hypher::hyphenate;
@@ -7,14 +10,13 @@ use itertools::Itertools;
 use crate::save::Save;
 
 async fn call_inference_service(word: &str) -> anyhow::Result<String> {
-    let server: Result<String, anyhow::Error> =
-        env::var("PHONEMIZER").or_else(|_| Ok("http://localhost:8000/".to_string()));
-    Ok(
-        reqwest::get(format!("{}?grapheme={}", server.unwrap(), word))
-            .await?
-            .text()
-            .await?,
-    )
+    let server: String = env::var("PHONEMIZER")
+        .or_else(|_| Ok::<String, VarError>("http://localhost:8000/".to_string()))
+        .unwrap();
+
+    let url = reqwest::Url::parse_with_params(&server, &[("grapheme", word)])?;
+
+    Ok(reqwest::get(url).await?.text().await?)
 }
 
 impl Save<'_> {
@@ -77,7 +79,7 @@ impl Save<'_> {
         }
 
         // we finally just need to compute the end of the word which matches the sound
-        let found = completed_syllabes.drain(i+1..).join("");
+        let found = completed_syllabes.drain(i + 1..).join("");
         println!("{} is equivalent to {}", completion, found);
 
         Ok(format!("{} ({})", found, word))
index fbd392ac43c1e94c50ea0f6248dbb9397214f601..171a170899640507b3d45836bc6bcab3ea671674 100644 (file)
@@ -13,7 +13,6 @@ pub struct TrieNode<'a> {
 }
 
 impl<'a> TrieNode<'a> {
-    // Create new node
     pub fn new<'b>(is_final: bool) -> TrieNode<'b> {
         TrieNode {
             is_final,