add wallpaper api
This commit is contained in:
parent
7c0e2961b5
commit
e41450ddd8
@ -12,6 +12,7 @@ from app.core.config import settings
|
||||
from app.db import get_db
|
||||
from app.db.models.user import User
|
||||
from app.log import logger
|
||||
from app.utils.http import RequestUtils
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@ -47,3 +48,26 @@ async def login_access_token(
|
||||
),
|
||||
token_type="bearer",
|
||||
)
|
||||
|
||||
|
||||
@router.get("/login/wallpaper", summary="Bing每日壁纸", response_model=schemas.Response)
|
||||
async def bing_wallpaper() -> Any:
|
||||
"""
|
||||
获取Bing每日壁纸
|
||||
"""
|
||||
url = "https://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1"
|
||||
try:
|
||||
resp = RequestUtils(timeout=5).get_res(url)
|
||||
except Exception as err:
|
||||
print(str(err))
|
||||
return schemas.Response(success=False)
|
||||
if resp and resp.status_code == 200:
|
||||
try:
|
||||
result = resp.json()
|
||||
if isinstance(result, dict):
|
||||
for image in result.get('images') or []:
|
||||
return schemas.Response(success=False,
|
||||
message=f"https://cn.bing.com{image.get('url')}" if 'url' in image else '')
|
||||
except Exception as err:
|
||||
print(str(err))
|
||||
return schemas.Response(success=False)
|
||||
|
@ -97,7 +97,7 @@ class QbittorrentModule(_ModuleBase):
|
||||
if hashs:
|
||||
# 按Hash获取
|
||||
torrents, _ = self.qbittorrent.get_torrents(ids=hashs, tags=settings.TORRENT_TAG)
|
||||
for torrent in torrents:
|
||||
for torrent in torrents or []:
|
||||
content_path = torrent.get("content_path")
|
||||
if content_path:
|
||||
torrent_path = Path(content_path)
|
||||
@ -112,7 +112,7 @@ class QbittorrentModule(_ModuleBase):
|
||||
elif status == TorrentStatus.TRANSFER:
|
||||
# 获取已完成且未整理的
|
||||
torrents = self.qbittorrent.get_completed_torrents(tags=settings.TORRENT_TAG)
|
||||
for torrent in torrents:
|
||||
for torrent in torrents or []:
|
||||
tags = torrent.get("tags") or []
|
||||
if "已整理" in tags:
|
||||
continue
|
||||
@ -131,7 +131,7 @@ class QbittorrentModule(_ModuleBase):
|
||||
elif status == TorrentStatus.DOWNLOADING:
|
||||
# 获取正在下载的任务
|
||||
torrents = self.qbittorrent.get_downloading_torrents(tags=settings.TORRENT_TAG)
|
||||
for torrent in torrents:
|
||||
for torrent in torrents or []:
|
||||
meta = MetaInfo(torrent.get('name'))
|
||||
ret_torrents.append(DownloadingTorrent(
|
||||
title=torrent.get('name'),
|
||||
|
@ -84,7 +84,7 @@ class TransmissionModule(_ModuleBase):
|
||||
if hashs:
|
||||
# 按Hash获取
|
||||
torrents, _ = self.transmission.get_torrents(ids=hashs, tags=settings.TORRENT_TAG)
|
||||
for torrent in torrents:
|
||||
for torrent in torrents or []:
|
||||
ret_torrents.append(TransferTorrent(
|
||||
title=torrent.name,
|
||||
path=Path(torrent.download_dir) / torrent.name,
|
||||
@ -94,7 +94,7 @@ class TransmissionModule(_ModuleBase):
|
||||
elif status == TorrentStatus.TRANSFER:
|
||||
# 获取已完成且未整理的
|
||||
torrents = self.transmission.get_completed_torrents(tags=settings.TORRENT_TAG)
|
||||
for torrent in torrents:
|
||||
for torrent in torrents or []:
|
||||
# 含"已整理"tag的不处理
|
||||
if "已整理" in torrent.labels or []:
|
||||
continue
|
||||
@ -113,7 +113,7 @@ class TransmissionModule(_ModuleBase):
|
||||
elif status == TorrentStatus.DOWNLOADING:
|
||||
# 获取正在下载的任务
|
||||
torrents = self.transmission.get_downloading_torrents(tags=settings.TORRENT_TAG)
|
||||
for torrent in torrents:
|
||||
for torrent in torrents or []:
|
||||
meta = MetaInfo(torrent.name)
|
||||
ret_torrents.append(DownloadingTorrent(
|
||||
title=torrent.name,
|
||||
|
Loading…
x
Reference in New Issue
Block a user