mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-04-09 21:58:39 +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.siteicon import SiteIcon
|
||||
from app.db.models.sitestatistic import SiteStatistic
|
||||
from app.db.models.siteuserdata import SiteUserData
|
||||
from app.db.systemconfig_oper import SystemConfigOper
|
||||
from app.db.user_oper import get_current_active_superuser
|
||||
from app.helper.sites import SitesHelper
|
||||
@@ -164,7 +165,7 @@ def update_cookie(
|
||||
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(
|
||||
site_id: int,
|
||||
db: Session = Depends(get_db),
|
||||
@@ -185,6 +186,27 @@ def refresh_userdata(
|
||||
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)
|
||||
def test_site(site_id: int,
|
||||
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])
|
||||
def read_subscribe(
|
||||
def subscribe_history(
|
||||
mtype: str,
|
||||
page: int = 1,
|
||||
count: int = 30,
|
||||
|
||||
@@ -52,7 +52,14 @@ class SiteUserData(Base):
|
||||
|
||||
@staticmethod
|
||||
@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()
|
||||
|
||||
@staticmethod
|
||||
|
||||
@@ -105,22 +105,29 @@ class SiteOper(DbOper):
|
||||
"""
|
||||
更新站点用户数据
|
||||
"""
|
||||
site = Site.get_by_domain(self._db, domain)
|
||||
if not site:
|
||||
return False, "站点不存在"
|
||||
# 当前系统日期
|
||||
current_day = datetime.now().strftime('%Y-%m-%d')
|
||||
current_time = datetime.now().strftime('%H:%M:%S')
|
||||
payload.update({
|
||||
"domain": domain,
|
||||
"updated_day": datetime.now().strftime('%Y-%m-%d'),
|
||||
"updated_time": datetime.now().strftime('%H:%M:%S')
|
||||
"updated_day": current_day,
|
||||
"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, "更新站点用户数据成功"
|
||||
|
||||
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]:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user