]> git.ipfire.org Git - pbs.git/commitdiff
API: Add method to fetch basic information about an upload
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 15 Jun 2025 15:21:50 +0000 (15:21 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 15 Jun 2025 15:21:50 +0000 (15:21 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/api/__init__.py
src/api/uploads.py [new file with mode: 0644]

index bc99be5692b596449f2a2bca9e78376d75a61cf7..9b7151469fe4a629301d9f8bd673a21c1a82400c 100644 (file)
@@ -122,7 +122,8 @@ CLEANFILES += \
 
 api_PYTHON = \
        src/api/__init__.py \
-       src/api/builds.py
+       src/api/builds.py \
+       src/api/uploads.py
 
 apidir = $(pkgpythondir)/api
 
index c98c56ff9bb2ebba0c874b9db9c30a66a78b93eb..c5dfacce9ce2d6cb6e82e6aa85915137fa501442 100644 (file)
@@ -47,3 +47,4 @@ app.add_middleware(
 
 # Load all further modules
 from . import builds
+from . import uploads
diff --git a/src/api/uploads.py b/src/api/uploads.py
new file mode 100644 (file)
index 0000000..f140852
--- /dev/null
@@ -0,0 +1,37 @@
+###############################################################################
+#                                                                             #
+# Pakfire - The IPFire package management system                              #
+# Copyright (C) 2025 Pakfire development team                                 #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
+
+import fastapi
+import uuid
+
+from . import app
+from . import backend
+
+from .. import uploads
+
+@app.get("/uploads/{id}")
+async def get(id: uuid.UUID) -> uploads.Upload:
+       upload = await backend.uploads.get_by_uuid(id)
+
+       # Raise 404 if the upload could not be found
+       if not upload:
+               raise fastapi.HTTPException(404, "Upload not found")
+
+       return upload