Skip to content

Commit a78cff6

Browse files
committed
fix: 修复没有自动同步文件的问题
1 parent f1c80a4 commit a78cff6

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

core/cluster.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,8 @@ async def sync(self):
336336

337337
await self.download(missing)
338338

339+
scheduler.run_later(self.sync, 600)
340+
339341
async def download(self, filelist: set[File]):
340342
total = len(filelist)
341343
size = sum(f.size for f in filelist)
@@ -365,7 +367,6 @@ async def download(self, filelist: set[File]):
365367
finally:
366368
for session in sessions:
367369
await session.close()
368-
scheduler.run_later(self.sync, 600)
369370

370371
async def _download(self, session: aiohttp.ClientSession, file_queues: asyncio.Queue[File], pbar: DownloadStatistics):
371372
while not file_queues.empty():
@@ -563,8 +564,6 @@ def __init__(self, id: str, secret: str):
563564
self.id = id
564565
self.secret = secret
565566
self.token: Optional[Token] = None
566-
self.fetch_time: float = 0
567-
self.token_ttl: float = 0
568567
self.token_scheduler: Optional[int] = None
569568
self.socket_io = ClusterSocketIO(self)
570569
self.want_enable: bool = False
@@ -578,7 +577,7 @@ def __repr__(self):
578577
return f"Cluster(id={self.id})"
579578

580579
async def get_token(self):
581-
if self.token is None or time.time() - self.fetch_time > self.token_ttl - 300:
580+
if self.token is None or time.time() - self.token.last > self.token.ttl - 300:
582581
await self._fetch_token()
583582

584583
if self.token is None or self.token.last + self.token.ttl < time.time():
@@ -588,7 +587,10 @@ async def get_token(self):
588587

589588
async def _fetch_token(self):
590589
async with aiohttp.ClientSession(
591-
config.const.base_url
590+
config.const.base_url,
591+
headers={
592+
"User-Agent": USER_AGENT
593+
}
592594
) as session:
593595
logger.tdebug("cluster.debug.fetch_token", cluster=self.id)
594596
async with session.get(
@@ -737,7 +739,8 @@ def __init__(self, cluster: Cluster) -> None:
737739
self.cluster = cluster
738740
self.sio = socketio.AsyncClient(
739741
logger=True,
740-
handle_sigint=False
742+
handle_sigint=False,
743+
engineio_logger=logger
741744
)
742745

743746
async def connect(self):

0 commit comments

Comments
 (0)