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" __codename__ = "Yeast Starter"

View file

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