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

This commit is contained in:
yumoqing 2025-06-07 19:36:47 +08:00
commit 88fc36d7e3

View File

@ -270,8 +270,10 @@ class JsonHttpAPI:
jd = json.loads(a) jd = json.loads(a)
await self.user_stream_func(jd) await self.user_stream_func(jd)
async def chunk_handle(self, chunk, chunk_lead, chunk_end):
return chunk
async def __call__(self, url, method='GET', ns={}, async def __call__(self, url, method='GET', ns={},
stream=False,
headerstmpl=None, headerstmpl=None,
paramstmpl=None, paramstmpl=None,
datatmpl=None, datatmpl=None,
@ -279,6 +281,7 @@ class JsonHttpAPI:
chunk_end="[done]", chunk_end="[done]",
resptmpl=None): resptmpl=None):
headers = None headers = None
self.chunk_buffer = ''
ns1 = self.env.copy() ns1 = self.env.copy()
ns1.update(ns) ns1.update(ns)
if headerstmpl: if headerstmpl:
@ -288,16 +291,11 @@ class JsonHttpAPI:
if paramstmpl: if paramstmpl:
params = json.loads(self.te.renders(paramstmpl, ns1)) params = json.loads(self.te.renders(paramstmpl, ns1))
data = None data = None
stream = False
if datatmpl: if datatmpl:
datadic = json.loads(self.te.renders(datatmpl, ns1)) datadic = json.loads(self.te.renders(datatmpl, ns1))
stream = atadic.get('stream', False)
data = json.dumps(datadic, ensure_ascii=False) data = json.dumps(datadic, ensure_ascii=False)
"""
data = FormData()
for k,v in datadic.items():
data.add_field(k, v)
headers['Content-Type'] = 'multipart/form-data'
"""
info(f'{data=},{ns=}, {headers=}')
hc = HttpClient() hc = HttpClient()
async for d in self.hc(url, method=method, async for d in self.hc(url, method=method,
stream=stream, stream=stream,
@ -306,11 +304,11 @@ class JsonHttpAPI:
data=data): data=data):
if stream: if stream:
d = self.chunk_handle(d, chunk_leading, chunk_end) d = self.chunk_handle(d, chunk_leading, chunk_end)
if isinstance(d, dict) and resptmpl: if resptmpl:
ds = self.te.renders(resptmpl, d) dic = json.loads(d)
yield json.loads(ds) ns1.update(dic)
else: d = self.te.renders(resptmpl, ns1)
yield d yield d
async def call(self, url, method='GET', ns={}, async def call(self, url, method='GET', ns={},
stream_func=None, stream_func=None,