mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-04 23:17:20 +08:00
fix site userdata
This commit is contained in:
@@ -14,6 +14,7 @@ from app.db.models import User
|
|||||||
from app.db.models.site import Site
|
from app.db.models.site import Site
|
||||||
from app.db.models.siteicon import SiteIcon
|
from app.db.models.siteicon import SiteIcon
|
||||||
from app.db.models.sitestatistic import SiteStatistic
|
from app.db.models.sitestatistic import SiteStatistic
|
||||||
|
from app.db.models.siteuserdata import SiteUserData
|
||||||
from app.db.systemconfig_oper import SystemConfigOper
|
from app.db.systemconfig_oper import SystemConfigOper
|
||||||
from app.db.user_oper import get_current_active_superuser
|
from app.db.user_oper import get_current_active_superuser
|
||||||
from app.helper.sites import SitesHelper
|
from app.helper.sites import SitesHelper
|
||||||
@@ -164,7 +165,7 @@ def update_cookie(
|
|||||||
return schemas.Response(success=state, message=message)
|
return schemas.Response(success=state, message=message)
|
||||||
|
|
||||||
|
|
||||||
@router.get("/userdata/{site_id}", summary="更新站点用户数据", response_model=schemas.Response)
|
@router.post("/userdata/{site_id}", summary="更新站点用户数据", response_model=schemas.Response)
|
||||||
def refresh_userdata(
|
def refresh_userdata(
|
||||||
site_id: int,
|
site_id: int,
|
||||||
db: Session = Depends(get_db),
|
db: Session = Depends(get_db),
|
||||||
@@ -185,6 +186,27 @@ def refresh_userdata(
|
|||||||
return schemas.Response(success=True, data=user_data)
|
return schemas.Response(success=True, data=user_data)
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/userdata/{site_id}", summary="查询站点用户数据", response_model=schemas.Response)
|
||||||
|
def read_userdata(
|
||||||
|
site_id: int,
|
||||||
|
workdate: str = None,
|
||||||
|
db: Session = Depends(get_db),
|
||||||
|
_: schemas.TokenPayload = Depends(get_current_active_superuser)) -> Any:
|
||||||
|
"""
|
||||||
|
查询站点用户数据
|
||||||
|
"""
|
||||||
|
site = Site.get(db, site_id)
|
||||||
|
if not site:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=404,
|
||||||
|
detail=f"站点 {site_id} 不存在",
|
||||||
|
)
|
||||||
|
user_data = SiteUserData.get_by_domain(db, domain=site.domain, workdate=workdate)
|
||||||
|
if not user_data:
|
||||||
|
return schemas.Response(success=False, data=[])
|
||||||
|
return schemas.Response(success=True, data=user_data)
|
||||||
|
|
||||||
|
|
||||||
@router.get("/test/{site_id}", summary="连接测试", response_model=schemas.Response)
|
@router.get("/test/{site_id}", summary="连接测试", response_model=schemas.Response)
|
||||||
def test_site(site_id: int,
|
def test_site(site_id: int,
|
||||||
db: Session = Depends(get_db),
|
db: Session = Depends(get_db),
|
||||||
|
|||||||
@@ -317,7 +317,7 @@ async def seerr_subscribe(request: Request, background_tasks: BackgroundTasks,
|
|||||||
|
|
||||||
|
|
||||||
@router.get("/history/{mtype}", summary="查询订阅历史", response_model=List[schemas.Subscribe])
|
@router.get("/history/{mtype}", summary="查询订阅历史", response_model=List[schemas.Subscribe])
|
||||||
def read_subscribe(
|
def subscribe_history(
|
||||||
mtype: str,
|
mtype: str,
|
||||||
page: int = 1,
|
page: int = 1,
|
||||||
count: int = 30,
|
count: int = 30,
|
||||||
|
|||||||
@@ -52,7 +52,14 @@ class SiteUserData(Base):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@db_query
|
@db_query
|
||||||
def get_by_domain(db: Session, domain: str):
|
def get_by_domain(db: Session, domain: str, workdate: str = None, worktime: str = None):
|
||||||
|
if workdate and worktime:
|
||||||
|
return db.query(SiteUserData).filter(SiteUserData.domain == domain,
|
||||||
|
SiteUserData.updated_day == workdate,
|
||||||
|
SiteUserData.updated_time == worktime).all()
|
||||||
|
elif workdate:
|
||||||
|
return db.query(SiteUserData).filter(SiteUserData.domain == domain,
|
||||||
|
SiteUserData.updated_day == workdate).all()
|
||||||
return db.query(SiteUserData).filter(SiteUserData.domain == domain).all()
|
return db.query(SiteUserData).filter(SiteUserData.domain == domain).all()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
+15
-8
@@ -105,22 +105,29 @@ class SiteOper(DbOper):
|
|||||||
"""
|
"""
|
||||||
更新站点用户数据
|
更新站点用户数据
|
||||||
"""
|
"""
|
||||||
site = Site.get_by_domain(self._db, domain)
|
# 当前系统日期
|
||||||
if not site:
|
current_day = datetime.now().strftime('%Y-%m-%d')
|
||||||
return False, "站点不存在"
|
current_time = datetime.now().strftime('%H:%M:%S')
|
||||||
payload.update({
|
payload.update({
|
||||||
"domain": domain,
|
"domain": domain,
|
||||||
"updated_day": datetime.now().strftime('%Y-%m-%d'),
|
"updated_day": current_day,
|
||||||
"updated_time": datetime.now().strftime('%H:%M:%S')
|
"updated_time": current_time
|
||||||
})
|
})
|
||||||
SiteUserData.update(self._db, payload)
|
siteuserdata = SiteUserData.get_by_domain(self._db, domain=domain,
|
||||||
|
workdate=current_day, worktime=current_time)
|
||||||
|
if siteuserdata:
|
||||||
|
# 存在则更新
|
||||||
|
SiteUserData.update(self._db, payload)
|
||||||
|
else:
|
||||||
|
# 不存在则插入
|
||||||
|
SiteUserData(**payload).create(self._db)
|
||||||
return True, "更新站点用户数据成功"
|
return True, "更新站点用户数据成功"
|
||||||
|
|
||||||
def get_userdata_by_domain(self, domain: str) -> List[SiteUserData]:
|
def get_userdata_by_domain(self, domain: str, workdate: str = None) -> List[SiteUserData]:
|
||||||
"""
|
"""
|
||||||
获取站点用户数据
|
获取站点用户数据
|
||||||
"""
|
"""
|
||||||
return SiteUserData.get_by_domain(self._db, domain)
|
return SiteUserData.get_by_domain(self._db, domain=domain, workdate=workdate)
|
||||||
|
|
||||||
def get_userdata_by_date(self, date: str) -> List[SiteUserData]:
|
def get_userdata_by_date(self, date: str) -> List[SiteUserData]:
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user