add check for logtime parameter in http_system endpoint as first test to address issue #132

This commit is contained in:
avollkopf 2024-04-15 19:07:37 +02:00
parent 33481caa7b
commit 57572c777e
2 changed files with 35 additions and 17 deletions

View file

@ -1,3 +1,3 @@
__version__ = "4.4.0"
__version__ = "4.4.1.a1"
__codename__ = "Yeast Starter"

View file

@ -165,31 +165,49 @@ class SystemHttpEndpoints:
description: Zip and download craftbeerpi.service log
tags:
- System
parameters:
- name: "logtime"
in: "path"
description: "Logtime in hours"
required: true
type: "integer"
format: "int64"
responses:
"200":
description: successful operation
content: # Response body
application/zip: # Media type
"""
checklogtime = False
logtime = request.match_info['logtime']
await self.controller.downloadlog(logtime)
filename = "cbpi4_log.zip"
file_name = pathlib.Path(os.path.join(".", filename))
response = web.StreamResponse(
status=200,
reason='OK',
headers={'Content-Type': 'application/zip'},
)
await response.prepare(request)
with open(file_name, 'rb') as file:
for line in file.readlines():
await response.write(line)
try:
test=int(logtime)
checklogtime = True
except:
if logtime == "b":
checklogtime = True
await response.write_eof()
os.remove(file_name)
return response
if checklogtime:
await self.controller.downloadlog(logtime)
filename = "cbpi4_log.zip"
file_name = pathlib.Path(os.path.join(".", filename))
response = web.StreamResponse(
status=200,
reason='OK',
headers={'Content-Type': 'application/zip'},
)
await response.prepare(request)
with open(file_name, 'rb') as file:
for line in file.readlines():
await response.write(line)
await response.write_eof()
os.remove(file_name)
return response
else:
return web.Response(status=400, text='Need integer or "b" for logtime.')
@request_mapping("/restore", method="POST", name="RestoreConfig", auth_required=False)
async def restore(self, request):