Skip to content

Commit

Permalink
🐛 middleware(obv11): file name
Browse files Browse the repository at this point in the history
  • Loading branch information
j1g5awi committed Aug 9, 2024
1 parent 4bd111c commit 8c5b164
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
38 changes: 19 additions & 19 deletions nonebot_plugin_all4one/database/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,27 @@ async def get_file(file_id: str, src: Optional[str] = None) -> File:
file = (
await session.scalars(select(File).where(File.id == UUID(file_id)))
).one_or_none()
if file:
if src is None:
if file.sha256:
return file
if file is None:
raise DatabaseError("failed", 31001, "file not found", {})
if src is None:
if file.sha256:
return file
else:
if file.src == src:
return file
else:
if file.src == src:
return file
if file.sha256 is None:
raise DatabaseError("failed", 31001, "file not found", {})
if file_ := (
await session.scalars(
select(File).where(File.sha256 == file.sha256, File.src == src)
)
).first():
return file_
else:
if file.sha256:
if file_ := (
await session.scalars(
select(File).where(
File.sha256 == file.sha256, File.src == src
)
)
).first():
return file_
else:
file.src = src
file.src_id = None
return file
file.src = src
file.src_id = None
return file

raise DatabaseError("failed", 31001, "file not found", {})

Expand Down
3 changes: 2 additions & 1 deletion nonebot_plugin_all4one/middlewares/onebot_v11.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import uuid
from pathlib import Path
from datetime import datetime
from typing import Any, Union, Literal, Optional

Expand Down Expand Up @@ -155,7 +156,7 @@ async def to_onebot_message(self, message: Message) -> OneBotMessage:
data = None

file_id = await upload_file(
"",
Path(file).name,
self.get_name(),
file,
data=data,
Expand Down

0 comments on commit 8c5b164

Please sign in to comment.