diff --git a/bootstrap.py b/bootstrap.py index 8316955..b43df96 100644 --- a/bootstrap.py +++ b/bootstrap.py @@ -23,11 +23,13 @@ from hub_api.workflow.insel_montly_energy_balance import InselMonthlyEnergyBalan from hub_api.workflow.costs import Costs from hub_api.workflow.energy_plus import EnergyPlus from hub_api.energy_plus.idf_generator import IdfGenerator +from hub_api.config import Config sh.begin_time = datetime.datetime.now() app = flask.Flask('cerc_api') app.json_provider_class = LazyJSONEncoder +app.config['MAX_CONTENT_LENGTH'] = Config.max_file_size api = Api(app) api.add_resource(Uptime, '/v1.4/uptime') diff --git a/hub_api/config.py b/hub_api/config.py index a61fcd2..33c1ac7 100644 --- a/hub_api/config.py +++ b/hub_api/config.py @@ -21,6 +21,7 @@ class Config: environment = 'PROD' database_name = 'montreal_retrofit' + self._max_file_size = 10 * 1024 * 1024 # 10 MB 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) @@ -37,3 +38,7 @@ class Config: @property def energy_systems_catalog(self): return self._energy_systems_catalog + + @property + def max_file_size(self): + return self._max_file_size diff --git a/hub_api/workflow/insel_montly_energy_balance.py b/hub_api/workflow/insel_montly_energy_balance.py index c7564c4..8a49af1 100644 --- a/hub_api/workflow/insel_montly_energy_balance.py +++ b/hub_api/workflow/insel_montly_energy_balance.py @@ -1,14 +1,36 @@ +import json +from pathlib import Path from flask_restful import Resource +from flask import Response, request from hub_api.config import Config +from hub_api.helpers.session_helper import refresh_session class InselMonthlyEnergyBalance(Resource, Config): def __init__(self): super().__init__() + self._extensions = ['geojson', 'citygml'] + + def _allowed_extensions(self, filename): + self._file_extension = Path(filename).suffix + return self._file_extension in self._extensions + + def _geojson(self, geojson_file): + return def post(self): """ API call for performing the monthly energy balance workflow """ - raise NotImplementedError() + session_id = request.headers.get('session-id', None) + token = request.headers.get('token', None) + application_uuid = request.headers.get('application-uuid', None) + _session = refresh_session(session_id, token, application_uuid) + if _session is None: + return Response(json.dumps({'error': 'unauthorized'}), status=403) + else: + geometry_file = request.files['geometry_file'] + if not self._allowed_extensions(geometry_file): + return Response(json.dumps({'error': 'Unsupported media type'}), status=415, headers=token) +