Skip to content

Commit

Permalink
Merge pull request #330 from EstrellaXD/3.0-dev
Browse files Browse the repository at this point in the history
3.0.6
  • Loading branch information
EstrellaXD authored Jun 13, 2023
2 parents 51f720a + 88f9b50 commit 750b7e6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/wiki
Submodule wiki updated from 519e38 to d0bb98
9 changes: 8 additions & 1 deletion src/module/api/bangumi.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logging

from fastapi import Depends, HTTPException, status
from fastapi.responses import JSONResponse

Expand All @@ -7,6 +9,7 @@
from module.manager import TorrentManager
from module.security import get_current_user

logger = logging.getLogger(__name__)

@router.get(
"/api/v1/bangumi/getAll", tags=["bangumi"], response_model=list[BangumiData]
Expand Down Expand Up @@ -39,7 +42,11 @@ async def update_rule(data: BangumiData, current_user=Depends(get_current_user))
status_code=status.HTTP_401_UNAUTHORIZED, detail="invalid token"
)
with TorrentManager() as torrent:
return torrent.update_rule(data)
try:
return torrent.update_rule(data)
except Exception as e:
logger.error(f"Failed to update rule: {e}")
return JSONResponse(status_code=500, content={"message": "Failed"})


@router.delete("/api/v1/bangumi/deleteRule/{bangumi_id}", tags=["bangumi"])
Expand Down
28 changes: 23 additions & 5 deletions src/module/database/bangumi.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,13 @@ def not_complete(self) -> list[BangumiData]:
return [self.__db_to_data(x) for x in dict_data]

def not_added(self) -> list[BangumiData]:
condition = {"added": 0, "rule_name": None, "save_path": None}
dict_data = self._search_datas(
table_name=self.__table_name,
condition=condition,
self._cursor.execute(
"""
SELECT * FROM bangumi
WHERE added = 0 OR rule_name IS NULL OR save_path IS NULL
"""
)
return [self.__db_to_data(x) for x in dict_data]
return self.__fetch_data()

def gen_id(self) -> int:
self._cursor.execute(
Expand Down Expand Up @@ -215,7 +216,24 @@ def __check_list_exist(self, data_list: list[BangumiData]):
return True
return False


if __name__ == '__main__':
with BangumiDatabase() as db:
db.update_table()
data = BangumiData(
id=1,
title_raw="",
official_title="",
poster_link="",
rss_link=[],
eps_collect=0,
eps_total=0,
eps_update=0,
eps_complete=False,
added=False,
rule_name=None,
save_path=None,
)
db.insert(data)
print(db.not_added())
print(db.not_complete())

0 comments on commit 750b7e6

Please sign in to comment.