Skip to content

📄 Awesome OCR multiple programing languages toolkits based on ONNX Runtime, OpenVINO, MNN, PaddlePaddle, TensorRT and PyTorch.

修正token验证实现

AutumnSun199636c508095673
diff --git a/ocrweb_multi/config.yaml b/ocrweb_multi/config.yaml
index 363c4ed..e092823 100644
--- a/ocrweb_multi/config.yaml
+++ b/ocrweb_multi/config.yaml
@@ -1,8 +1,7 @@
-debug: '1'
-
server:
host: 127.0.0.1
port: 9003
+ # OCR接口Token, 为null时将跳过Token验证
token: null
global:
diff --git a/ocrweb_multi/main.py b/ocrweb_multi/main.py
index a5c7511..694572e 100644
--- a/ocrweb_multi/main.py
+++ b/ocrweb_multi/main.py
@@ -23,8 +23,8 @@ def index():
return send_file('static/index.html')
-def json_response(data, *args):
- return make_response(tojson(data), {"content-type": 'application/json'}, *args)
+def json_response(data, status=200):
+ return make_response(tojson(data), status, {"content-type": 'application/json'})
@app.route('/lang')
@@ -43,7 +43,7 @@ def ocr():
"""执行文字识别"""
if conf['server'].get('token'):
if request.values.get('token') != conf['server']['token']:
- return json_response({'msg': 'invalid token'}, 403)
+ return json_response({'msg': 'invalid token'}, status=403)
lang = request.values.get('lang') or 'ch'
detect = parse_bool(request.values.get('detect') or 'true')
diff --git a/ocrweb_multi/static/index.html b/ocrweb_multi/static/index.html
index 1c4aedd..534485a 100644
--- a/ocrweb_multi/static/index.html
+++ b/ocrweb_multi/static/index.html
@@ -156,6 +156,8 @@
reader.readAsDataURL(targetFile);
var formdata = new FormData();
+ var token = location.hash.slice(1);
+ formdata.set('token', token);
formdata.set('image', targetFile);
formdata.set('lang', $('input[name=lang]:checked').val());
@@ -172,11 +174,12 @@
},
error: function (evt) {
console.log(evt);
- alert('检测失败: ' + evt);
+ alert('检测失败: ' + evt.status + ', ' + evt.statusText);
},
success: function (resp) {
$("#wrapper").hide();
if (resp.msg !== 'OK') {
+ console.log(resp);
alert('检测失败: ', resp.msg);
return;
}