Update server.py
Browse files
server.py
CHANGED
|
@@ -405,9 +405,19 @@ def image_to_base64(image: Image, quality: int = 75) -> str:
|
|
| 405 |
image.save(buffer, format="JPEG", quality=quality)
|
| 406 |
img_str = base64.b64encode(buffer.getvalue()).decode("utf-8")
|
| 407 |
return img_str
|
|
|
|
|
|
|
| 408 |
|
| 409 |
api_key = os.environ.get("password")
|
| 410 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 411 |
@app.before_request
|
| 412 |
def before_request():
|
| 413 |
# Request time measuring
|
|
@@ -416,14 +426,14 @@ def before_request():
|
|
| 416 |
# Checks if an API key is present and valid, otherwise return unauthorized
|
| 417 |
# The options check is required so CORS doesn't get angry
|
| 418 |
try:
|
| 419 |
-
if request.method != 'OPTIONS' and request.authorization
|
| 420 |
print(f"WARNING: Unauthorized API key access from {request.remote_addr}")
|
| 421 |
response = jsonify({ 'error': '401: Invalid API key' })
|
| 422 |
response.status_code = 401
|
| 423 |
return response
|
| 424 |
except Exception as e:
|
| 425 |
print(f"API key check error: {e}")
|
| 426 |
-
return "
|
| 427 |
|
| 428 |
|
| 429 |
@app.after_request
|
|
@@ -840,5 +850,5 @@ def chromadb_import():
|
|
| 840 |
|
| 841 |
return jsonify({"count": len(ids)})
|
| 842 |
|
| 843 |
-
|
| 844 |
app.run(host=host, port=port)
|
|
|
|
| 405 |
image.save(buffer, format="JPEG", quality=quality)
|
| 406 |
img_str = base64.b64encode(buffer.getvalue()).decode("utf-8")
|
| 407 |
return img_str
|
| 408 |
+
|
| 409 |
+
ignore_auth = []
|
| 410 |
|
| 411 |
api_key = os.environ.get("password")
|
| 412 |
|
| 413 |
+
def is_authorize_ignored(request):
|
| 414 |
+
view_func = app.view_functions.get(request.endpoint)
|
| 415 |
+
|
| 416 |
+
if view_func is not None:
|
| 417 |
+
if view_func in ignore_auth:
|
| 418 |
+
return True
|
| 419 |
+
return False
|
| 420 |
+
|
| 421 |
@app.before_request
|
| 422 |
def before_request():
|
| 423 |
# Request time measuring
|
|
|
|
| 426 |
# Checks if an API key is present and valid, otherwise return unauthorized
|
| 427 |
# The options check is required so CORS doesn't get angry
|
| 428 |
try:
|
| 429 |
+
if request.method != 'OPTIONS' and is_authorize_ignored(request) == False and getattr(request.authorization, 'token', '') != api_key:
|
| 430 |
print(f"WARNING: Unauthorized API key access from {request.remote_addr}")
|
| 431 |
response = jsonify({ 'error': '401: Invalid API key' })
|
| 432 |
response.status_code = 401
|
| 433 |
return response
|
| 434 |
except Exception as e:
|
| 435 |
print(f"API key check error: {e}")
|
| 436 |
+
return "this space is only for doctord98 you can duplicate and make your own".format(e),
|
| 437 |
|
| 438 |
|
| 439 |
@app.after_request
|
|
|
|
| 850 |
|
| 851 |
return jsonify({"count": len(ids)})
|
| 852 |
|
| 853 |
+
ignore_auth.append(tts_play_sample)
|
| 854 |
app.run(host=host, port=port)
|