Skip to content

Commit

Permalink
修正禁用API的报错,更新了在线演示
Browse files Browse the repository at this point in the history
  • Loading branch information
DriverLin committed Jul 11, 2022
1 parent 759b985 commit f06142e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# EXviewer

E站的PWA客户端,于在线浏览,下载以及管理本地画廊。基于React与MaterialUI构建

[在线演示](https://driverlin.github.io/EXviewerUI/)


## 截图

<div style="display: flex;">
Expand Down
16 changes: 8 additions & 8 deletions server/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ async def websocket_endpoint(websocket: WebSocket):
async def addFavorite(gid: int, token: str, index: int):
if FAVORITE_DISABLED == "true":
raise HTTPException(
status_code=403, detail="FAVORITE_DISABLED,该API已禁用")
status_code=403, detail=makeTrackableException(None, "FAVORITE_DISABLED,该API已禁用"))
logger.info(f"添加收藏 {gid}_{token} {index}")
try:
await aioPa.addFavorite(gid, token, index)
Expand All @@ -188,7 +188,7 @@ async def addFavorite(gid: int, token: str, index: int):
async def rmFavorite(gid: int, token: str):
if FAVORITE_DISABLED == "true":
raise HTTPException(
status_code=403, detail="FAVORITE_DISABLED,该API已禁用")
status_code=403, detail=makeTrackableException(None, "FAVORITE_DISABLED,该API已禁用"))
logger.info(f"删除收藏 {gid}_{token}")
try:
await aioPa.rmFavorite(gid, token)
Expand All @@ -203,7 +203,7 @@ async def rmFavorite(gid: int, token: str):
async def download(gid: int, token: str):
if DOWNLOAD_DISABLED == "true":
raise HTTPException(
status_code=403, detail="DOWNLOAD_DISABLED,该API已禁用")
status_code=403, detail=makeTrackableException(None, "DOWNLOAD_DISABLED,该API已禁用"))
logger.info(f"添加下载 {gid}_{token}")
try:
await aioPa.addDownload([[gid, token]])
Expand All @@ -218,7 +218,7 @@ async def download(gid: int, token: str):
async def delete(gid: int, token: str):
if DOWNLOAD_DISABLED == "true":
raise HTTPException(
status_code=403, detail="DOWNLOAD_DISABLED,该API已禁用")
status_code=403, detail=makeTrackableException(None, "DOWNLOAD_DISABLED,该API已禁用"))
logger.info(f"请求删除 {gid}_{token}")
try:
await aioPa.deleteDownload([[gid, token]])
Expand All @@ -233,7 +233,7 @@ async def delete(gid: int, token: str):
async def continueDownload():
if DOWNLOAD_DISABLED == "true":
raise HTTPException(
status_code=403, detail="DOWNLOAD_DISABLED,该API已禁用")
status_code=403, detail=makeTrackableException(None, "DOWNLOAD_DISABLED,该API已禁用"))
reDownloadCount = await aioPa.continueDownload()
return {"msg": f"已开始{reDownloadCount}项下载"}

Expand Down Expand Up @@ -377,7 +377,7 @@ async def handelUploadZipGallery(ws: WebSocket):
async def rateGallery(gid: int, token: str, score: float):
if EH_RATE_DISABLED == "true":
raise HTTPException(
status_code=403, detail="EH_RATE_DISABLED,该API已禁用")
status_code=403, detail=makeTrackableException(None, "EH_RATE_DISABLED,该API已禁用"))
try:
return await aioPa.rateGallery(gid, token, score)
except Exception as e:
Expand All @@ -390,7 +390,7 @@ async def rateGallery(gid: int, token: str, score: float):
async def voteComment(gid: int, token: str, commentId: int, vote: int):
if EH_COMMENT_DISABLED == "true":
raise HTTPException(
status_code=403, detail="EH_COMMENT_DISABLED,该API已禁用")
status_code=403, detail=makeTrackableException(None, "EH_COMMENT_DISABLED,该API已禁用"))
try:
return await aioPa.voteComment(gid, token, commentId, vote)
except Exception as e:
Expand All @@ -403,7 +403,7 @@ async def voteComment(gid: int, token: str, commentId: int, vote: int):
async def postComment(comment: commentBody):
if EH_COMMENT_DISABLED == "true":
raise HTTPException(
status_code=403, detail="EH_COMMENT_DISABLED,该API已禁用")
status_code=403, detail=makeTrackableException(None, "EH_COMMENT_DISABLED,该API已禁用"))
try:
return await aioPa.postComment(comment)
except Exception as e:
Expand Down
16 changes: 10 additions & 6 deletions server/utils/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,16 @@ def printTrackableException(e):


def makeTrackableException(e, appendE):
try:
exceptions = json.loads(str(e))
exceptions.append(str(appendE))
return Exception(json.dumps(exceptions))
except Exception :
return Exception(json.dumps([str(e), str(appendE)]))
if e:
try:
exceptions = json.loads(str(e))
exceptions.append(str(appendE))
return Exception(json.dumps(exceptions))
except Exception :
return Exception(json.dumps([str(e), str(appendE)]))
else:
return Exception(json.dumps([str(appendE)]))


printPerformance__log = {}
printPerformance__lock = threading.Lock()
Expand Down

0 comments on commit f06142e

Please sign in to comment.