Skip to content

Commit 63c1c7e

Browse files
Fix: 辞書登録できないのを修正
1 parent 42f67d1 commit 63c1c7e

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

src/error.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use axum::{
2+
http::StatusCode,
23
response::{IntoResponse, Response},
34
Json,
45
};
@@ -52,9 +53,12 @@ pub struct ErrorResponse {
5253

5354
impl IntoResponse for Error {
5455
fn into_response(self) -> Response {
55-
Json(&ErrorResponse {
56-
error: self.to_string(),
57-
})
58-
.into_response()
56+
(
57+
StatusCode::INTERNAL_SERVER_ERROR,
58+
Json(&ErrorResponse {
59+
error: self.to_string(),
60+
}),
61+
)
62+
.into_response()
5963
}
6064
}

src/routes/user_dict.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ static USER_DICT: Lazy<Arc<Mutex<UserDict>>> = Lazy::new(|| {
2323

2424
static USER_DICT_PATH: Lazy<String> = Lazy::new(|| {
2525
process_path::get_executable_path()
26+
.unwrap()
27+
.parent()
2628
.unwrap()
2729
.join("user_dict.json")
2830
.to_str()
@@ -125,11 +127,15 @@ pub async fn import_user_dict(Json(payload): Json<HashMap<String, VvUserDictWord
125127

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

128-
serde_json::to_writer(temp_file_writer, &payload)
130+
let converted: HashMap<String, UserDictWord> =
131+
payload.into_iter().map(|(k, v)| (k, v.into())).collect();
132+
serde_json::to_writer(temp_file_writer, &converted)
129133
.map_err(|e| Error::DictionaryOperationFailed(e.into()))?;
130134

131135
let temp_file = temp_file.into_temp_path();
132136

137+
tracing::debug!("Importing user dict from {:?}", temp_file);
138+
133139
user_dict
134140
.load(temp_file.to_str().unwrap())
135141
.map_err(|e| Error::DictionaryOperationFailed(e.into()))?;
@@ -194,6 +200,8 @@ pub async fn put_user_dict_word(
194200
) -> Result<()> {
195201
let mut user_dict = USER_DICT.lock().await;
196202

203+
dbg!(&word_uuid);
204+
197205
let word_uuid = uuid::Uuid::parse_str(&word_uuid)
198206
.map_err(|e| Error::DictionaryOperationFailed(e.into()))?;
199207

src/voicevox/user_dict/word.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ impl UserDictWord {
212212
pub fn to_mecab_format(&self) -> String {
213213
let pos = PART_OF_SPEECH_DETAIL.get(&self.word_type).unwrap();
214214
format!(
215-
"{},{},{},{},{},{},{},{},{},{},{},{},{},{}/{},{}\n",
215+
"{},{},{},{},{},{},{},{},{},{},{},{},{},{}/{},{}",
216216
self.surface,
217217
pos.context_id,
218218
pos.context_id,

0 commit comments

Comments
 (0)