1010from urllib .parse import urlparse
1111
1212LOG_FILE = 'app.log'
13- IMPORTER_URL = 'http://importer:5020'
14- FUSEKI_URL = 'http://fuseki:3030'
13+ IMPORTER_HOST = 'http://importer:5020'
14+ FUSEKI_HOST = 'http://fuseki:3030'
1515
1616
1717logging .basicConfig (filename = LOG_FILE , level = logging .INFO )
@@ -86,7 +86,7 @@ def logout():
8686@app .route ('/fuseki' , methods = ['post' ])
8787def fuseki ():
8888 if data := request .json .get ('data' ):
89- res = requests .post (f'{ FUSEKI_URL } /n4o?query={ data } ' )
89+ res = requests .post (f'{ FUSEKI_HOST } /n4o?query={ data } ' )
9090 return jsonify (res .text ), res .status_code
9191
9292
@@ -95,7 +95,7 @@ def importer(subpath):
9595 '''Forwards requests to the importer service'''
9696 res = requests .request (
9797 method = request .method ,
98- url = f'{ IMPORTER_URL } /{ subpath } ' , # Forward to importer service
98+ url = f'{ IMPORTER_HOST } /{ subpath } ' , # Forward to importer service
9999 headers = {k : v for k , v in request .headers if k .lower () != 'host' }, # Exclude 'host' header
100100 data = request .get_data (),
101101 cookies = request .cookies ,
@@ -110,21 +110,22 @@ def importer(subpath):
110110 return response
111111
112112
113- @app .route ('/postCollectionData' , methods = ['POST' ])
114- def postCollectionData ():
115- '''Posts new collection data. Recent data will be deleted.'''
116- if uri := request .json .get ('uri' ):
117- index = urlparse (uri ).path .strip ('/' ).split ('/' )[- 1 ]
118- if data := request .json ['data' ]:
113+ @app .route ('/postCollectionData/<int:coll_index>' , methods = ['POST' ])
114+ def postCollectionData (coll_index ):
115+ '''Upload new collection data. Recent data will be deleted.'''
116+ if coll_index > 0 :
117+ if file := request .files .get ('file' ):
119118 # Copy data to file, then call importer services receive and add
120- suffix = request .json .get ("suffix" , "ttl" )
121- import_file = f'import_{ index } .{ suffix } '
122- Path (f'./data' ).mkdir (exist_ok = True )
123- Path (f'./data/{ import_file } ' ).write_text (data )
124- service = f'{ IMPORTER_URL } /collection/{ index } '
125- res = requests .post (f'{ service } /receive?from={ import_file } ' )
126- res = requests .post (f'{ service } /load' )
127- #res = requests.post(f'{service}/add')
119+ # logger.info(f'name = {file.filename} index = {index}')
120+ buffer_name = f'collection_{ coll_index } { Path (file .filename ).suffix } '
121+ file .save (f'./data/{ buffer_name } ' )
122+
123+ service_url = f'{ IMPORTER_HOST } /collection/{ coll_index } '
124+ res = requests .post (f'{ service_url } /receive?from={ buffer_name } ' )
125+ if res .ok :
126+ res = requests .post (f'{ service_url } /load' )
127+ # TODO res = requests.post(f'{service}/add') #Not supporte
128+ Path (f'./data/{ buffer_name } ' ).unlink (missing_ok = False )
128129 return res .text , res .status_code
129130 return jsonify (message = 'No data or collection index provided' )
130131
0 commit comments