mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 06:12:53 +08:00
修复更新色图问题
This commit is contained in:
parent
9f16f938dc
commit
b1660bb9d6
@ -334,6 +334,7 @@ PS: **ARM平台** 请使用全量版 同时 **如果你的机器 RAM < 1G 可能
|
||||
### 2023/4/16
|
||||
|
||||
* 修复开箱更新未登录时没有停止更新
|
||||
* 修复更新色图问题
|
||||
|
||||
### 2023/4/5
|
||||
|
||||
|
||||
@ -19,7 +19,7 @@ class Setu(Model):
|
||||
"""作者"""
|
||||
pid = fields.BigIntField()
|
||||
"""pid"""
|
||||
img_hash = fields.TextField()
|
||||
img_hash: str = fields.TextField()
|
||||
"""图片hash"""
|
||||
img_url = fields.CharField(255)
|
||||
"""pixiv url链接"""
|
||||
@ -64,16 +64,16 @@ class Setu(Model):
|
||||
return await query.all()
|
||||
|
||||
@classmethod
|
||||
async def delete_image(cls, pid: int) -> int:
|
||||
async def delete_image(cls, pid: int, img_url: str) -> int:
|
||||
"""
|
||||
说明:
|
||||
删除图片并替换
|
||||
参数:
|
||||
:param pid: 图片pid
|
||||
"""
|
||||
print(pid)
|
||||
return_id = -1
|
||||
query = await cls.get_or_none(pid=pid)
|
||||
if query:
|
||||
if query := await cls.get_or_none(pid=pid, img_url=img_url):
|
||||
num = await cls.filter(is_r18=query.is_r18).count()
|
||||
last_image = await cls.get_or_none(is_r18=query.is_r18, local_id=num - 1)
|
||||
if last_image:
|
||||
|
||||
@ -157,9 +157,10 @@ async def update_setu_img(flag: bool = False):
|
||||
unlink = True
|
||||
if unlink:
|
||||
local_image.unlink()
|
||||
max_num = await Setu.delete_image(image.pid)
|
||||
os.rename(path / f"{max_num}.jpg", local_image)
|
||||
logger.warning(f"更新色图 PID:{image.pid} 404,已删除并替换")
|
||||
max_num = await Setu.delete_image(image.pid, image.img_url)
|
||||
if (path / f"{max_num}.jpg").exists():
|
||||
os.rename(path / f"{max_num}.jpg", local_image)
|
||||
logger.warning(f"更新色图 PID:{image.pid} 404,已删除并替换")
|
||||
except Exception as e:
|
||||
_success -= 1
|
||||
logger.error(f"更新色图 {image.local_id}.jpg 错误 {type(e)}: {e}")
|
||||
@ -169,8 +170,9 @@ async def update_setu_img(flag: bool = False):
|
||||
else:
|
||||
logger.info(f"更新色图 {image.local_id}.jpg 已存在")
|
||||
if _success or error_info or flag:
|
||||
await get_bot().send_private_msg(
|
||||
user_id=int(list(get_bot().config.superusers)[0]),
|
||||
message=f'{str(datetime.now()).split(".")[0]} 更新 色图 完成,本地存在 {count} 张,实际更新 {_success} 张,'
|
||||
f"以下为更新时未知错误:\n" + "\n".join(error_info),
|
||||
)
|
||||
if bot := get_bot():
|
||||
await bot.send_private_msg(
|
||||
user_id=int(list(bot.config.superusers)[0]),
|
||||
message=f'{str(datetime.now()).split(".")[0]} 更新 色图 完成,本地存在 {count} 张,实际更新 {_success} 张,'
|
||||
f"以下为更新时未知错误:\n" + "\n".join(error_info),
|
||||
)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user