mirror of
https://github.com/PiBrewing/craftbeerpi4.git
synced 2024-11-25 00:18:17 +01:00
SVG upload functionality
This commit is contained in:
parent
40121e667e
commit
6e3dc392b6
3 changed files with 59 additions and 1 deletions
|
@ -1 +1 @@
|
|||
__version__ = "4.0.0.43"
|
||||
__version__ = "4.0.0.44"
|
||||
|
|
|
@ -85,6 +85,30 @@ class SystemController:
|
|||
else:
|
||||
self.cbpi.notify("Error", "Wrong content type. Upload failed", NotificationType.ERROR)
|
||||
|
||||
async def uploadSVG(self, data):
|
||||
fileData = data['File']
|
||||
filename = fileData.filename
|
||||
svg_file = fileData.file
|
||||
content_type = fileData.content_type
|
||||
|
||||
logging.info(content_type)
|
||||
|
||||
if content_type == 'image/svg+xml':
|
||||
try:
|
||||
content = svg_file.read().decode('utf-8','replace')
|
||||
if svg_file and self.allowed_file(filename, 'svg'):
|
||||
self.path = os.path.join(".","config","dashboard","widgets", filename)
|
||||
logging.info(self.path)
|
||||
|
||||
f=open(self.path, "w")
|
||||
f.write(content)
|
||||
f.close()
|
||||
except:
|
||||
self.cbpi.notify("Error", "SVG upload failed", NotificationType.ERROR)
|
||||
pass
|
||||
else:
|
||||
self.cbpi.notify("Error", "Wrong content type. Upload failed", NotificationType.ERROR)
|
||||
|
||||
async def systeminfo(self):
|
||||
logging.info("SYSTEMINFO")
|
||||
system = ""
|
||||
|
@ -147,6 +171,23 @@ class SystemController:
|
|||
except:
|
||||
pass
|
||||
|
||||
if system == "Windows":
|
||||
try:
|
||||
ethernet = psutil.net_if_addrs()
|
||||
for nic, addrs in ethernet.items():
|
||||
if nic == "Ethernet":
|
||||
for addr in addrs:
|
||||
if str(addr.family) == "AddressFamily.AF_INET":
|
||||
if addr.address:
|
||||
eth0IP = addr.address
|
||||
if nic == "WLAN":
|
||||
for addr in addrs:
|
||||
if str(addr.family) == "AddressFamily.AF_INET":
|
||||
if addr.address:
|
||||
wlan0IP = addr.address
|
||||
except:
|
||||
pass
|
||||
|
||||
except:
|
||||
pass
|
||||
|
||||
|
|
|
@ -176,3 +176,20 @@ class SystemHttpEndpoints:
|
|||
"""
|
||||
systeminfo = await self.controller.systeminfo()
|
||||
return web.json_response(data=systeminfo)
|
||||
|
||||
@request_mapping("/uploadsvg", method="POST", name="UploadSVG", auth_required=False)
|
||||
async def uploadSVG(self, request):
|
||||
"""
|
||||
---
|
||||
description: Upload SVG file to widgets folder
|
||||
tags:
|
||||
- System
|
||||
responses:
|
||||
"200":
|
||||
description: successful operation
|
||||
"""
|
||||
logging.info("Upload SVG file")
|
||||
data = await request.post()
|
||||
logging.info("Data received")
|
||||
await self.controller.uploadSVG(data)
|
||||
return web.Response(status=200)
|
Loading…
Reference in a new issue