跨域
Browse files- main_v6.py +10 -14
- run_https.ps1 +0 -3
main_v6.py
CHANGED
|
@@ -87,18 +87,11 @@ def _parse_csv_env(name: str, default: str):
|
|
| 87 |
_cors_allowed_origins = set(_parse_csv_env("PPV5_CORS_ALLOWED_ORIGINS", "https://typst-app-clone.pages.dev"))
|
| 88 |
|
| 89 |
def _add_cors_headers(resp):
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
req_headers = request.headers.get("Access-Control-Request-Headers")
|
| 96 |
-
resp.headers["Access-Control-Allow-Headers"] = req_headers or "Content-Type"
|
| 97 |
-
resp.headers["Access-Control-Max-Age"] = "86400"
|
| 98 |
-
|
| 99 |
-
if request.headers.get("Access-Control-Request-Private-Network") == "true":
|
| 100 |
-
resp.headers["Access-Control-Allow-Private-Network"] = "true"
|
| 101 |
-
|
| 102 |
return resp
|
| 103 |
|
| 104 |
@app.before_request
|
|
@@ -274,8 +267,8 @@ ch, chinese_cht, en, japan, af, az, bs, ca, cs, cy, da, de, es, et, eu, fi, fr,
|
|
| 274 |
|
| 275 |
# 限制同时处理的请求数量为1
|
| 276 |
ocr_semaphore = threading.Semaphore(1)
|
| 277 |
-
@app.route('/ppocrv6', methods=['
|
| 278 |
-
@app.route('/ocr', methods=['
|
| 279 |
def ppv6():
|
| 280 |
# request.json 只能够接受方法为POST、Body为raw,header 内容为 application/json类型的数据
|
| 281 |
# print(request.json, type(request.json))
|
|
@@ -289,6 +282,9 @@ def ppv6():
|
|
| 289 |
|
| 290 |
# base64_str = form_data["img"]
|
| 291 |
|
|
|
|
|
|
|
|
|
|
| 292 |
# 非阻塞方式获取信号量
|
| 293 |
if not ocr_semaphore.acquire(blocking=False):
|
| 294 |
return jsonify({"warning": "wait pre task done."})
|
|
|
|
| 87 |
_cors_allowed_origins = set(_parse_csv_env("PPV5_CORS_ALLOWED_ORIGINS", "https://typst-app-clone.pages.dev"))
|
| 88 |
|
| 89 |
def _add_cors_headers(resp):
|
| 90 |
+
resp.headers["Access-Control-Allow-Origin"] = "*"
|
| 91 |
+
resp.headers["Access-Control-Allow-Methods"] = "POST, OPTIONS"
|
| 92 |
+
resp.headers["Access-Control-Allow-Headers"] = "Content-Type"
|
| 93 |
+
resp.headers["Access-Control-Allow-Private-Network"] = "true"
|
| 94 |
+
resp.headers["Access-Control-Max-Age"] = "86400"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
return resp
|
| 96 |
|
| 97 |
@app.before_request
|
|
|
|
| 267 |
|
| 268 |
# 限制同时处理的请求数量为1
|
| 269 |
ocr_semaphore = threading.Semaphore(1)
|
| 270 |
+
@app.route('/ppocrv6', methods=['POST', 'OPTIONS'])
|
| 271 |
+
@app.route('/ocr', methods=['POST', 'OPTIONS'])
|
| 272 |
def ppv6():
|
| 273 |
# request.json 只能够接受方法为POST、Body为raw,header 内容为 application/json类型的数据
|
| 274 |
# print(request.json, type(request.json))
|
|
|
|
| 282 |
|
| 283 |
# base64_str = form_data["img"]
|
| 284 |
|
| 285 |
+
if request.method == "OPTIONS":
|
| 286 |
+
return _add_cors_headers(app.make_response(("", 204)))
|
| 287 |
+
|
| 288 |
# 非阻塞方式获取信号量
|
| 289 |
if not ocr_semaphore.acquire(blocking=False):
|
| 290 |
return jsonify({"warning": "wait pre task done."})
|
run_https.ps1
CHANGED
|
@@ -53,9 +53,6 @@ $env:PPV5_HOST = "127.0.0.1"
|
|
| 53 |
$env:PPV5_PORT = "9346"
|
| 54 |
$env:PPV5_TLS_CERT = $certFile
|
| 55 |
$env:PPV5_TLS_KEY = $keyFile
|
| 56 |
-
if (-not $env:PPV5_CORS_ALLOWED_ORIGINS) {
|
| 57 |
-
$env:PPV5_CORS_ALLOWED_ORIGINS = "https://typst-app-clone.pages.dev"
|
| 58 |
-
}
|
| 59 |
|
| 60 |
Set-Location $root
|
| 61 |
& $pythonPath (Join-Path $root "main_v6.py")
|
|
|
|
| 53 |
$env:PPV5_PORT = "9346"
|
| 54 |
$env:PPV5_TLS_CERT = $certFile
|
| 55 |
$env:PPV5_TLS_KEY = $keyFile
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
Set-Location $root
|
| 58 |
& $pythonPath (Join-Path $root "main_v6.py")
|