]> git.ipfire.org Git - pbs.git/commitdiff
api: Create an endpoint to fetch the filelist of a package
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 7 Jul 2025 13:05:56 +0000 (13:05 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 7 Jul 2025 13:05:56 +0000 (13:05 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/api/packages.py

index 65189cbb6adebb647038d382245e5a6e09a4b4e7..b5af79745891572f2ac654a0a74fc64036fd7d42 100644 (file)
@@ -27,7 +27,7 @@ from uuid import UUID
 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(
@@ -35,6 +35,12 @@ 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
@@ -57,16 +63,15 @@ async def get_packages() -> list[PackageSummary]:
 
 
 @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)
@@ -74,5 +79,14 @@ async def get_package(name: str) -> Package:
        # 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)