from . import apiv1
from . import backend
-from ..packages import Package
+from ..packages import Package, File
# Create a new router for all endpoints
router = fastapi.APIRouter(
tags=["Packages"],
)
+async def get_package_by_uuid(uuid: UUID) -> Package:
+ """
+ Fetches a package by its UUID
+ """
+ return await backend.packages.get_by_uuid(uuid)
+
class PackageSummary(pydantic.BaseModel):
"""
This is a helper model to shorten the list of packages which
@router.get("/{uuid:uuid}")
-async def get_package_by_uuid(uuid: UUID) -> Package:
- # Fetch the package by its UUID
- pkg = await backend.packages.get_by_uuid(uuid)
- if not pkg:
+async def get_by_uuid(
+ package: Package = fastapi.Depends(get_package_by_uuid)) -> Package:
+ if not package:
raise fastapi.HTTPException(404, "Could not find package %s" % id)
- return pkg
+ return package
@router.get("/{name}")
-async def get_package(name: str) -> Package:
+async def get_by_name(name: str) -> Package:
build = await backend.builds.get_latest_by_name(name)
if not build:
raise fastapi.HTTPException(404, "Could not find package %s" % name)
# Return the source package
return build.pkg
+@router.get("/{uuid:uuid}/filelist")
+async def get_filelist_by_uuid(
+ package: Package = fastapi.Depends(get_package_by_uuid)) -> list[File]:
+ if not package:
+ raise fastapi.HTTPException(404, "Could not find package")
+
+ # Return the entire filelist
+ return [file async for file in await package.get_files()]
+
# Add everything to the APIv1
apiv1.include_router(router)