From 63c1c7ea707c4cb1397ab73788bdba4c9c7b554f Mon Sep 17 00:00:00 2001 From: sevenc-nanashi Date: Sat, 18 Nov 2023 17:09:39 +0900 Subject: [PATCH] =?UTF-8?q?Fix:=20=E8=BE=9E=E6=9B=B8=E7=99=BB=E9=8C=B2?= =?UTF-8?q?=E3=81=A7=E3=81=8D=E3=81=AA=E3=81=84=E3=81=AE=E3=82=92=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/error.rs | 12 ++++++++---- src/routes/user_dict.rs | 10 +++++++++- src/voicevox/user_dict/word.rs | 2 +- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/error.rs b/src/error.rs index 0ae1f6c..3412e51 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,4 +1,5 @@ use axum::{ + http::StatusCode, response::{IntoResponse, Response}, Json, }; @@ -52,9 +53,12 @@ pub struct ErrorResponse { impl IntoResponse for Error { fn into_response(self) -> Response { - Json(&ErrorResponse { - error: self.to_string(), - }) - .into_response() + ( + StatusCode::INTERNAL_SERVER_ERROR, + Json(&ErrorResponse { + error: self.to_string(), + }), + ) + .into_response() } } diff --git a/src/routes/user_dict.rs b/src/routes/user_dict.rs index e5d5f32..02cb92a 100644 --- a/src/routes/user_dict.rs +++ b/src/routes/user_dict.rs @@ -23,6 +23,8 @@ static USER_DICT: Lazy>> = Lazy::new(|| { static USER_DICT_PATH: Lazy = Lazy::new(|| { process_path::get_executable_path() + .unwrap() + .parent() .unwrap() .join("user_dict.json") .to_str() @@ -125,11 +127,15 @@ pub async fn import_user_dict(Json(payload): Json = + payload.into_iter().map(|(k, v)| (k, v.into())).collect(); + serde_json::to_writer(temp_file_writer, &converted) .map_err(|e| Error::DictionaryOperationFailed(e.into()))?; let temp_file = temp_file.into_temp_path(); + tracing::debug!("Importing user dict from {:?}", temp_file); + user_dict .load(temp_file.to_str().unwrap()) .map_err(|e| Error::DictionaryOperationFailed(e.into()))?; @@ -194,6 +200,8 @@ pub async fn put_user_dict_word( ) -> Result<()> { let mut user_dict = USER_DICT.lock().await; + dbg!(&word_uuid); + let word_uuid = uuid::Uuid::parse_str(&word_uuid) .map_err(|e| Error::DictionaryOperationFailed(e.into()))?; diff --git a/src/voicevox/user_dict/word.rs b/src/voicevox/user_dict/word.rs index 8ea8187..fa9875c 100644 --- a/src/voicevox/user_dict/word.rs +++ b/src/voicevox/user_dict/word.rs @@ -212,7 +212,7 @@ impl UserDictWord { pub fn to_mecab_format(&self) -> String { let pos = PART_OF_SPEECH_DETAIL.get(&self.word_type).unwrap(); format!( - "{},{},{},{},{},{},{},{},{},{},{},{},{},{}/{},{}\n", + "{},{},{},{},{},{},{},{},{},{},{},{},{},{}/{},{}", self.surface, pos.context_id, pos.context_id,