This commit is contained in:
yumoqing 2025-05-29 15:32:31 +08:00
parent 003ff36471
commit 9758b24915

View File

@ -268,8 +268,10 @@ class JsonHttpAPI:
jd = json.loads(a)
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={},
stream=False,
headerstmpl=None,
paramstmpl=None,
datatmpl=None,
@ -277,6 +279,7 @@ class JsonHttpAPI:
chunk_end="[done]",
resptmpl=None):
headers = None
self.chunk_buffer = ''
ns1 = self.env.copy()
ns1.update(ns)
if headerstmpl:
@ -286,16 +289,11 @@ class JsonHttpAPI:
if paramstmpl:
params = json.loads(self.te.renders(paramstmpl, ns1))
data = None
stream = False
if datatmpl:
datadic = json.loads(self.te.renders(datatmpl, ns1))
stream = atadic.get('stream', 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()
async for d in self.hc(url, method=method,
stream=stream,
@ -304,11 +302,11 @@ class JsonHttpAPI:
data=data):
if stream:
d = self.chunk_handle(d, chunk_leading, chunk_end)
if isinstance(d, dict) and resptmpl:
ds = self.te.renders(resptmpl, d)
yield json.loads(ds)
else:
yield d
if resptmpl:
dic = json.loads(d)
ns1.update(dic)
d = self.te.renders(resptmpl, ns1)
yield d
async def call(self, url, method='GET', ns={},
stream_func=None,