uapi/uapi/init.py
2026-07-01 13:55:22 +08:00

68 lines
1.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from ahserver.serverenv import ServerEnv
from sqlor.dbpools import get_sor_context
from .appapi import (
UAPI,
deerer,
sor_get_uapi_by_appname_apiname,
bearer,
get_callerid,
sor_get_callerid,
get_deerer
)
from .uptask import (
check_uptask_status,
get_my_uptasks,
uptask_feedback,
uptask_started
)
from .uapi import UpAppApi
from .apidata import UAPIData
async def get_upapps_for_copy(request):
"""获取所有upapp供复制API时选择目标排除源upapp"""
source_upappid = (request._run_ns.params_kw or {}).get('upappid', '')
env = ServerEnv()
async with get_sor_context(env, 'uapi') as sor:
sql = "select id as value, name as text from upapp"
ns = {}
if source_upappid:
sql += " where id != ${source_upappid}$"
ns['source_upappid'] = source_upappid
recs = await sor.sqlExe(sql, ns)
return recs
def load_uapi():
g = ServerEnv()
g.UAPI = UAPI
g.UpAppApi = UpAppApi
g.uapi_data = UAPIData()
g.get_deerer = get_deerer
g.deerer = deerer
g.get_callerid = get_callerid
g.sor_get_callerid = sor_get_callerid
g.sor_get_uapi_by_appname_apiname = sor_get_uapi_by_appname_apiname
g.bearer = bearer
g.check_uptask_status = check_uptask_status
g.get_my_uptasks = get_my_uptasks
g.uptask_feedback = uptask_feedback
g.uptask_started = uptask_started
g.get_upapps_for_copy = get_upapps_for_copy
# Bind hot_reload event — instance method, WeakMethod safe (stored on g)
if hasattr(g, 'event_dispatcher'):
g.event_dispatcher.bind('hot_reload', g.uapi_data.on_hot_reload)
# USAGE in dspy
## uapi = UAPI(request, DictObject(**globals()))
## d = uapi.request(upappid, apiname. user, params_kw)
## use d in your following code
# bearer usage
## in your header template
## {{bearer(apikey)}}
# deerer usge
## in your header template
## {{deerer(myappid, apikey, secretkey)}}