From 3bc5a20794371473f1ce898a31141e18e3ccd222 Mon Sep 17 00:00:00 2001 From: Riley Housden Date: Wed, 8 Dec 2021 08:43:34 -0500 Subject: [PATCH] add get builds route --- routers/mc_optimizer.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/routers/mc_optimizer.py b/routers/mc_optimizer.py index 4eccf78..730d27e 100644 --- a/routers/mc_optimizer.py +++ b/routers/mc_optimizer.py @@ -17,18 +17,13 @@ ROOT_PATH.mkdir(exist_ok=True) class PackFile: def __init__(self, file: Path) -> None: self.file = file - self.datetime = self.set_datetime() - self.build = self.set_build() - - def set_datetime(self): - zf = ZipFile(self.file) - manifest = json.loads(zf.read("manifest.json").decode("utf-8")) - return datetime.strptime(manifest['build-date'], "%d-%m-%Y-%H%M%S") + self.manifest = self.set_manifest() + self.datetime = datetime.strptime(self.manifest['build-date'], "%d-%m-%Y-%H%M%S") + self.build = self.manifest['build'] - def set_build(self): + def set_manifest(self): zf = ZipFile(self.file) - manifest = json.loads(zf.read("manifest.json").decode("utf-8")) - return manifest['build'] + return json.loads(zf.read("manifest.json").decode("utf-8")) def __lt__(self, other: PackFile): return self.datetime.__lt__(other.datetime) @@ -53,4 +48,12 @@ def get_build(build: int): pf = PackFile(file) if pf.build == build: return FileResponse(pf.file, filename=f"mc-optimizer-pack-{pf.build}.zip") - raise HTTPException(404, "Build not found.") \ No newline at end of file + raise HTTPException(404, "Build not found.") + +@router.get("/builds") +def get_builds(): + builds = [] + for file in ROOT_PATH.iterdir(): + pf = PackFile(file) + builds.append(pf.manifest) + return builds \ No newline at end of file