This commit is contained in:
pengtao 2021-12-22 10:08:42 +08:00
parent a5d178031b
commit 5389226e6a

39
main.py
View File

@ -41,6 +41,10 @@ orderby_list = {
6: "price", # 当前价格 6: "price", # 当前价格
7: "mcScore" # 评分 7: "mcScore" # 评分
} }
dirty_stuff = [
"\"", "\\", "/", "*", "'", "=", "-", "#", ";", "<", ">", "+", "&", "$",
"(", ")", "%", "@"
]
def create_app(): def create_app():
@ -88,6 +92,13 @@ async def getPlatform(request: Request, platformAlias: str):
) )
def check_dirty(strings: str) -> bool:
for key in dirty_stuff:
if key in str(strings):
return True
return False
@app.get("/getgamelist") @app.get("/getgamelist")
async def getgamelist(request: Request, async def getgamelist(request: Request,
category: str = '', category: str = '',
@ -100,6 +111,12 @@ async def getgamelist(request: Request,
limit: int = 10, limit: int = 10,
orderbyid: int = 1): orderbyid: int = 1):
db = request.app.state.mongo db = request.app.state.mongo
if check_dirty(category) or check_dirty(gameids) or check_dirty(
name) or check_dirty(platform):
return JSONResponse(
status_code=starlette.status.HTTP_500_INTERNAL_SERVER_ERROR,
content="args check failed!",
)
try: try:
find_args = {} find_args = {}
@ -169,6 +186,11 @@ async def getgamelist(request: Request,
@app.get("/getgameinfo") @app.get("/getgameinfo")
async def getgameinfo(request: Request, oldGameId: int = 0, name: str = ""): async def getgameinfo(request: Request, oldGameId: int = 0, name: str = ""):
if check_dirty(name) or check_dirty(oldGameId):
return JSONResponse(
status_code=starlette.status.HTTP_500_INTERNAL_SERVER_ERROR,
content="args check failed!",
)
db = request.app.state.mongo db = request.app.state.mongo
if oldGameId: if oldGameId:
gameinfo = db["gameinfo"].find({"oldGameId": oldGameId}, {"_id": 0}) gameinfo = db["gameinfo"].find({"oldGameId": oldGameId}, {"_id": 0})
@ -189,6 +211,11 @@ async def getgameinfo(request: Request, oldGameId: int = 0, name: str = ""):
@app.get("/getgameprice") @app.get("/getgameprice")
async def getgameprice(request: Request, oldGameId: int, nums: int = 0): async def getgameprice(request: Request, oldGameId: int, nums: int = 0):
if check_dirty(oldGameId):
return JSONResponse(
status_code=starlette.status.HTTP_500_INTERNAL_SERVER_ERROR,
content="args check failed!",
)
db = request.app.state.mongo db = request.app.state.mongo
if nums == 0: if nums == 0:
gameprice = db["gameprice"].find_one({"oldGameId": oldGameId}, gameprice = db["gameprice"].find_one({"oldGameId": oldGameId},
@ -201,7 +228,7 @@ async def getgameprice(request: Request, oldGameId: int, nums: int = 0):
gameprice['prices'] = price[:nums] gameprice['prices'] = price[:nums]
else: else:
logger.error(f"get price with {oldGameId} failed\n {gameprice}") logger.error(f"get price with {oldGameId} failed\n {gameprice}")
gameprice = {} gameprice = {"prices": []}
logger.info(f"get gameprice with {oldGameId} !") logger.info(f"get gameprice with {oldGameId} !")
return JSONResponse( return JSONResponse(
@ -212,6 +239,11 @@ async def getgameprice(request: Request, oldGameId: int, nums: int = 0):
@app.get("/getgameinfoext") @app.get("/getgameinfoext")
async def getgameinfoext(request: Request, oldGameId: int): async def getgameinfoext(request: Request, oldGameId: int):
if check_dirty(oldGameId):
return JSONResponse(
status_code=starlette.status.HTTP_500_INTERNAL_SERVER_ERROR,
content="args check failed!",
)
db = request.app.state.mongo db = request.app.state.mongo
gameinfoext = db["gameinfoext"].find_one({"oldGameId": oldGameId}, gameinfoext = db["gameinfoext"].find_one({"oldGameId": oldGameId},
{"_id": 0}) {"_id": 0})
@ -239,6 +271,11 @@ async def getgameinfoext(request: Request, oldGameId: int):
@app.get("/gethistoryprice") @app.get("/gethistoryprice")
async def gethistoryprice(request: Request, oldGameId: int): async def gethistoryprice(request: Request, oldGameId: int):
if check_dirty(oldGameId):
return JSONResponse(
status_code=starlette.status.HTTP_500_INTERNAL_SERVER_ERROR,
content="args check failed!",
)
db = request.app.state.mongo db = request.app.state.mongo
history_price = db["history_price"].find_one({"oldGameId": oldGameId}, history_price = db["history_price"].find_one({"oldGameId": oldGameId},
{"_id": 0}) {"_id": 0})