add 历史记录API
This commit is contained in:
parent
c7f897fdcd
commit
686c0dec05
@ -1,6 +1,7 @@
|
||||
from fastapi import APIRouter
|
||||
|
||||
from app.api.endpoints import login, user, site, message, webhook, subscribe, media, douban, search, plugin, tmdb
|
||||
from app.api.endpoints import login, user, site, message, webhook, subscribe, \
|
||||
media, douban, search, plugin, tmdb, history
|
||||
|
||||
api_router = APIRouter()
|
||||
api_router.include_router(login.router, tags=["login"])
|
||||
@ -14,3 +15,5 @@ api_router.include_router(search.router, prefix="/search", tags=["search"])
|
||||
api_router.include_router(douban.router, prefix="/douban", tags=["douban"])
|
||||
api_router.include_router(tmdb.router, prefix="/tmdb", tags=["tmdb"])
|
||||
api_router.include_router(plugin.router, prefix="/plugin", tags=["plugin"])
|
||||
api_router.include_router(history.router, prefix="/history", tags=["history"])
|
||||
api_router.include_router(plugin.router, prefix="/plugin", tags=["plugin"])
|
||||
|
39
app/api/endpoints/history.py
Normal file
39
app/api/endpoints/history.py
Normal file
@ -0,0 +1,39 @@
|
||||
from typing import List, Any
|
||||
|
||||
from fastapi import APIRouter, Depends
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app import schemas
|
||||
from app.db import get_db
|
||||
from app.db.models.downloadhistory import DownloadHistory
|
||||
from app.db.models.transferhistory import TransferHistory
|
||||
from app.db.models.user import User
|
||||
from app.db.userauth import get_current_active_user
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/download", summary="下载历史记录", response_model=List[schemas.Context])
|
||||
async def download_history(page: int = 1,
|
||||
count: int = 30,
|
||||
db: Session = Depends(get_db),
|
||||
_: User = Depends(get_current_active_user)) -> Any:
|
||||
"""
|
||||
查询下载历史记录
|
||||
"""
|
||||
return DownloadHistory.list_by_page(db, page, count)
|
||||
|
||||
|
||||
@router.get("/transfer", summary="转移历史记录", response_model=List[schemas.TorrentInfo])
|
||||
async def transfer_history(title: str = None,
|
||||
page: int = 1,
|
||||
count: int = 30,
|
||||
db: Session = Depends(get_db),
|
||||
_: User = Depends(get_current_active_user)) -> Any:
|
||||
"""
|
||||
查询转移历史记录
|
||||
"""
|
||||
if title:
|
||||
return TransferHistory.list_by_title(db, title, page, count)
|
||||
else:
|
||||
return TransferHistory.list_by_page(db, page, count)
|
@ -30,3 +30,9 @@ class DownloadHistoryOper(DbOper):
|
||||
"""
|
||||
downloadhistory = DownloadHistory(**kwargs)
|
||||
return downloadhistory.create(self._db)
|
||||
|
||||
def list_by_page(self, page: int = 1, count: int = 30):
|
||||
"""
|
||||
分页查询下载历史
|
||||
"""
|
||||
return DownloadHistory.list_by_page(self._db, page, count)
|
||||
|
@ -29,3 +29,7 @@ class DownloadHistory(Base):
|
||||
@staticmethod
|
||||
def get_by_hash(db: Session, download_hash: str):
|
||||
return db.query(DownloadHistory).filter(DownloadHistory.download_hash == download_hash).first()
|
||||
|
||||
@staticmethod
|
||||
def list_by_page(db: Session, page: int = 1, count: int = 30):
|
||||
return db.query(DownloadHistory).offset((page - 1) * count).limit(count).all()
|
||||
|
@ -29,5 +29,10 @@ class TransferHistory(Base):
|
||||
date = Column(String, index=True, default=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
|
||||
|
||||
@staticmethod
|
||||
def search_by_title(db: Session, title: str):
|
||||
return db.query(TransferHistory).filter(TransferHistory.title == title).all()
|
||||
def list_by_title(db: Session, title: str, page: int = 1, count: int = 30):
|
||||
return db.query(TransferHistory).filter(TransferHistory.title == title).offset((page - 1) * count).limit(
|
||||
count).all()
|
||||
|
||||
@staticmethod
|
||||
def list_by_page(db: Session, page: int = 1, count: int = 30):
|
||||
return db.query(TransferHistory).offset((page - 1) * count).limit(count).all()
|
||||
|
49
app/schemas/history.py
Normal file
49
app/schemas/history.py
Normal file
@ -0,0 +1,49 @@
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class DownloadHistory(BaseModel):
|
||||
id: int
|
||||
path: Optional[str] = None
|
||||
type: Optional[str] = None
|
||||
title: Optional[str] = None
|
||||
year: Optional[str] = None
|
||||
tmdbid: Optional[int] = None
|
||||
imdbid: Optional[str] = None
|
||||
tvdbid: Optional[int] = None
|
||||
doubanid: Optional[str] = None
|
||||
seasons: Optional[str] = None
|
||||
episodes: Optional[str] = None
|
||||
image: Optional[str] = None
|
||||
download_hash: Optional[str] = None
|
||||
torrent_name: Optional[str] = None
|
||||
torrent_description: Optional[str] = None
|
||||
torrent_site: Optional[str] = None
|
||||
note: Optional[str] = None
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
|
||||
|
||||
class TransferHistory(BaseModel):
|
||||
id: int
|
||||
src: Optional[str] = None
|
||||
dest: Optional[str] = None
|
||||
mode: Optional[str] = None
|
||||
type: Optional[str] = None
|
||||
category: Optional[str] = None
|
||||
title: Optional[str] = None
|
||||
year: Optional[str] = None
|
||||
tmdbid: Optional[int] = None
|
||||
imdbid: Optional[str] = None
|
||||
tvdbid: Optional[int] = None
|
||||
doubanid: Optional[str] = None
|
||||
seasons: Optional[str] = None
|
||||
episodes: Optional[str] = None
|
||||
image: Optional[str] = None
|
||||
download_hash: Optional[str] = None
|
||||
date: Optional[str] = None
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
Loading…
x
Reference in New Issue
Block a user