Merge branch 'master' of git.kaiyuancloud.cn:yumoqing/ahserver

This commit is contained in:
yumoqing 2025-04-14 14:19:11 +08:00
commit b58bb334d5
6 changed files with 28 additions and 10 deletions

View File

@ -17,6 +17,7 @@ from .processorResource import ProcessorResource
from .auth_api import AuthAPI
from .myTE import setupTemplateEngine
from .globalEnv import initEnv
from .serverenv import ServerEnv
from .filestorage import TmpFileRecord
from .loadplugins import load_plugins
@ -53,6 +54,8 @@ class ConfiguredServer:
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()

View File

@ -36,7 +36,7 @@ async def file_handle(request, filepath, download=False):
return r
async def file_download(request, filepath):
return file_handler(request, filepath, download=True)
return await file_handle(request, filepath, download=True)
async def path_download(request, kw, *params):
path = kw.get('path')
@ -51,7 +51,3 @@ async def path_download(request, kw, *params):
rf = RegisterFunction()
rf.register('idfile', path_download)
rf.register('download', path_download)

View File

@ -39,6 +39,7 @@ from .xlsxData import XLSXData
from .uriop import URIOp
from .error import Success, Error, NeedLogin, NoPermission
from .filetest import current_fileno
from .filedownload import path_download, file_download
from .filestorage import FileStorage
from .serverenv import ServerEnv
@ -192,15 +193,15 @@ def paramify(data, ns):
def get_password_key():
config = getConfig()
return config.password_key or 'QRIVSRHrthhwyjy176556332')
return config.password_key or 'QRIVSRHrthhwyjy176556332'
def password_encode(s, k=None):
def password_encode(s):
k = get_password_key()
return password(s, key=k)
def password_decode(c, k=None):
def password_decode(c):
k = get_password_key()
return unpassword_c, key=k)
return unpassword(c, key=k)
def initEnv():
pool = DBPools()
@ -262,6 +263,8 @@ def initEnv():
g.rfexe = RegisterFunction().exe
g.stream_response = stream_response
g.webpath = webpath
g.file_download = file_download
g.path_download = path_download
def set_builtins():
all_builtins = [ i for i in dir(builtins) if not i.startswith('_')]

View File

@ -31,6 +31,7 @@ from aiohttp.web_fileresponse import FileResponse
from aiohttp.web_request import Request
from aiohttp.web_response import Response, StreamResponse
from aiohttp.web_routedef import AbstractRouteDef
from aiohttp_session import get_session
from appPublic.jsonConfig import getConfig
from appPublic.dictObject import DictObject
@ -251,6 +252,9 @@ class ProcessorResource(StaticResource,Url2File):
username=username,
userorgid=userorgid)
async def getsession():
return await get_session(request)
async def remember_ticket(ticket):
await auth.remember_ticket(request, ticket)
@ -278,6 +282,7 @@ class ProcessorResource(StaticResource,Url2File):
self.parse_request(request)
self.y_env.i18n = serveri18n
self.y_env.get_session = getsession
self.y_env.file_realpath = file_realpath
self.y_env.redirect = redirect
self.y_env.info = info

View File

@ -28,12 +28,18 @@ class ProxyProcessor(BaseProcessor):
auth = None
if d.get('user') and d.get('password'):
auth = BasicAuth(d['user'], d['password'])
if g.get('headers'):
regH.update(d['headers'])
params = None
if d.get('params'):
params = params
async with client.request(
request.method,
d.get('method', request.method),
d['url'],
auth=auth,
headers = reqH,
allow_redirects=False,
params=paams,
data=await request.read()) as res:
headers = res.headers.copy()
# body = await res.read()

View File

@ -223,6 +223,11 @@ class WebsocketProcessor(PythonScriptProcessor):
return name=='ws'
async def path_call(self, request,params={}):
cookie = request.headers.get('Sec-WebSocket-Protocol', None)
if cookie:
request.headers['Cookies'] = cookie
userid = await get_user()
debug(f'{cookie=}, {userid=}')
await self.set_run_env(request)
lenv = self.run_ns.copy()
lenv.update(params)