Skip to content

Commit e27ecee

Browse files
committed
Return RDF knowledge for a map from a request to its URL if index.ttl exists and the request is for text/turtle.
1 parent 1b98fa3 commit e27ecee

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

mapserver/server/flatmap.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,25 @@ async def flatmap_index(request: Request, map_uuid: str) -> dict|Response:
119119
120120
:reqheader Accept: Determines the response content
121121
122-
If an SVG representation of the map exists and the :mailheader:`Accept` header
123-
doesn't specify a JSON response then the SVG is returned, otherwise the
122+
A request for ``text/turtle`` will return the RDF knowledge about the map in
123+
``index.ttl`; if an SVG representation of the map exists and the :mailheader:`Accept`
124+
header doesn't specify a JSON response then the SVG is returned; otherwise the
124125
flatmap's ``index.json`` is returned.
125126
"""
126127
index_file = pathlib.Path(settings['FLATMAP_ROOT']) / map_uuid / 'index.json'
127128
if not index_file.exists():
128129
return Response(content={'detail': 'Missing map index'}, status_code=404)
129130
with open(index_file) as fp:
130131
index = json.load(fp)
131-
if 'json' not in request.headers.get('accept', '*/*'):
132+
accept_mediatype = request.headers.get('accept', '*/*')
133+
if 'text/turtle' in accept_mediatype:
134+
# Return RDF knowledge (as Turtle) about the map.
135+
knowledge = pathlib.Path(settings['FLATMAP_ROOT']) / map_uuid / 'index.ttl'
136+
if not knowledge.exists():
137+
return Response(content={'detail': 'RDF knowledge is not available'}, status_code=404)
138+
with open(knowledge) as fp:
139+
return Response(content=fp.read(), media_type='text/turtle')
140+
elif 'json' not in request.headers.get('accept', '*/*'):
132141
svg_file = pathlib.Path(settings['FLATMAP_ROOT']) / map_uuid / f'{index["id"]}.svg'
133142
if not svg_file.exists():
134143
svg_file = pathlib.Path(settings['FLATMAP_ROOT']) / map_uuid / 'images' / f'{index["id"]}.svg'

0 commit comments

Comments
 (0)