|
|
|
|
@ -18,6 +18,7 @@ import pandas as pd
|
|
|
|
|
|
|
|
|
|
class RequestController :
|
|
|
|
|
def __init__(self,_route):
|
|
|
|
|
# self._plugins = _plugins
|
|
|
|
|
self._routes = _route
|
|
|
|
|
def isfile(self,request):
|
|
|
|
|
#
|
|
|
|
|
@ -99,6 +100,11 @@ class Initialization (IOConfig):
|
|
|
|
|
# self._config = self.read_config(**_args)
|
|
|
|
|
self._args = _args
|
|
|
|
|
#
|
|
|
|
|
# in case the path provided does NOT have the manifest
|
|
|
|
|
if 'path' in self._args and not os.path.isfile(self._args['path']) :
|
|
|
|
|
#
|
|
|
|
|
self._args['path'] = f"{self._args['path']}{os.sep}qcms-manifest.json"
|
|
|
|
|
#
|
|
|
|
|
# Invoke initialization
|
|
|
|
|
self.reload()
|
|
|
|
|
#
|
|
|
|
|
@ -225,9 +231,11 @@ class Initialization (IOConfig):
|
|
|
|
|
|
|
|
|
|
self.set('system.icon',_icon)
|
|
|
|
|
self.set('system.logo',_icon)
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# from the path provided we can determine the location of the project
|
|
|
|
|
_homefolder = os.sep.join(_args['path'].split(os.sep)[:-1])
|
|
|
|
|
|
|
|
|
|
if _homefolder and os.path.exists(os.sep.join([_homefolder,_root])) :
|
|
|
|
|
self.set('layout.location',_homefolder)
|
|
|
|
|
|
|
|
|
|
@ -310,6 +318,20 @@ class Initialization (IOConfig):
|
|
|
|
|
# self._config['layout']['menu'] = _menu
|
|
|
|
|
else:
|
|
|
|
|
pass
|
|
|
|
|
def _api(self):
|
|
|
|
|
"""
|
|
|
|
|
This function will update public facing api provided
|
|
|
|
|
"""
|
|
|
|
|
_context = self.get('system.context')
|
|
|
|
|
_plugins = self.get('plugins')
|
|
|
|
|
for _key in ['debug','log'] :
|
|
|
|
|
_pointer = getattr(self,_key)
|
|
|
|
|
_uri = f'{_context}/api/system/{_key}'
|
|
|
|
|
if _uri[0] == '/' :
|
|
|
|
|
_uri = _uri[1:]
|
|
|
|
|
_plugins[_uri] = _pointer
|
|
|
|
|
self.set('plugins',_plugins)
|
|
|
|
|
|
|
|
|
|
def plugins (self,**_args):
|
|
|
|
|
"""
|
|
|
|
|
This function will load the plugins from disk (only)
|
|
|
|
|
@ -319,15 +341,18 @@ class Initialization (IOConfig):
|
|
|
|
|
_parentContext = self.get('system.parentContext')
|
|
|
|
|
_map = {}
|
|
|
|
|
_plugins = {}
|
|
|
|
|
|
|
|
|
|
# if self.get('system.source.id') == 'cloud' :
|
|
|
|
|
# _plugins = cloud.plugins(_context)
|
|
|
|
|
# else:
|
|
|
|
|
# _plugins = disk.plugins(context=_context)
|
|
|
|
|
_uri = f'{_context}/api/system/debug'
|
|
|
|
|
if _uri.startswith('/') :
|
|
|
|
|
_uri = _uri[1:]
|
|
|
|
|
# _uri = _uri if not _context else f'{_context}/{_uri}'
|
|
|
|
|
_plugins[_uri] = self.debug
|
|
|
|
|
# _uri = f'{_context}/api/system/debug'
|
|
|
|
|
# if _uri.startswith('/') :
|
|
|
|
|
# _uri = _uri[1:]
|
|
|
|
|
# # _uri = _uri if not _context else f'{_context}/{_uri}'
|
|
|
|
|
# _plugins[_uri] = self.debug
|
|
|
|
|
|
|
|
|
|
self._api() #-- adding default api calls
|
|
|
|
|
if os.path.exists(_folder) and self.get('plugins'):
|
|
|
|
|
|
|
|
|
|
_items = self.get('plugins')
|
|
|
|
|
@ -360,11 +385,14 @@ class Initialization (IOConfig):
|
|
|
|
|
#
|
|
|
|
|
# Updating plugins from disk/cloud
|
|
|
|
|
_plugins = _map if not _plugins else dict(_plugins,**_map)
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# if we have login enabled we should add them as a plugins
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
self.set('plugins',_plugins)
|
|
|
|
|
self._api() #-- updating with system level api
|
|
|
|
|
|
|
|
|
|
self.log(action='init.plugins',module='plugins',input=list(_plugins.keys()))
|
|
|
|
|
|
|
|
|
|
class Site(Initialization) :
|
|
|
|
|
@ -431,11 +459,12 @@ class Site(Initialization) :
|
|
|
|
|
# _content = f'<div>{_content}</div>'
|
|
|
|
|
if _uri.split('.')[-1].strip().lower() == 'md':
|
|
|
|
|
_content = mistune.html(_content).replace(""",'"').replace("<","<").replace(">",">") if _uri[-2:] in ['md','MD','Md','mD'] else _content
|
|
|
|
|
_content = f"<div>{_content}</div>" #if 'dom' not in _request.headers else f'<div id="{_request.headers['dom']}">{_content}</div>'
|
|
|
|
|
# _content = f"<div>{_content}</div>" #if 'dom' not in _request.headers else f'<div id="{_request.headers['dom']}">{_content}</div>'
|
|
|
|
|
else:
|
|
|
|
|
_env = Environment(loader=BaseLoader()).from_string(_content)
|
|
|
|
|
_env = Environment(loader=BaseLoader()).from_string(f"<div>{_content}</div>")
|
|
|
|
|
_content = str(_env.render(**self.get(None)))
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
return _content,_mimeType
|
|
|
|
|
def uri(self,request):
|
|
|
|
|
if 'uri' in request.headers or 'uri' in request.args :
|
|
|
|
|
@ -447,6 +476,7 @@ class Site(Initialization) :
|
|
|
|
|
#
|
|
|
|
|
file = request.path.replace(f'{_route}','')
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
if file.startswith('//') or file.startswith('/') :
|
|
|
|
|
# NOTE: false positive if file.startswith('/') is used
|
|
|
|
|
file = file[2:] if file.startswith('//') else file[1:]
|
|
|
|
|
@ -502,6 +532,7 @@ class Site(Initialization) :
|
|
|
|
|
# _content = io.BytesIO(f.read())
|
|
|
|
|
|
|
|
|
|
# f.close()
|
|
|
|
|
|
|
|
|
|
_content = self.open(uri=self.path(_uri),mode='rb')
|
|
|
|
|
_content = io.BytesIO( _content )
|
|
|
|
|
_kwargs = {'allow':1,'mimeType':_mimeType,'extension':_extension,
|
|
|
|
|
@ -510,7 +541,7 @@ class Site(Initialization) :
|
|
|
|
|
self.log(action='file.read',module='site.read',input=_kwargs)
|
|
|
|
|
if _content :
|
|
|
|
|
return _content, _mimeType
|
|
|
|
|
return None, 'plain/html'
|
|
|
|
|
return None, 'text/html'
|
|
|
|
|
# if 'html' in _mimetype :
|
|
|
|
|
|
|
|
|
|
# _args = {'layout':self.get('layout'),'system':self.get('system')}
|
|
|
|
|
@ -554,6 +585,7 @@ class Site(Initialization) :
|
|
|
|
|
return None
|
|
|
|
|
def apply_tags (self,_html):
|
|
|
|
|
_kwargs = {'layout':self.get('layout'),'system':self.get('system')}
|
|
|
|
|
|
|
|
|
|
_env = Environment(loader=BaseLoader()).from_string(f'<div>{_html}</div>')
|
|
|
|
|
return _env.render(**_kwargs)
|
|
|
|
|
def run(self,_request) :
|
|
|
|
|
@ -562,8 +594,6 @@ class Site(Initialization) :
|
|
|
|
|
_mimeType = 'text/html'
|
|
|
|
|
_code = 404
|
|
|
|
|
_key = _request.path[1:] #if self.get('system.context') != '' else _request.path[1:]
|
|
|
|
|
# print ([_key,_key in list(_plugins.keys())])
|
|
|
|
|
# print (list (_plugins.keys()))
|
|
|
|
|
if _plugins and _key in _plugins:
|
|
|
|
|
_mimeType = 'application/octet-stream'
|
|
|
|
|
_pointer = _plugins.get(_key)
|
|
|
|
|
@ -606,6 +636,7 @@ class QCMS:
|
|
|
|
|
for _name in _routes :
|
|
|
|
|
self._routes.append(_name)
|
|
|
|
|
_path = _routes[_name]['path']
|
|
|
|
|
|
|
|
|
|
self._sites[_name] = Site(context=_name,path=_path,caller=_app)
|
|
|
|
|
# self._sites[f'{_name}/'] = self._sites[_name]
|
|
|
|
|
|
|
|
|
|
@ -623,6 +654,7 @@ class QCMS:
|
|
|
|
|
isfile = self.inspect.isfile(request)
|
|
|
|
|
isapi = self.inspect.isapi(request)
|
|
|
|
|
isroute= self.inspect.isroute(request)
|
|
|
|
|
|
|
|
|
|
if not isapi and not isfile:
|
|
|
|
|
return self._render(request)
|
|
|
|
|
#
|
|
|
|
|
|