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.jsonConfig import getConfig
|
||||
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
|
||||
|
||||
@ -24,6 +24,7 @@ from .real_ip import real_ip_middleware
|
||||
|
||||
class AHApp(web.Application):
|
||||
def __init__(self, *args, **kw):
|
||||
if not kw.get('client_max_size'):
|
||||
kw['client_max_size'] = 1024000000
|
||||
super().__init__(*args, **kw)
|
||||
self.user_data = DictObject()
|
||||
@ -36,7 +37,7 @@ class AHApp(web.Application):
|
||||
return self.user_data.get(k)
|
||||
|
||||
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.workdir = workdir
|
||||
if self.workdir is not None:
|
||||
@ -54,13 +55,16 @@ class ConfiguredServer:
|
||||
if 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)
|
||||
load_plugins(self.workdir)
|
||||
g = ServerEnv()
|
||||
g.workdir = workdir
|
||||
|
||||
async def build_app(self):
|
||||
rf = RegisterCoroutine()
|
||||
rf = RegisterFunction()
|
||||
await rf.exe('ahapp_built', self.app)
|
||||
auth = self.auth_klass()
|
||||
await auth.setupAuth(self.app)
|
||||
|
||||
@ -76,7 +76,7 @@ def i18nDICT(request):
|
||||
return json.dumps(i18n.getLangDict(l)).encode(c.website.coding)
|
||||
|
||||
class ProcessorResource(StaticResource,Url2File):
|
||||
def __init__(self, prefix: str, directory: PathLike,
|
||||
def __init__(self, prefix: str, directory: str,
|
||||
*, name: Optional[str]=None,
|
||||
expect_handler: Optional[_ExpectHandler]=None,
|
||||
chunk_size: int=256 * 1024,
|
||||
|
||||
@ -21,6 +21,19 @@ class Url2File:
|
||||
break
|
||||
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:
|
||||
url = url.split('?')[0]
|
||||
if len(url) > 0 and url[-1] == '/':
|
||||
|
||||
@ -7,16 +7,16 @@ from ahserver.configuredServer import ConfiguredServer
|
||||
from ahserver.serverenv import ServerEnv
|
||||
from appPublic.jsonConfig import getConfig
|
||||
|
||||
def webapp(init_func):
|
||||
def webapp(init_func, app=None):
|
||||
parser = argparse.ArgumentParser(prog="Sage")
|
||||
parser.add_argument('-w', '--workdir')
|
||||
parser.add_argument('-p', '--port')
|
||||
args = parser.parse_args()
|
||||
workdir = args.workdir or os.getcwd()
|
||||
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()
|
||||
config = getConfig(workdir, NS={'workdir':workdir, 'ProgramPath':p})
|
||||
if config.logger:
|
||||
@ -29,7 +29,7 @@ def webserver(init_func, workdir, port=None):
|
||||
se = ServerEnv()
|
||||
se.workdir = workdir
|
||||
se.port = port
|
||||
server = ConfiguredServer(workdir=workdir)
|
||||
server = ConfiguredServer(workdir=workdir, app=app)
|
||||
port = port or config.website.port or 8080
|
||||
port = int(port)
|
||||
server.run(port=port)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user