Skip to content

Commit

Permalink
Merge pull request #9 from Valorant-Shop-CN/develop
Browse files Browse the repository at this point in the history
chome(1.1.1): release v1.1.1
  • Loading branch information
musnows authored Mar 6, 2023
2 parents 986df07 + edf4d57 commit 1ab9e3c
Show file tree
Hide file tree
Showing 17 changed files with 569 additions and 529 deletions.
40 changes: 20 additions & 20 deletions code/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from aiohttp import web
from utils.Gtime import GetTime
from utils.api import ApiHandler
from utils.log.Logging import _log

# 初始化节点
routes = web.RouteTableDef()
Expand All @@ -11,7 +12,7 @@
# 基础返回
@routes.get('/')
async def hello_world(request): # put application's code here
print(f"[{GetTime()}] [request] /")
_log.info(f"request | root-url")
return web.Response(body=json.dumps(
{
'code': 0,
Expand All @@ -30,14 +31,14 @@ async def hello_world(request): # put application's code here
# 提供4个皮肤uuid,返回图片
@routes.get('/shop-draw')
async def get_shop_draw(request):
print(f"[{GetTime()}] [request] /shop-draw")
_log.info(f"request | /shop-draw")
try:
ret = await ApiHandler.img_draw_request(request)
return web.Response(body=json.dumps(ret, indent=2, sort_keys=True, ensure_ascii=False),
content_type='application/json',status=200)
except:
err_cur = traceback.format_exc()
print(f"[{GetTime()}] [Api] ERR in /shop\n{err_cur}")
_log.exception("Exception in /shop-draw")
return web.Response(body=json.dumps(
{
'code': 200,
Expand All @@ -55,7 +56,7 @@ async def get_shop_draw(request):
# 直接跳转图片(浏览器访问,get方法不安全)
@routes.get('/shop-img')
async def get_shop_img(request):
print(f"[{GetTime()}] [request] /shop-img")
_log.info(f"request | /shop-img")
try:
ret = await ApiHandler.login_request(request,"GET")
if ret['code'] == 0:
Expand All @@ -65,7 +66,7 @@ async def get_shop_img(request):
content_type='application/json',status=200)
except:
err_cur = traceback.format_exc()
print(f"[{GetTime()}] [Api] ERR in /shop-img\n{err_cur}")
_log.exception("Exception in /shop-img")
return web.Response(body=json.dumps(
{
'code': 200,
Expand All @@ -83,14 +84,14 @@ async def get_shop_img(request):
# 登录接口
@routes.post('/login')
async def post_login(request):
print(f"[{GetTime()}] [request] /login")
_log.info(f"request | /login")
try:
ret = await ApiHandler.login_request(request,"POST")
return web.Response(body=json.dumps(ret, indent=2, sort_keys=True, ensure_ascii=False),
content_type='application/json',status=200)
except:
err_cur = traceback.format_exc()
print(f"[{GetTime()}] [Api] ERR in /shop\n{err_cur}")
_log.exception("Exception in /login")
return web.Response(body=json.dumps(
{
'code': 200,
Expand All @@ -107,14 +108,14 @@ async def post_login(request):
# 邮箱验证登录
@routes.post('/tfa')
async def post_tfa_code(request):
print(f"[{GetTime()}] [request] /tfa")
_log.info(f"request | /tfa")
try:
ret = await ApiHandler.tfa_code_requeset(request)
return web.Response(body=json.dumps(ret, indent=2, sort_keys=True, ensure_ascii=False),
content_type='application/json',status=200)
except:
err_cur = traceback.format_exc()
print(f"[{GetTime()}] [Api] ERR in /tfa\n{err_cur}")
_log.exception("Exception in /tfa")
return web.Response(body=json.dumps(
{
'code': 200,
Expand All @@ -130,13 +131,13 @@ async def post_tfa_code(request):

@routes.post('/shop')
async def post_shop(request):
print(f"[{GetTime()}] [request] /shop")
_log.info(f"request | /shop")
try:
body = await request.content.read()
params = json.loads(body.decode('UTF8'))
# 判断必须要的参数是否齐全
if 'account' not in params or 'token' not in params: # 不全,报错
print(f"ERR! [{GetTime()}] params needed: token/account/passwd")
_log.error(f"params needed: token/account/passwd")
ret = {
'code': 400,
'message': 'params needed: token/account/passwd',
Expand All @@ -151,7 +152,7 @@ async def post_shop(request):
content_type='application/json',status=200)
except:
err_cur = traceback.format_exc()
print(f"[{GetTime()}] [Api] ERR in /shop\n{err_cur}")
_log.exception("Exception in /shop")
return web.Response(body=json.dumps(
{
'code': 200,
Expand All @@ -168,14 +169,14 @@ async def post_shop(request):
# 用于控制db中ShopCmp的更新
@routes.post('/shop-cmp')
async def post_shop_cmp(request):
print(f"[{GetTime()}] [request] /shop-cmp")
_log.info(f"request | /shop-cmp")
try:
ret = await ApiHandler.shop_cmp_request(request)
return web.Response(body=json.dumps(ret, indent=2, sort_keys=True, ensure_ascii=False),
content_type='application/json',status=200)
except:
err_cur = traceback.format_exc()
print(f"[{GetTime()}] [Api] ERR in /shop-cmp\n{err_cur}")
_log.exception("Exception in /shop-cmp")
return web.Response(body=json.dumps(
{
'code': 200,
Expand All @@ -192,17 +193,16 @@ async def post_shop_cmp(request):


# 爱发电的wh
from main import bot
from utils.FileManage import bot
@routes.post('/afd')
async def aifadian_webhook(request):
print(f"[{GetTime()}] [request] /afd")
_log.info(f"request | /afd")
try:
ret = await ApiHandler.afd_request(request, bot)
return web.Response(body=json.dumps(ret, indent=2, sort_keys=True, ensure_ascii=False),
content_type='application/json')
except:
err_cur = traceback.format_exc()
print(f"[{GetTime()}] [Api] ERR in /afd\n{err_cur}")
_log.exception("Exception in /afd")
return web.Response(body=json.dumps({
"ec": 0,
"em": "err ouccer"
Expand All @@ -214,7 +214,7 @@ async def aifadian_webhook(request):
app.add_routes(routes)
if __name__ == '__main__':
try: # host需要设置成0.0.0.0,否则只有本地才能访问
print(f"[API Start] starting at {GetTime()}")
_log.info(f"API Service Start")
web.run_app(app, host='0.0.0.0', port=14726)
except:
print(traceback.format_exc())
_log.exception("Exception occur")
Loading

0 comments on commit 1ab9e3c

Please sign in to comment.