Skip to content

Commit

Permalink
Fix: 辞書登録できないのを修正
Browse files Browse the repository at this point in the history
  • Loading branch information
sevenc-nanashi committed Nov 18, 2023
1 parent 42f67d1 commit 63c1c7e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
12 changes: 8 additions & 4 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use axum::{
http::StatusCode,
response::{IntoResponse, Response},
Json,
};
Expand Down Expand Up @@ -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()
}
}
10 changes: 9 additions & 1 deletion src/routes/user_dict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ static USER_DICT: Lazy<Arc<Mutex<UserDict>>> = Lazy::new(|| {

static USER_DICT_PATH: Lazy<String> = Lazy::new(|| {
process_path::get_executable_path()
.unwrap()
.parent()
.unwrap()
.join("user_dict.json")
.to_str()
Expand Down Expand Up @@ -125,11 +127,15 @@ pub async fn import_user_dict(Json(payload): Json<HashMap<String, VvUserDictWord

let temp_file_writer = std::io::BufWriter::new(temp_file.as_file());

serde_json::to_writer(temp_file_writer, &payload)
let converted: HashMap<String, UserDictWord> =
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()))?;
Expand Down Expand Up @@ -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()))?;

Expand Down
2 changes: 1 addition & 1 deletion src/voicevox/user_dict/word.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 63c1c7e

Please sign in to comment.