11
This commit is contained in:
31
app/services/oem_public.py
Normal file
31
app/services/oem_public.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.config import get_settings
|
||||
from app.models.oem import Oem
|
||||
from app.schemas.oem_public import OemPublicBrandingOut
|
||||
|
||||
|
||||
def _logo_url(logo_path: str | None, base_url: str) -> str | None:
|
||||
if not logo_path or not logo_path.strip():
|
||||
return None
|
||||
path = logo_path.strip().replace("\\", "/").lstrip("/")
|
||||
if path.startswith("http://") or path.startswith("https://"):
|
||||
return path
|
||||
if not path.startswith("images/"):
|
||||
path = f"images/{path.removeprefix('images/')}"
|
||||
return f"{base_url.rstrip('/')}/{path}"
|
||||
|
||||
|
||||
async def get_oem_public_branding(db: AsyncSession, oem_id: int) -> OemPublicBrandingOut:
|
||||
settings = get_settings()
|
||||
base_url = settings.api_public_base.rstrip("/")
|
||||
oem = await db.get(Oem, oem_id)
|
||||
if oem is None:
|
||||
return OemPublicBrandingOut(oem_id=oem_id, software_name="", logo_url=None, wechat=None)
|
||||
|
||||
return OemPublicBrandingOut(
|
||||
oem_id=oem.id,
|
||||
software_name=oem.software_name or "",
|
||||
logo_url=_logo_url(oem.logo_path, base_url),
|
||||
wechat=oem.wechat,
|
||||
)
|
||||
Reference in New Issue
Block a user