remove debug session and return file as response
This commit is contained in:
parent
1371f3f2e5
commit
d66ad362c7
|
@ -23,7 +23,6 @@ class Config:
|
||||||
|
|
||||||
environment = 'PROD'
|
environment = 'PROD'
|
||||||
database_name = 'montreal_retrofit'
|
database_name = 'montreal_retrofit'
|
||||||
self._base_uri = 'https://nextgenerations-cities.encs.concordia.ca/data/files/response_files'
|
|
||||||
self._database = DBControl(db_name=database_name, app_env=environment, dotenv_path=dotenv_path)
|
self._database = DBControl(db_name=database_name, app_env=environment, dotenv_path=dotenv_path)
|
||||||
self._repository = Repository(db_name=database_name, app_env=environment, dotenv_path=dotenv_path)
|
self._repository = Repository(db_name=database_name, app_env=environment, dotenv_path=dotenv_path)
|
||||||
self._energy_systems_catalog = EnergySystemsCatalogFactory('montreal_custom').catalog
|
self._energy_systems_catalog = EnergySystemsCatalogFactory('montreal_custom').catalog
|
||||||
|
|
|
@ -4,7 +4,7 @@ import shutil
|
||||||
import zipfile
|
import zipfile
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from flask import Response, request, send_file
|
from flask import Response, request, send_file, make_response
|
||||||
from flask_restful import Resource
|
from flask_restful import Resource
|
||||||
from hub.exports.energy_building_exports_factory import EnergyBuildingsExportsFactory
|
from hub.exports.energy_building_exports_factory import EnergyBuildingsExportsFactory
|
||||||
from hub.imports.construction_factory import ConstructionFactory
|
from hub.imports.construction_factory import ConstructionFactory
|
||||||
|
@ -67,11 +67,10 @@ class EnergyPlus(Resource, Config):
|
||||||
token = request.headers.get('token', None)
|
token = request.headers.get('token', None)
|
||||||
application_uuid = request.headers.get('application-uuid', None)
|
application_uuid = request.headers.get('application-uuid', None)
|
||||||
_session = refresh_session(session_id, token, application_uuid)
|
_session = refresh_session(session_id, token, application_uuid)
|
||||||
_session = {'token': token}
|
|
||||||
response_token = {'token': _session['token']}
|
|
||||||
if _session is None:
|
if _session is None:
|
||||||
return Response(json.dumps({'error': 'unauthorized'}), status=403)
|
return Response(json.dumps({'error': 'unauthorized'}), status=403)
|
||||||
else:
|
else:
|
||||||
|
response_token = {'token': _session['token']}
|
||||||
tmp_path = (self._tmp_path / token).resolve()
|
tmp_path = (self._tmp_path / token).resolve()
|
||||||
response_path = (self._response_path / session_id).resolve()
|
response_path = (self._response_path / session_id).resolve()
|
||||||
try:
|
try:
|
||||||
|
@ -109,11 +108,10 @@ class EnergyPlus(Resource, Config):
|
||||||
str((tmp_path / f'{self._city.name}.idf').resolve()),
|
str((tmp_path / f'{self._city.name}.idf').resolve()),
|
||||||
]
|
]
|
||||||
result_zip = (response_path / f'{token}.zip').resolve()
|
result_zip = (response_path / f'{token}.zip').resolve()
|
||||||
with zipfile.ZipFile(result_zip, 'w') as zip:
|
with zipfile.ZipFile(result_zip, 'w') as zf:
|
||||||
for result_file in result_files:
|
for result_file in result_files:
|
||||||
zip.write(result_file, Path(result_file).name)
|
zf.write(result_file, Path(result_file).name)
|
||||||
shutil.rmtree(tmp_path)
|
shutil.rmtree(tmp_path)
|
||||||
return Response(json.dumps({
|
response = make_response(send_file(result_zip))
|
||||||
'result': 'succeed',
|
response.headers['token'] = token
|
||||||
'file': f'{self.base_uri}/{session_id}/{token}.zip'
|
return response
|
||||||
}), status=200, headers=response_token)
|
|
||||||
|
|
|
@ -69,11 +69,10 @@ class InselMonthlyEnergyBalance(Resource, Config):
|
||||||
token = request.headers.get('token', None)
|
token = request.headers.get('token', None)
|
||||||
application_uuid = request.headers.get('application-uuid', None)
|
application_uuid = request.headers.get('application-uuid', None)
|
||||||
_session = refresh_session(session_id, token, application_uuid)
|
_session = refresh_session(session_id, token, application_uuid)
|
||||||
_session = {'token': token}
|
|
||||||
response_token = {'token': _session['token']}
|
|
||||||
if _session is None:
|
if _session is None:
|
||||||
return Response(json.dumps({'error': 'unauthorized'}), status=403)
|
return Response(json.dumps({'error': 'unauthorized'}), status=403)
|
||||||
else:
|
else:
|
||||||
|
response_token = {'token': _session['token']}
|
||||||
tmp_path = (self._tmp_path / token).resolve()
|
tmp_path = (self._tmp_path / token).resolve()
|
||||||
try:
|
try:
|
||||||
os.mkdir(tmp_path)
|
os.mkdir(tmp_path)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user