This commit is contained in:
yumoqing 2025-10-11 12:11:53 +08:00
parent e636fbd81b
commit 817a2b9639

View File

@ -123,13 +123,13 @@ class UAPI:
self.auth_ret = None
self.sor = sor
def rendertmpl(self, tmplstr, params={}):
async def rendertmpl(self, tmplstr, params={}):
if tmplstr is None:
return None
ns = self.env.copy()
ns.update(params)
te = MyTemplateEngine([], env=self.env)
return te.renders(tmplstr, ns)
te = self.env.tmpl_engine
return await te.renders(tmplstr, ns)
async def get_uapis(self, sor, upappid, apiname, callerid, params={}):
self.env.update(params)
@ -186,7 +186,7 @@ class UAPI:
if self.uapi.response:
try:
dic = json.loads(line)
line = self.rendertmpl(self.uapi.response, dic)
line = await self.rendertmpl(self.uapi.response, dic)
line = self.filter_nl_cr(line)
except Exception as e:
debug(f'{line=}, {self.uapi.response=} error({e})\n{format_exc()}')
@ -202,7 +202,7 @@ class UAPI:
b += chunk
if self.uapi.response:
dic = json.loads(b.decode('utf-8'))
s = self.rendertmpl(self.uapi.response, dic)
s = await self.rendertmpl(self.uapi.response, dic)
b = s.encode('utf-8')
return b
@ -212,22 +212,22 @@ class UAPI:
b+= chunk
d = json.loads(b.encode('utf-8'))
if auth_uapi.response:
s = self.rendertmpl(auth_uapi.response, d)
s = await self.rendertmpl(auth_uapi.response, d)
d = json.loads(s)
self.env.update(d)
return
async def stream_resp(self, api):
path = self.rendertmpl(api.path)
path = await self.rendertmpl(api.path)
url = self.env.get('baseurl') + path
method = api.httpmethod
headers = self.rendertmpl(api.headers)
headers = await self.rendertmpl(api.headers)
try:
headers = json.loads(headers)
except Exception as e:
exception(f'{e}, {headers=},{api.headers=}')
raise e
body = self.rendertmpl(api.data)
body = await self.rendertmpl(api.data)
if body:
try:
bdy = json.loads(body)
@ -235,7 +235,7 @@ class UAPI:
except Exception as e:
exception(f'{e}, {body=},{api.data=}')
body = None
_params = self.rendertmpl(api.params)
_params = await self.rendertmpl(api.params)
if _params:
_params = json.loads(_params)
debug(f'{headers=}, {body=}. {method=}, {url=}')