SVG upload functionality

This commit is contained in:
avollkopf 2021-11-09 18:32:00 +01:00
parent 40121e667e
commit 6e3dc392b6
3 changed files with 59 additions and 1 deletions

View file

@ -1 +1 @@
__version__ = "4.0.0.43"
__version__ = "4.0.0.44"

View file

@ -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

View file

@ -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)