bugfix
This commit is contained in:
parent
1c7807ac63
commit
2881257d09
@ -9,7 +9,7 @@ from appPublic.folderUtils import ProgramPath
|
|||||||
from appPublic.dictObject import DictObject
|
from appPublic.dictObject import DictObject
|
||||||
from appPublic.jsonConfig import getConfig
|
from appPublic.jsonConfig import getConfig
|
||||||
from appPublic.log import info, debug, warning, error, critical, exception
|
from appPublic.log import info, debug, warning, error, critical, exception
|
||||||
from appPublic.registerfunction import RegisterCoroutine
|
from appPublic.registerfunction import RegisterFunction
|
||||||
|
|
||||||
from sqlor.dbpools import DBPools
|
from sqlor.dbpools import DBPools
|
||||||
|
|
||||||
@ -24,6 +24,7 @@ from .real_ip import real_ip_middleware
|
|||||||
|
|
||||||
class AHApp(web.Application):
|
class AHApp(web.Application):
|
||||||
def __init__(self, *args, **kw):
|
def __init__(self, *args, **kw):
|
||||||
|
if not kw.get('client_max_size'):
|
||||||
kw['client_max_size'] = 1024000000
|
kw['client_max_size'] = 1024000000
|
||||||
super().__init__(*args, **kw)
|
super().__init__(*args, **kw)
|
||||||
self.user_data = DictObject()
|
self.user_data = DictObject()
|
||||||
@ -36,7 +37,7 @@ class AHApp(web.Application):
|
|||||||
return self.user_data.get(k)
|
return self.user_data.get(k)
|
||||||
|
|
||||||
class ConfiguredServer:
|
class ConfiguredServer:
|
||||||
def __init__(self, auth_klass=AuthAPI, workdir=None):
|
def __init__(self, auth_klass=AuthAPI, workdir=None, app=None):
|
||||||
self.auth_klass = auth_klass
|
self.auth_klass = auth_klass
|
||||||
self.workdir = workdir
|
self.workdir = workdir
|
||||||
if self.workdir is not None:
|
if self.workdir is not None:
|
||||||
@ -54,13 +55,16 @@ class ConfiguredServer:
|
|||||||
if config.website.client_max_size:
|
if config.website.client_max_size:
|
||||||
client_max_size = config.website.client_max_size
|
client_max_size = config.website.client_max_size
|
||||||
|
|
||||||
|
if app:
|
||||||
|
self.app = app
|
||||||
|
else:
|
||||||
self.app = AHApp(client_max_size=client_max_size)
|
self.app = AHApp(client_max_size=client_max_size)
|
||||||
load_plugins(self.workdir)
|
load_plugins(self.workdir)
|
||||||
g = ServerEnv()
|
g = ServerEnv()
|
||||||
g.workdir = workdir
|
g.workdir = workdir
|
||||||
|
|
||||||
async def build_app(self):
|
async def build_app(self):
|
||||||
rf = RegisterCoroutine()
|
rf = RegisterFunction()
|
||||||
await rf.exe('ahapp_built', self.app)
|
await rf.exe('ahapp_built', self.app)
|
||||||
auth = self.auth_klass()
|
auth = self.auth_klass()
|
||||||
await auth.setupAuth(self.app)
|
await auth.setupAuth(self.app)
|
||||||
@ -88,7 +92,7 @@ class ConfiguredServer:
|
|||||||
|
|
||||||
def configPath(self,config):
|
def configPath(self,config):
|
||||||
for p,prefix in config.website.paths:
|
for p,prefix in config.website.paths:
|
||||||
res = ProcessorResource(prefix,p,show_index=True,
|
res = ProcessorResource(prefix, p, show_index=True,
|
||||||
follow_symlinks=True,
|
follow_symlinks=True,
|
||||||
indexes=config.website.indexes,
|
indexes=config.website.indexes,
|
||||||
processors=config.website.processors)
|
processors=config.website.processors)
|
||||||
|
|||||||
@ -76,7 +76,7 @@ def i18nDICT(request):
|
|||||||
return json.dumps(i18n.getLangDict(l)).encode(c.website.coding)
|
return json.dumps(i18n.getLangDict(l)).encode(c.website.coding)
|
||||||
|
|
||||||
class ProcessorResource(StaticResource,Url2File):
|
class ProcessorResource(StaticResource,Url2File):
|
||||||
def __init__(self, prefix: str, directory: PathLike,
|
def __init__(self, prefix: str, directory: str,
|
||||||
*, name: Optional[str]=None,
|
*, name: Optional[str]=None,
|
||||||
expect_handler: Optional[_ExpectHandler]=None,
|
expect_handler: Optional[_ExpectHandler]=None,
|
||||||
chunk_size: int=256 * 1024,
|
chunk_size: int=256 * 1024,
|
||||||
@ -84,14 +84,14 @@ class ProcessorResource(StaticResource,Url2File):
|
|||||||
append_version: bool=False,
|
append_version: bool=False,
|
||||||
indexes:list=[],
|
indexes:list=[],
|
||||||
processors:dict={}) -> None:
|
processors:dict={}) -> None:
|
||||||
StaticResource.__init__(self,prefix, directory,
|
StaticResource.__init__(self, prefix, directory,
|
||||||
name=name,
|
name=name,
|
||||||
expect_handler=expect_handler,
|
expect_handler=expect_handler,
|
||||||
chunk_size=chunk_size,
|
chunk_size=chunk_size,
|
||||||
show_index=show_index,
|
show_index=show_index,
|
||||||
follow_symlinks=follow_symlinks,
|
follow_symlinks=follow_symlinks,
|
||||||
append_version=append_version)
|
append_version=append_version)
|
||||||
Url2File.__init__(self,directory,prefix,indexes,inherit=True)
|
Url2File.__init__(self, directory, prefix, indexes, inherit=True)
|
||||||
gr = self._routes.get('GET')
|
gr = self._routes.get('GET')
|
||||||
self._routes.update({'POST':gr})
|
self._routes.update({'POST':gr})
|
||||||
self._routes.update({'PUT':gr})
|
self._routes.update({'PUT':gr})
|
||||||
|
|||||||
@ -21,6 +21,19 @@ class Url2File:
|
|||||||
break
|
break
|
||||||
return '/'.join(items)
|
return '/'.join(items)
|
||||||
|
|
||||||
|
def get_ospath_by_webpath(self, path:str) -> str:
|
||||||
|
paths = url.split('/')
|
||||||
|
f = os.path.join(self.rootpath, *paths)
|
||||||
|
if not os.path.exists(f):
|
||||||
|
return None
|
||||||
|
if os.path.isdir(f):
|
||||||
|
for idx in self.indexes:
|
||||||
|
p = os.path.join(real_path,idx)
|
||||||
|
if os.path.isfile(p):
|
||||||
|
return p
|
||||||
|
return None
|
||||||
|
return f
|
||||||
|
|
||||||
def url2ospath(self, url: str) -> str:
|
def url2ospath(self, url: str) -> str:
|
||||||
url = url.split('?')[0]
|
url = url.split('?')[0]
|
||||||
if len(url) > 0 and url[-1] == '/':
|
if len(url) > 0 and url[-1] == '/':
|
||||||
|
|||||||
@ -7,16 +7,16 @@ from ahserver.configuredServer import ConfiguredServer
|
|||||||
from ahserver.serverenv import ServerEnv
|
from ahserver.serverenv import ServerEnv
|
||||||
from appPublic.jsonConfig import getConfig
|
from appPublic.jsonConfig import getConfig
|
||||||
|
|
||||||
def webapp(init_func):
|
def webapp(init_func, app=None):
|
||||||
parser = argparse.ArgumentParser(prog="Sage")
|
parser = argparse.ArgumentParser(prog="Sage")
|
||||||
parser.add_argument('-w', '--workdir')
|
parser.add_argument('-w', '--workdir')
|
||||||
parser.add_argument('-p', '--port')
|
parser.add_argument('-p', '--port')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
workdir = args.workdir or os.getcwd()
|
workdir = args.workdir or os.getcwd()
|
||||||
port = args.port
|
port = args.port
|
||||||
webserver(init_func, workdir, port)
|
webserver(init_func, workdir, port=port, app=app)
|
||||||
|
|
||||||
def webserver(init_func, workdir, port=None):
|
def webserver(init_func, workdir, port=None, app=None):
|
||||||
p = ProgramPath()
|
p = ProgramPath()
|
||||||
config = getConfig(workdir, NS={'workdir':workdir, 'ProgramPath':p})
|
config = getConfig(workdir, NS={'workdir':workdir, 'ProgramPath':p})
|
||||||
if config.logger:
|
if config.logger:
|
||||||
@ -29,7 +29,7 @@ def webserver(init_func, workdir, port=None):
|
|||||||
se = ServerEnv()
|
se = ServerEnv()
|
||||||
se.workdir = workdir
|
se.workdir = workdir
|
||||||
se.port = port
|
se.port = port
|
||||||
server = ConfiguredServer(workdir=workdir)
|
server = ConfiguredServer(workdir=workdir, app=app)
|
||||||
port = port or config.website.port or 8080
|
port = port or config.website.port or 8080
|
||||||
port = int(port)
|
port = int(port)
|
||||||
server.run(port=port)
|
server.run(port=port)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user