mirror of
https://github.com/PiBrewing/craftbeerpi4.git
synced 2024-11-21 22:48:16 +01:00
add check for logtime parameter in http_system endpoint as first test to address issue #132
This commit is contained in:
parent
33481caa7b
commit
57572c777e
2 changed files with 35 additions and 17 deletions
|
@ -1,3 +1,3 @@
|
||||||
__version__ = "4.4.0"
|
__version__ = "4.4.1.a1"
|
||||||
__codename__ = "Yeast Starter"
|
__codename__ = "Yeast Starter"
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
"""
|
"""
|
||||||
|
checklogtime = False
|
||||||
logtime = request.match_info['logtime']
|
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(
|
try:
|
||||||
status=200,
|
test=int(logtime)
|
||||||
reason='OK',
|
checklogtime = True
|
||||||
headers={'Content-Type': 'application/zip'},
|
except:
|
||||||
)
|
if logtime == "b":
|
||||||
await response.prepare(request)
|
checklogtime = True
|
||||||
with open(file_name, 'rb') as file:
|
|
||||||
for line in file.readlines():
|
|
||||||
await response.write(line)
|
|
||||||
|
|
||||||
await response.write_eof()
|
if checklogtime:
|
||||||
os.remove(file_name)
|
await self.controller.downloadlog(logtime)
|
||||||
return response
|
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)
|
@request_mapping("/restore", method="POST", name="RestoreConfig", auth_required=False)
|
||||||
async def restore(self, request):
|
async def restore(self, request):
|
||||||
|
|
Loading…
Reference in a new issue