feat: add logs, fix bugs
This commit is contained in:
parent
864781a511
commit
08bfbd1022
@ -129,6 +129,7 @@ class MediaChunkHolder(object):
|
||||
await waiter
|
||||
except:
|
||||
waiter.cancel()
|
||||
logger.warning("waiter cancel")
|
||||
try:
|
||||
self.waiters.remove(waiter)
|
||||
except ValueError:
|
||||
|
@ -15,7 +15,7 @@ logger = logging.getLogger(__file__.split("/")[-1])
|
||||
|
||||
class TgFileSystemClientManager(object):
|
||||
MAX_MANAGE_CLIENTS: int = 10
|
||||
is_init: asyncio.Future
|
||||
is_init: bool = False
|
||||
param: configParse.TgToFileSystemParameter
|
||||
clients: dict[str, TgFileSystemClient] = {}
|
||||
|
||||
@ -28,7 +28,6 @@ class TgFileSystemClientManager(object):
|
||||
def __init__(self, param: configParse.TgToFileSystemParameter) -> None:
|
||||
self.param = param
|
||||
self.db = UserManager()
|
||||
self.is_init = asyncio.Future()
|
||||
self.loop = asyncio.get_running_loop()
|
||||
if self.loop.is_running():
|
||||
self.loop.create_task(self._start_clients())
|
||||
@ -49,7 +48,7 @@ class TgFileSystemClientManager(object):
|
||||
await client.start()
|
||||
except Exception as err:
|
||||
logger.warning(f"start client: {err=}, {traceback.format_exc()}")
|
||||
self.is_init.set_result(True)
|
||||
self.is_init = True
|
||||
|
||||
async def get_status(self) -> dict[str, any]:
|
||||
clients_status = [
|
||||
@ -58,7 +57,7 @@ class TgFileSystemClientManager(object):
|
||||
}
|
||||
for _, client in self.clients.items()
|
||||
]
|
||||
return {"init": await self.is_init, "clients": clients_status}
|
||||
return {"init": self.is_init, "clients": clients_status}
|
||||
|
||||
async def login_clients(self) -> str:
|
||||
for _, client in self.clients.items():
|
||||
|
@ -177,6 +177,7 @@ async def get_tg_file_media_stream(token: str, cid: int, mid: int, request: Requ
|
||||
@app.get("/tg/api/v1/file/get/{chat_id}/{msg_id}/{file_name}")
|
||||
@apiutils.atimeit
|
||||
async def get_tg_file_media(chat_id: int|str, msg_id: int, file_name: str, sign: str, req: Request):
|
||||
logger.info(f"request: {chat_id=},{msg_id=},{file_name=},{req=},{id(req)=}")
|
||||
try:
|
||||
if isinstance(chat_id, str):
|
||||
chat_id = int(chat_id)
|
||||
@ -195,9 +196,8 @@ async def login_new_tg_file_client():
|
||||
|
||||
|
||||
@app.get("/tg/api/v1/client/status")
|
||||
async def get_tg_file_client_status(request: Request):
|
||||
clients_mgr = TgFileSystemClientManager.get_instance()
|
||||
return await clients_mgr.get_status()
|
||||
async def get_tg_file_client_status(flag: bool = False, request: Request = None):
|
||||
return await api.get_clients_manager_status(flag)
|
||||
|
||||
|
||||
@app.get("/tg/api/v1/client/link_convert")
|
||||
|
@ -1,4 +1,5 @@
|
||||
import traceback
|
||||
import json
|
||||
import logging
|
||||
|
||||
from telethon import types, hints, utils
|
||||
@ -37,3 +38,18 @@ async def link_convert(link: str) -> str:
|
||||
f"{param.base.exposed_url}/tg/api/v1/file/get/{utils.get_peer_id(msg.peer_id)}/{msg.id}/{file_name}?sign={client.sign}"
|
||||
)
|
||||
return url
|
||||
|
||||
|
||||
async def get_clients_manager_status(detail) -> dict[str, any]:
|
||||
clients_mgr = TgFileSystemClientManager.get_instance()
|
||||
ret = await clients_mgr.get_status()
|
||||
if not detail:
|
||||
return ret
|
||||
chat_details = {}
|
||||
for _, client in clients_mgr.clients.items():
|
||||
chat_list = client.client_param.whitelist_chat
|
||||
for chat_id in chat_list:
|
||||
chat_entity = await client.get_entity(chat_id)
|
||||
chat_details[chat_id] = json.loads(chat_entity.to_json())
|
||||
ret["info"] = chat_details
|
||||
return ret
|
||||
|
Loading…
x
Reference in New Issue
Block a user