add get builds route
This commit is contained in:
parent
9fb5a7a456
commit
3bc5a20794
1 changed files with 14 additions and 11 deletions
|
@ -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()
|
||||
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_datetime(self):
|
||||
def set_manifest(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")
|
||||
|
||||
def set_build(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)
|
||||
|
@ -54,3 +49,11 @@ def get_build(build: int):
|
|||
if pf.build == build:
|
||||
return FileResponse(pf.file, filename=f"mc-optimizer-pack-{pf.build}.zip")
|
||||
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
|
Loading…
Reference in a new issue