Skip to content

Commit d0f6133

Browse files
authored
Merge pull request #51 from TTB-Network/dev/dashboard
Dev/dashboard
2 parents 43bd965 + 64df172 commit d0f6133

File tree

2 files changed

+19
-34
lines changed

2 files changed

+19
-34
lines changed

bmclapi_dashboard/static/js/index.min.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ class Application {
583583
this.createElement("button").append(
584584
this.createElement("i").class("bx", "bx-user-circle")
585585
).event("click", () => {
586-
modal.open().body(app.createElement("a").setText("cnm"),app.createElement("a").setText("cnm"))
586+
modal.open().body()
587587
})
588588
)
589589
)

core/cluster.py

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ async def get(self, hash: str, offset: int = 0) -> File:
533533
file.cache = True
534534
return file
535535
path = Path(str(self.dir) + f"/{hash[:2]}/{hash}")
536-
file = File(path, hash, 0)
536+
file = File(path, hash, path.stat().st_size)
537537
if CACHE_ENABLE:
538538
buf = io.BytesIO()
539539
async with aiofiles.open(path, "rb") as r:
@@ -830,64 +830,49 @@ async def _wait_lock(self):
830830
return
831831
await self.lock.wait()
832832

833-
async def get(self, file: str, offset: int = 0) -> File:
834-
if file in self.cache and self.cache[file].expiry - 10 > time.time():
835-
self.cache[file].cache = True
836-
self.cache[file].last_hit = time.time()
837-
return self.cache[file]
833+
async def get(self, hash: str, offset: int = 0) -> File:
834+
if hash in self.cache and self.cache[hash].expiry - 10 > time.time():
835+
self.cache[hash].cache = True
836+
self.cache[hash].last_hit = time.time()
837+
return self.cache[hash]
838838
try:
839+
f = File(
840+
hash,
841+
hash,
842+
size=0,
843+
)
839844
async with aiohttp.ClientSession(
840845
auth=aiohttp.BasicAuth(self.username, self.password)
841846
) as session:
842847
async with session.get(
843-
self.hostname + self._file_endpoint(file[:2] + "/" + file),
848+
self.hostname + self._file_endpoint(hash[:2] + "/" + hash),
844849
allow_redirects=False,
845850
) as resp:
846-
f = File(
847-
file,
848-
file,
849-
size=int(resp.headers.get("Content-Length", 0)),
850-
)
851851
if resp.status == 200:
852852
f.headers = {}
853853
for field in (
854854
"ETag",
855855
"Last-Modified",
856856
"Content-Length",
857-
"Content-Range",
858-
"Accept-Ranges",
859857
):
860858
if field not in resp.headers:
861859
continue
862860
f.headers[field] = resp.headers.get(field)
861+
f.size = int(resp.headers.get("Content-Length", 0))
863862
f.set_data(await resp.read())
864863
if CACHE_ENABLE:
865864
f.expiry = time.time() + CACHE_TIME
866-
self.cache[file] = f
867-
else:
868-
return f
865+
self.cache[hash] = f
869866
elif resp.status // 100 == 3:
867+
f.size = self.get_size(hash)
870868
f.path = resp.headers.get("Location")
871-
expiry = min(
872-
(
873-
0,
874-
*(
875-
float(n)
876-
for n in utils.parse_cache_control(
877-
resp.headers.get("Cache-Control", "")
878-
).values()
879-
if str(n).isnumeric()
880-
),
881-
)
882-
)
869+
expiry = re.search(r"max-age=(\d+)", resp.headers.get("Cache-Control", "")) or 0
883870
if expiry == 0:
884871
return f
885872
f.expiry = time.time() + expiry
886873
if CACHE_ENABLE:
887-
self.cache[file] = f
888-
else:
889-
return f
890-
return self.cache[file]
874+
self.cache[hash] = f
875+
return f
891876
except Exception:
892877
storages.disable(self)
893878
logger.error(traceback.format_exc())

0 commit comments

Comments
 (0)