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'
|
||||
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._repository = Repository(db_name=database_name, app_env=environment, dotenv_path=dotenv_path)
|
||||
self._energy_systems_catalog = EnergySystemsCatalogFactory('montreal_custom').catalog
|
||||
|
@ -4,7 +4,7 @@ import shutil
|
||||
import zipfile
|
||||
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 hub.exports.energy_building_exports_factory import EnergyBuildingsExportsFactory
|
||||
from hub.imports.construction_factory import ConstructionFactory
|
||||
@ -67,11 +67,10 @@ class EnergyPlus(Resource, Config):
|
||||
token = request.headers.get('token', None)
|
||||
application_uuid = request.headers.get('application-uuid', None)
|
||||
_session = refresh_session(session_id, token, application_uuid)
|
||||
_session = {'token': token}
|
||||
response_token = {'token': _session['token']}
|
||||
if _session is None:
|
||||
return Response(json.dumps({'error': 'unauthorized'}), status=403)
|
||||
else:
|
||||
response_token = {'token': _session['token']}
|
||||
tmp_path = (self._tmp_path / token).resolve()
|
||||
response_path = (self._response_path / session_id).resolve()
|
||||
try:
|
||||
@ -109,11 +108,10 @@ class EnergyPlus(Resource, Config):
|
||||
str((tmp_path / f'{self._city.name}.idf').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:
|
||||
zip.write(result_file, Path(result_file).name)
|
||||
zf.write(result_file, Path(result_file).name)
|
||||
shutil.rmtree(tmp_path)
|
||||
return Response(json.dumps({
|
||||
'result': 'succeed',
|
||||
'file': f'{self.base_uri}/{session_id}/{token}.zip'
|
||||
}), status=200, headers=response_token)
|
||||
response = make_response(send_file(result_zip))
|
||||
response.headers['token'] = token
|
||||
return response
|
||||
|
@ -69,11 +69,10 @@ class InselMonthlyEnergyBalance(Resource, Config):
|
||||
token = request.headers.get('token', None)
|
||||
application_uuid = request.headers.get('application-uuid', None)
|
||||
_session = refresh_session(session_id, token, application_uuid)
|
||||
_session = {'token': token}
|
||||
response_token = {'token': _session['token']}
|
||||
if _session is None:
|
||||
return Response(json.dumps({'error': 'unauthorized'}), status=403)
|
||||
else:
|
||||
response_token = {'token': _session['token']}
|
||||
tmp_path = (self._tmp_path / token).resolve()
|
||||
try:
|
||||
os.mkdir(tmp_path)
|
||||
|
Loading…
Reference in New Issue
Block a user