Skip to content

Commit 4ce1bf9

Browse files
committed
修复已知问题
1 parent d0f6133 commit 4ce1bf9

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

bmclapi_dashboard/static/js/index.min.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,6 +1337,10 @@ class SocketData {
13371337
}, 30000)
13381338
const xhr = new XMLHttpRequest()
13391339
xhr.onload = async (event) => {
1340+
if (!this.$opened) {
1341+
this.$opened = true
1342+
window.dispatchEvent(new Event("mainsocket_connect"))
1343+
}
13401344
if (event.target.readyState == 4) {
13411345
var header = event.target.getResponseHeader("X-Encoding")
13421346
if (header == "binary") {
@@ -1348,6 +1352,11 @@ class SocketData {
13481352
}
13491353
}
13501354
}
1355+
xhr.error = async (event) => {
1356+
if (!this.$opened) return;
1357+
this.$opened = false
1358+
window.dispatchEvent(new Event("mainsocket_disconnect"))
1359+
}
13511360
xhr.open("POST", `${this.$url}?key=${key}&namespace=${encodeURIComponent(namespace)}`, true)
13521361
xhr.setRequestHeader("Content-Type", "application/json")
13531362
xhr.setRequestHeader("X-Accept-Encoding", "json")

core/cluster.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -764,11 +764,18 @@ async def _list_all(self, force=False):
764764
if not self.fetch:
765765
self.lock.acquire()
766766
self.fetch = True
767+
def stop(tqdm: Optional[tqdm] = None):
768+
if tqdm is not None:
769+
del tqdm
770+
self.lock.acquire()
771+
self.fetch = False
772+
raise asyncio.CancelledError
767773
try:
768774
await self._mkdir(self._download_endpoint())
769775
r = await self._execute(self.session.list(self._download_endpoint()))
770776
if r is asyncio.CancelledError:
771777
self.lock.acquire()
778+
self.fetch = False
772779
raise asyncio.CancelledError
773780
dirs = r[1:]
774781
with tqdm(
@@ -778,9 +785,7 @@ async def _list_all(self, force=False):
778785
await dashboard.set_status_by_tqdm("storage.webdav", pbar)
779786
r = await self._execute(self.session.list(self._download_endpoint()))
780787
if r is asyncio.CancelledError:
781-
self.lock.acquire()
782-
del pbar
783-
raise asyncio.CancelledError
788+
return stop(pbar)
784789
for dir in r[1:]:
785790
pbar.update(1)
786791
files: dict[str, File] = {}
@@ -793,9 +798,7 @@ async def _list_all(self, force=False):
793798
)
794799
)
795800
if r is asyncio.CancelledError:
796-
self.lock.acquire()
797-
del pbar
798-
raise asyncio.CancelledError
801+
return stop(pbar)
799802
for file in r[1:]:
800803
if file["isdir"]:
801804
continue
@@ -807,9 +810,7 @@ async def _list_all(self, force=False):
807810
try:
808811
await asyncio.sleep(0)
809812
except asyncio.CancelledError:
810-
self.lock.acquire()
811-
del pbar
812-
raise asyncio.CancelledError
813+
return stop(pbar)
813814
except Exception as e:
814815
raise e
815816
for remove in set(
@@ -864,7 +865,7 @@ async def get(self, hash: str, offset: int = 0) -> File:
864865
f.expiry = time.time() + CACHE_TIME
865866
self.cache[hash] = f
866867
elif resp.status // 100 == 3:
867-
f.size = self.get_size(hash)
868+
f.size = await self.get_size(hash)
868869
f.path = resp.headers.get("Location")
869870
expiry = re.search(r"max-age=(\d+)", resp.headers.get("Cache-Control", "")) or 0
870871
if expiry == 0:

0 commit comments

Comments
 (0)