forked from open-webui/open-webui
chore: 🎨 format backend
This commit is contained in:
parent
8480a9b418
commit
05fade1426
3 changed files with 26 additions and 21 deletions
|
@ -30,7 +30,8 @@ async def get_ollama_api_url(user=Depends(get_current_user)):
|
||||||
if user and user.role == "admin":
|
if user and user.role == "admin":
|
||||||
return {"OLLAMA_API_BASE_URL": app.state.OLLAMA_API_BASE_URL}
|
return {"OLLAMA_API_BASE_URL": app.state.OLLAMA_API_BASE_URL}
|
||||||
else:
|
else:
|
||||||
raise HTTPException(status_code=401, detail=ERROR_MESSAGES.ACCESS_PROHIBITED)
|
raise HTTPException(status_code=401,
|
||||||
|
detail=ERROR_MESSAGES.ACCESS_PROHIBITED)
|
||||||
|
|
||||||
|
|
||||||
class UrlUpdateForm(BaseModel):
|
class UrlUpdateForm(BaseModel):
|
||||||
|
@ -38,14 +39,14 @@ class UrlUpdateForm(BaseModel):
|
||||||
|
|
||||||
|
|
||||||
@app.post("/url/update")
|
@app.post("/url/update")
|
||||||
async def update_ollama_api_url(
|
async def update_ollama_api_url(form_data: UrlUpdateForm,
|
||||||
form_data: UrlUpdateForm, user=Depends(get_current_user)
|
user=Depends(get_current_user)):
|
||||||
):
|
|
||||||
if user and user.role == "admin":
|
if user and user.role == "admin":
|
||||||
app.state.OLLAMA_API_BASE_URL = form_data.url
|
app.state.OLLAMA_API_BASE_URL = form_data.url
|
||||||
return {"OLLAMA_API_BASE_URL": app.state.OLLAMA_API_BASE_URL}
|
return {"OLLAMA_API_BASE_URL": app.state.OLLAMA_API_BASE_URL}
|
||||||
else:
|
else:
|
||||||
raise HTTPException(status_code=401, detail=ERROR_MESSAGES.ACCESS_PROHIBITED)
|
raise HTTPException(status_code=401,
|
||||||
|
detail=ERROR_MESSAGES.ACCESS_PROHIBITED)
|
||||||
|
|
||||||
|
|
||||||
@app.api_route("/{path:path}", methods=["GET", "POST", "PUT", "DELETE"])
|
@app.api_route("/{path:path}", methods=["GET", "POST", "PUT", "DELETE"])
|
||||||
|
@ -58,11 +59,11 @@ async def proxy(path: str, request: Request, user=Depends(get_current_user)):
|
||||||
if user.role in ["user", "admin"]:
|
if user.role in ["user", "admin"]:
|
||||||
if path in ["pull", "delete", "push", "copy", "create"]:
|
if path in ["pull", "delete", "push", "copy", "create"]:
|
||||||
if user.role != "admin":
|
if user.role != "admin":
|
||||||
raise HTTPException(
|
raise HTTPException(status_code=401,
|
||||||
status_code=401, detail=ERROR_MESSAGES.ACCESS_PROHIBITED
|
detail=ERROR_MESSAGES.ACCESS_PROHIBITED)
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
raise HTTPException(status_code=401, detail=ERROR_MESSAGES.ACCESS_PROHIBITED)
|
raise HTTPException(status_code=401,
|
||||||
|
detail=ERROR_MESSAGES.ACCESS_PROHIBITED)
|
||||||
|
|
||||||
headers.pop("Host", None)
|
headers.pop("Host", None)
|
||||||
headers.pop("Authorization", None)
|
headers.pop("Authorization", None)
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
from flask import Flask, request, Response, jsonify
|
from flask import Flask, request, Response, jsonify
|
||||||
from flask_cors import CORS
|
from flask_cors import CORS
|
||||||
|
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
|
||||||
from apps.web.models.users import Users
|
from apps.web.models.users import Users
|
||||||
from constants import ERROR_MESSAGES
|
from constants import ERROR_MESSAGES
|
||||||
from utils.utils import decode_token
|
from utils.utils import decode_token
|
||||||
|
@ -77,7 +75,9 @@ def update_ollama_api_url():
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@app.route("/", defaults={"path": ""}, methods=["GET", "POST", "PUT", "DELETE"])
|
@app.route("/",
|
||||||
|
defaults={"path": ""},
|
||||||
|
methods=["GET", "POST", "PUT", "DELETE"])
|
||||||
@app.route("/<path:path>", methods=["GET", "POST", "PUT", "DELETE"])
|
@app.route("/<path:path>", methods=["GET", "POST", "PUT", "DELETE"])
|
||||||
def proxy(path):
|
def proxy(path):
|
||||||
# Combine the base URL of the target server with the requested path
|
# Combine the base URL of the target server with the requested path
|
||||||
|
@ -106,13 +106,17 @@ def proxy(path):
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
return (
|
return (
|
||||||
jsonify({"detail": ERROR_MESSAGES.ACCESS_PROHIBITED}),
|
jsonify({
|
||||||
|
"detail":
|
||||||
|
ERROR_MESSAGES.ACCESS_PROHIBITED
|
||||||
|
}),
|
||||||
401,
|
401,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
return jsonify({"detail": ERROR_MESSAGES.ACCESS_PROHIBITED}), 401
|
return jsonify(
|
||||||
|
{"detail": ERROR_MESSAGES.ACCESS_PROHIBITED}), 401
|
||||||
else:
|
else:
|
||||||
return jsonify({"detail": ERROR_MESSAGES.UNAUTHORIZED}), 401
|
return jsonify({"detail": ERROR_MESSAGES.UNAUTHORIZED}), 401
|
||||||
else:
|
else:
|
||||||
|
@ -162,12 +166,10 @@ def proxy(path):
|
||||||
print(res)
|
print(res)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
jsonify(
|
jsonify({
|
||||||
{
|
|
||||||
"detail": error_detail,
|
"detail": error_detail,
|
||||||
"message": str(e),
|
"message": str(e),
|
||||||
}
|
}),
|
||||||
),
|
|
||||||
400,
|
400,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -50,4 +50,6 @@ app.mount("/api/v1", webui_app)
|
||||||
# app.mount("/ollama/api", WSGIMiddleware(ollama_app))
|
# app.mount("/ollama/api", WSGIMiddleware(ollama_app))
|
||||||
app.mount("/ollama/api", ollama_app)
|
app.mount("/ollama/api", ollama_app)
|
||||||
|
|
||||||
app.mount("/", SPAStaticFiles(directory="../build", html=True), name="spa-static-files")
|
app.mount("/",
|
||||||
|
SPAStaticFiles(directory="../build", html=True),
|
||||||
|
name="spa-static-files")
|
||||||
|
|
Loading…
Reference in a new issue