mirror of
https://github.com/lnbits/lnbits-legend.git
synced 2025-03-13 19:37:42 +01:00
feat: add normalize_path
helper (#2981)
This commit is contained in:
parent
6754ffb9dc
commit
9fe63b49d6
2 changed files with 17 additions and 1 deletions
|
@ -312,3 +312,18 @@ def get_api_routes(routes: list) -> dict[str, str]:
|
|||
data["/".join(segments[0:4])] = segments[1].capitalize()
|
||||
|
||||
return data
|
||||
|
||||
|
||||
def path_segments(path: str) -> list[str]:
|
||||
path = path.strip("/")
|
||||
segments = path.split("/")
|
||||
if len(segments) < 2:
|
||||
return segments
|
||||
if segments[0] == "upgrades":
|
||||
return segments[2:]
|
||||
return segments[0:]
|
||||
|
||||
|
||||
def normalize_path(path: Optional[str]) -> str:
|
||||
path = path or ""
|
||||
return "/" + "/".join(path_segments(path))
|
||||
|
|
|
@ -15,7 +15,7 @@ from starlette.types import ASGIApp, Receive, Scope, Send
|
|||
|
||||
from lnbits.core.db import core_app_extra
|
||||
from lnbits.core.models import AuditEntry
|
||||
from lnbits.helpers import template_renderer
|
||||
from lnbits.helpers import normalize_path, template_renderer
|
||||
from lnbits.settings import settings
|
||||
|
||||
|
||||
|
@ -156,6 +156,7 @@ class AuditMiddleware(BaseHTTPMiddleware):
|
|||
if settings.is_super_user(user_id):
|
||||
user_id = "super_user"
|
||||
component = "core"
|
||||
path = normalize_path(path)
|
||||
if path and not path.startswith("/api"):
|
||||
component = path.split("/")[1]
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue