server/image-hash: fix handling invalid input

This commit is contained in:
rr- 2016-12-26 19:03:04 +01:00
parent e8636a7775
commit f301ca9a8a
2 changed files with 15 additions and 9 deletions

1
API.md
View file

@ -1074,6 +1074,7 @@ data.
- **Errors** - **Errors**
- input file is not an image
- privileges are too low - privileges are too low
- **Description** - **Description**

View file

@ -1,7 +1,7 @@
import elasticsearch import elasticsearch
import elasticsearch_dsl import elasticsearch_dsl
from image_match.elasticsearch_driver import SignatureES from image_match.elasticsearch_driver import SignatureES
from szurubooru import config from szurubooru import config, errors
# pylint: disable=invalid-name # pylint: disable=invalid-name
@ -31,6 +31,7 @@ def delete_image(path):
def search_by_image(image_content): def search_by_image(image_content):
try:
for result in session.search_image( for result in session.search_image(
path=image_content, # sic path=image_content, # sic
bytestream=True): bytestream=True):
@ -39,6 +40,10 @@ def search_by_image(image_content):
'dist': result['dist'], 'dist': result['dist'],
'path': result['path'], 'path': result['path'],
} }
except elasticsearch.exceptions.ElasticsearchException as ex:
raise
except Exception as ex:
raise errors.SearchError('Error searching (invalid input?)')
def purge(): def purge():