mirror of
https://github.com/GNS3/gns3-server.git
synced 2025-05-31 14:50:55 +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:
commit
c9c6a5a762
@ -22,7 +22,7 @@ import urllib.parse
|
|||||||
|
|
||||||
from gns3server.web.route import Route
|
from gns3server.web.route import Route
|
||||||
from gns3server.controller import Controller
|
from gns3server.controller import Controller
|
||||||
|
from gns3server.utils.picture import get_size
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
@ -44,6 +44,24 @@ class SymbolHandler:
|
|||||||
controller = Controller.instance()
|
controller = Controller.instance()
|
||||||
response.json(controller.symbols.list())
|
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(
|
@Route.get(
|
||||||
r"/symbols/{symbol_id:.+}/raw",
|
r"/symbols/{symbol_id:.+}/raw",
|
||||||
description="Get the symbol file",
|
description="Get the symbol file",
|
||||||
|
@ -92,7 +92,7 @@ def get_size(data, default_width=0, default_height=0):
|
|||||||
# End of https://github.com/shibukawa/imagesize_py
|
# End of https://github.com/shibukawa/imagesize_py
|
||||||
|
|
||||||
# handle SVG
|
# 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"
|
filetype = "svg"
|
||||||
fhandle = io.BytesIO(data)
|
fhandle = io.BytesIO(data)
|
||||||
tree = ElementTree()
|
tree = ElementTree()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user