Update app.py
This commit is contained in:
22
app.py
22
app.py
@@ -22,7 +22,6 @@ import shutil
|
|||||||
from flask_limiter import Limiter
|
from flask_limiter import Limiter
|
||||||
|
|
||||||
import flask
|
import flask
|
||||||
import nkf
|
|
||||||
import tjaf
|
import tjaf
|
||||||
|
|
||||||
# ----
|
# ----
|
||||||
@@ -812,8 +811,25 @@ def upload_file():
|
|||||||
return flask.jsonify({'error': 'ファイルが選択されていません'})
|
return flask.jsonify({'error': 'ファイルが選択されていません'})
|
||||||
|
|
||||||
# TJAファイルをテキストUTF-8/LFに変換
|
# TJAファイルをテキストUTF-8/LFに変換
|
||||||
tja_data = nkf.nkf('-wd', file_tja.read())
|
tja_data = file_tja.read()
|
||||||
tja_text = tja_data.decode("utf-8")
|
# 尝试检测编码并转换为UTF-8
|
||||||
|
try:
|
||||||
|
# 首先尝试UTF-8解码
|
||||||
|
tja_text = tja_data.decode("utf-8")
|
||||||
|
except UnicodeDecodeError:
|
||||||
|
# 如果UTF-8失败,尝试其他常见编码
|
||||||
|
for encoding in ['shift_jis', 'euc-jp', 'iso-2022-jp', 'cp932']:
|
||||||
|
try:
|
||||||
|
tja_text = tja_data.decode(encoding)
|
||||||
|
break
|
||||||
|
except UnicodeDecodeError:
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
# 如果所有编码都失败,使用错误处理
|
||||||
|
tja_text = tja_data.decode("utf-8", errors="replace")
|
||||||
|
|
||||||
|
# 删除回车符(CR),只保留换行符(LF)
|
||||||
|
tja_text = tja_text.replace('\r', '')
|
||||||
print("TJAのサイズ:",len(tja_text))
|
print("TJAのサイズ:",len(tja_text))
|
||||||
# TJAファイルの内容を解析
|
# TJAファイルの内容を解析
|
||||||
tja = tjaf.Tja(tja_text)
|
tja = tjaf.Tja(tja_text)
|
||||||
|
|||||||
Reference in New Issue
Block a user