1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-29 02:08:10 +00:00

Merge pull request #1885 from GNS3/Create-endpoint-in-symbols-handler-to-get-symbol-dimensions

Create endpoint in symbols handler to get symbol dimensions #1884
This commit is contained in:
Jeremy Grossmann 2021-04-09 04:59:57 -07:00 committed by GitHub
commit c9c6a5a762
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 2 deletions

View File

@ -22,7 +22,7 @@ import urllib.parse
from gns3server.web.route import Route
from gns3server.controller import Controller
from gns3server.utils.picture import get_size
import logging
log = logging.getLogger(__name__)
@ -44,6 +44,24 @@ class SymbolHandler:
controller = Controller.instance()
response.json(controller.symbols.list())
@Route.get(
r"/symbols/{symbol_id:.+}/dimensions",
description="Get the symbol dimensions",
status_codes={
200: "Symbol dimensions returned"
})
async def raw(request, response):
controller = Controller.instance()
symbol_id = urllib.parse.unquote(request.match_info["symbol_id"])
try:
width, height, _ = controller.symbols.get_size(symbol_id)
symbol_dimensions = { 'width': width, 'height': height }
response.json(symbol_dimensions)
except (KeyError, OSError) as e:
log.warning("Could not get symbol file: {}".format(e))
response.set_status(404)
@Route.get(
r"/symbols/{symbol_id:.+}/raw",
description="Get the symbol file",

View File

@ -92,7 +92,7 @@ def get_size(data, default_width=0, default_height=0):
# End of https://github.com/shibukawa/imagesize_py
# handle SVG
elif size >= 10 and data.startswith(b'<?xml'):
elif size >= 10 and (data.startswith(b'<?xml') or data.startswith(b'<svg')):
filetype = "svg"
fhandle = io.BytesIO(data)
tree = ElementTree()