KevinHuSh
commited on
Commit
·
2aafb30
1
Parent(s):
4a90706
fix file encoding detection bug (#653)
Browse files### What problem does this PR solve?
#651
### Type of change
- [x] Bug Fix (non-breaking change which fixes an issue)
- api/apps/file_app.py +1 -1
- rag/nlp/__init__.py +6 -0
api/apps/file_app.py
CHANGED
|
@@ -335,7 +335,7 @@ def get(file_id):
|
|
| 335 |
response = flask.make_response(MINIO.get(file.parent_id, file.location))
|
| 336 |
ext = re.search(r"\.([^.]+)$", file.name)
|
| 337 |
if ext:
|
| 338 |
-
if
|
| 339 |
response.headers.set('Content-Type', 'image/%s' % ext.group(1))
|
| 340 |
else:
|
| 341 |
response.headers.set(
|
|
|
|
| 335 |
response = flask.make_response(MINIO.get(file.parent_id, file.location))
|
| 336 |
ext = re.search(r"\.([^.]+)$", file.name)
|
| 337 |
if ext:
|
| 338 |
+
if file.type == FileType.VISUAL.value:
|
| 339 |
response.headers.set('Content-Type', 'image/%s' % ext.group(1))
|
| 340 |
else:
|
| 341 |
response.headers.set(
|
rag/nlp/__init__.py
CHANGED
|
@@ -28,11 +28,17 @@ all_codecs = [
|
|
| 28 |
def find_codec(blob):
|
| 29 |
global all_codecs
|
| 30 |
for c in all_codecs:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
try:
|
| 32 |
blob.decode(c)
|
| 33 |
return c
|
| 34 |
except Exception as e:
|
| 35 |
pass
|
|
|
|
| 36 |
return "utf-8"
|
| 37 |
|
| 38 |
|
|
|
|
| 28 |
def find_codec(blob):
|
| 29 |
global all_codecs
|
| 30 |
for c in all_codecs:
|
| 31 |
+
try:
|
| 32 |
+
blob[:1024].decode(c)
|
| 33 |
+
return c
|
| 34 |
+
except Exception as e:
|
| 35 |
+
pass
|
| 36 |
try:
|
| 37 |
blob.decode(c)
|
| 38 |
return c
|
| 39 |
except Exception as e:
|
| 40 |
pass
|
| 41 |
+
|
| 42 |
return "utf-8"
|
| 43 |
|
| 44 |
|