Skip to content

Commit 201bd4d

Browse files
committed
Converter API: enable user mapping file
1 parent 6445328 commit 201bd4d

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

lidoapp_bp/lidoapp_bp.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,22 @@ def runMappings():
144144
def convert():
145145
# TODO: catch error and provide better error response e.g. code 400 for malformed LIDO
146146
# Valid formats: "xml", "n3", "turtle", "nt", "pretty-xml", "trix", "trig", "nquads", "json-ld", "hext"
147-
# Example: curl -X POST -F format='nt' -F file=@FILE HOST:PORT/convert"
147+
# Example: curl -X POST -F file=@my_lido_file.xml -F mapping=@my_mapping_file.x3ml -F format='nt' HOST:PORT/convert
148148
if request.mimetype == "multipart/form-data":
149-
lido_xml = request.files['file'].read().decode('utf-8')
149+
if 'file' not in request.files:
150+
return jsonify({'error': "No LIDO file part in the request."}), 400
151+
if 'mapping' in request.files:
152+
mapping_data = request.files['mapping'].read().decode('utf-8')
153+
else:
154+
mapping_data = dlftMappingFile().read_text()
155+
lido_data = request.files['file'].read().decode('utf-8')
150156
format = request.form.get('format','turtle')
151157
else:
152-
lido_xml = request.get_data()
158+
mapping_data = dlftMappingFile().read_text()
159+
lido_data = request.get_data()
153160
format ='turtle'
154161
try:
155-
rdf_str = convert_lido_str(lido_xml, dlftMappingFile().read_text(),format=format)
162+
rdf_str = convert_lido_str(lido_data, mapping_data,format=format)
156163
response = make_response(rdf_str, 200)
157164
response.mime_type = f"text/{format}"
158165
except Exception as e:

0 commit comments

Comments
 (0)