2026-05-08 10:54:33 +08:00

55 lines
1.3 KiB
Plaintext

upappid = 'wetokenai'
apiname = 'upload_asset'
uapi = UpAppApi(request)
env = request._run_ns
userid = None
async with get_sor_context(env, 'llmage') as sor:
recs = await sor.R('upapp', {'id': upappid})
if len(recs) < 1:
exception(f'{upappid=} upapp not found')
return {
'status': 'FAILED',
'error': f'{upappid=} upapp not found'
}
userid = await sor_get_callerid(sor, recs[0].ownerid)
if userid is None:
return {
'status': 'FAILED',
'error': f'sor_get_callerid() error'
}
try:
name = params_kw.name
if name is None:
return {
"status": "FAILED",
"error": "name is None"
}
if media_file is None:
return {
"status": "FAILED",
"error": "media_file is None"
}
assetType = params_kw.assetType
if assetType is None:
typ = media_file.split('.')[-1]
if typ in ['png', 'webp', 'jpg', 'gif']:
assetType = 'Image'
elif typ in ['mp4', 'mov', 'avi']:
assetType = 'Video'
elif type in ['mp3', 'wav', 'aac']:
assetType = 'Audio'
else:
assetType = None
params_kw.assetType = assetType
b = await uapi.call(upappid, apiname, userid, params=params_kw)
if isinstance(b, bytes):
b = b.decode('utf-8')
d = json.loads(b)
return d
except Exception as e:
exception(f'{e}, {format_exc()}')
return {
'status': 'FAILED',
'error': f'{e}'
}