Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /JeanExtreme002_Dokku-API /src /api /routers /search.py
| from fastapi import APIRouter, FastAPI, Request, status | |
| from fastapi.responses import JSONResponse | |
| from src.api.schemas import UserSchema | |
| from src.api.services import AppService, DatabaseService | |
| from src.api.tools.resource import ResourceName | |
| def get_router(app: FastAPI) -> APIRouter: | |
| router = APIRouter() | |
| async def search(request: Request, q: str): | |
| query = q.strip().lower() | |
| result = {} | |
| user: UserSchema = request.state.session_user | |
| for app_name in user.apps: | |
| app_name = str(ResourceName(user, app_name, from_system=True)).lower() | |
| if query in app_name: | |
| details = (await AppService.get_app_info(user, app_name))[1] | |
| data = result.get("apps", []) + [ | |
| {app_name: details}, | |
| ] | |
| result["apps"] = data | |
| for author_email, app_name in user.shared_apps: | |
| if query in author_email.lower() or query in app_name.lower(): | |
| details = ( | |
| await AppService.get_app_info( | |
| user, app_name, shared_by=author_email | |
| ) | |
| )[1] | |
| data = result.get("share_apps", []) + [ | |
| {f"{author_email}:{app_name}": details}, | |
| ] | |
| result["share_apps"] = data | |
| for service_name in user.services: | |
| plugin_name, service_name = service_name.split(":", maxsplit=1) | |
| service_name = str( | |
| ResourceName(user, service_name, from_system=True) | |
| ).lower() | |
| if query in service_name: | |
| details = ( | |
| await DatabaseService.get_database_info( | |
| user, plugin_name, service_name | |
| ) | |
| )[1] | |
| data = result.get("services", []) + [ | |
| {service_name: details}, | |
| ] | |
| result["services"] = data | |
| for network_name in user.networks: | |
| network_name = str( | |
| ResourceName(user, network_name, from_system=True) | |
| ).lower() | |
| if query in network_name: | |
| data = result.get("networks", []) + [ | |
| network_name, | |
| ] | |
| result["networks"] = data | |
| for available_database in (await DatabaseService.list_available_databases())[1]: | |
| if query in available_database: | |
| data = result.get("available_databases", []) + [ | |
| available_database, | |
| ] | |
| result["available_databases"] = data | |
| return JSONResponse( | |
| status_code=status.HTTP_200_OK, | |
| content={ | |
| "success": True, | |
| "result": result, | |
| }, | |
| ) | |
| return router | |
Xet Storage Details
- Size:
- 2.97 kB
- Xet hash:
- bf8d9da4baa2a7bb379185344922def625d3d8d7171cd07fa277ff657ec08569
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.