summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthieu Pignolet <m@mpgn.dev>2025-01-30 19:23:03 +0400
committerMatthieu Pignolet <m@mpgn.dev>2025-01-30 19:23:03 +0400
commitf14f90c141a742f32cb50372aaf2cd73c546e8af (patch)
treede3792c2d7679259d1dde931d2ab9062a36987a0
parent3ba26023d0d8b2b033a02a731cb5985923ee73e7 (diff)
secure the api calling for the phonemizer service
-rw-r--r--autofeur_db/src/bin/generate.rs1
-rw-r--r--autofeur_db/src/inference.rs22
-rw-r--r--autofeur_db/src/trie.rs1
3 files changed, 12 insertions, 12 deletions
diff --git a/autofeur_db/src/bin/generate.rs b/autofeur_db/src/bin/generate.rs
index 7f85f41..f4996c6 100644
--- a/autofeur_db/src/bin/generate.rs
+++ b/autofeur_db/src/bin/generate.rs
@@ -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();
diff --git a/autofeur_db/src/inference.rs b/autofeur_db/src/inference.rs
index f681cd0..f54d15e 100644
--- a/autofeur_db/src/inference.rs
+++ b/autofeur_db/src/inference.rs
@@ -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))
diff --git a/autofeur_db/src/trie.rs b/autofeur_db/src/trie.rs
index fbd392a..171a170 100644
--- a/autofeur_db/src/trie.rs
+++ b/autofeur_db/src/trie.rs
@@ -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,