mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 23:47:41 +08:00
fix bug
This commit is contained in:
@@ -9,7 +9,7 @@ from app.core.context import MediaInfo, Context, TorrentInfo
|
|||||||
from app.core.metainfo import MetaInfo
|
from app.core.metainfo import MetaInfo
|
||||||
from app.core.security import verify_token
|
from app.core.security import verify_token
|
||||||
from app.db.models.user import User
|
from app.db.models.user import User
|
||||||
from app.db.user_oper import get_current_active_user, check_user_permission
|
from app.db.user_oper import get_current_active_user
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
@@ -100,8 +100,6 @@ def stop(hashString: str) -> Any:
|
|||||||
"""
|
"""
|
||||||
暂停下载任务
|
暂停下载任务
|
||||||
"""
|
"""
|
||||||
# 检查用户权限
|
|
||||||
check_user_permission(permission='downloading.manage')
|
|
||||||
ret = DownloadChain().set_downloading(hashString, "stop")
|
ret = DownloadChain().set_downloading(hashString, "stop")
|
||||||
return schemas.Response(success=True if ret else False)
|
return schemas.Response(success=True if ret else False)
|
||||||
|
|
||||||
@@ -111,7 +109,5 @@ def delete(hashString: str) -> Any:
|
|||||||
"""
|
"""
|
||||||
删除下载任务
|
删除下载任务
|
||||||
"""
|
"""
|
||||||
# 检查用户权限
|
|
||||||
check_user_permission(permission='downloading.manage')
|
|
||||||
ret = DownloadChain().remove_downloading(hashString)
|
ret = DownloadChain().remove_downloading(hashString)
|
||||||
return schemas.Response(success=True if ret else False)
|
return schemas.Response(success=True if ret else False)
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ from app.chain.media import MediaChain
|
|||||||
from app.chain.search import SearchChain
|
from app.chain.search import SearchChain
|
||||||
from app.core.config import settings
|
from app.core.config import settings
|
||||||
from app.core.security import verify_token
|
from app.core.security import verify_token
|
||||||
from app.db.user_oper import check_user_permission
|
|
||||||
from app.schemas.types import MediaType
|
from app.schemas.types import MediaType
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
@@ -30,8 +29,6 @@ def search_by_id(mediaid: str,
|
|||||||
"""
|
"""
|
||||||
根据TMDBID/豆瓣ID精确搜索站点资源 tmdb:/douban:/bangumi:
|
根据TMDBID/豆瓣ID精确搜索站点资源 tmdb:/douban:/bangumi:
|
||||||
"""
|
"""
|
||||||
# 检查用户权限
|
|
||||||
check_user_permission(permission='resource.search')
|
|
||||||
if mtype:
|
if mtype:
|
||||||
mtype = MediaType(mtype)
|
mtype = MediaType(mtype)
|
||||||
if season:
|
if season:
|
||||||
@@ -92,13 +89,10 @@ def search_by_id(mediaid: str,
|
|||||||
@router.get("/title", summary="模糊搜索资源", response_model=schemas.Response)
|
@router.get("/title", summary="模糊搜索资源", response_model=schemas.Response)
|
||||||
def search_by_title(keyword: str = None,
|
def search_by_title(keyword: str = None,
|
||||||
page: int = 0,
|
page: int = 0,
|
||||||
site: int = None,
|
site: int = None) -> Any:
|
||||||
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
|
||||||
"""
|
"""
|
||||||
根据名称模糊搜索站点资源,支持分页,关键词为空是返回首页资源
|
根据名称模糊搜索站点资源,支持分页,关键词为空是返回首页资源
|
||||||
"""
|
"""
|
||||||
# 检查用户权限
|
|
||||||
check_user_permission(permission='resource.search')
|
|
||||||
torrents = SearchChain().search_by_title(title=keyword, page=page, site=site)
|
torrents = SearchChain().search_by_title(title=keyword, page=page, site=site)
|
||||||
if not torrents:
|
if not torrents:
|
||||||
return schemas.Response(success=False, message="未搜索到任何资源")
|
return schemas.Response(success=False, message="未搜索到任何资源")
|
||||||
|
|||||||
@@ -48,29 +48,6 @@ def get_current_active_superuser(
|
|||||||
return current_user
|
return current_user
|
||||||
|
|
||||||
|
|
||||||
def check_user_permission(
|
|
||||||
permission: str,
|
|
||||||
current_user: User = Depends(get_current_user)
|
|
||||||
) -> User:
|
|
||||||
"""
|
|
||||||
获取当前激活且有指定权限的用户
|
|
||||||
"""
|
|
||||||
if not current_user.is_active:
|
|
||||||
raise HTTPException(status_code=403, detail="用户未激活")
|
|
||||||
if current_user.is_superuser:
|
|
||||||
return current_user
|
|
||||||
if not current_user.permissions:
|
|
||||||
raise HTTPException(status_code=400, detail="用户权限不足")
|
|
||||||
permission_dict = json.loads(current_user.permissions)
|
|
||||||
if permission_dict.get("admin"):
|
|
||||||
return current_user
|
|
||||||
for key in permission.split("."):
|
|
||||||
if key not in permission_dict or not permission_dict[key]:
|
|
||||||
raise HTTPException(status_code=400, detail="用户权限不足")
|
|
||||||
permission_dict = permission_dict[key]
|
|
||||||
return current_user
|
|
||||||
|
|
||||||
|
|
||||||
class UserOper(DbOper):
|
class UserOper(DbOper):
|
||||||
"""
|
"""
|
||||||
用户管理
|
用户管理
|
||||||
|
|||||||
Reference in New Issue
Block a user