From 0dce4b4fce5439490935940b073e1829b7b3f68e Mon Sep 17 00:00:00 2001 From: tianxiu2b2t Date: Sat, 27 Apr 2024 22:57:42 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=88=A0=E9=99=A4=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E4=B8=9C=E8=A5=BF*?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bmclapi_dashboard/static/js/index.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bmclapi_dashboard/static/js/index.min.js b/bmclapi_dashboard/static/js/index.min.js index ad21891..854e074 100644 --- a/bmclapi_dashboard/static/js/index.min.js +++ b/bmclapi_dashboard/static/js/index.min.js @@ -583,7 +583,7 @@ class Application { this.createElement("button").append( this.createElement("i").class("bx", "bx-user-circle") ).event("click", () => { - modal.open().body(app.createElement("a").setText("cnm"),app.createElement("a").setText("cnm")) + modal.open().body() }) ) ) From 64df1724abac564c3dd585d6a310f80af078e793 Mon Sep 17 00:00:00 2001 From: tianxiu2b2t Date: Sun, 28 Apr 2024 21:57:40 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E6=B5=81=E9=87=8F=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/cluster.py | 51 +++++++++++++++++-------------------------------- 1 file changed, 18 insertions(+), 33 deletions(-) diff --git a/core/cluster.py b/core/cluster.py index 425a4b5..027dad7 100644 --- a/core/cluster.py +++ b/core/cluster.py @@ -533,7 +533,7 @@ async def get(self, hash: str, offset: int = 0) -> File: file.cache = True return file path = Path(str(self.dir) + f"/{hash[:2]}/{hash}") - file = File(path, hash, 0) + file = File(path, hash, path.stat().st_size) if CACHE_ENABLE: buf = io.BytesIO() async with aiofiles.open(path, "rb") as r: @@ -830,64 +830,49 @@ async def _wait_lock(self): return await self.lock.wait() - async def get(self, file: str, offset: int = 0) -> File: - if file in self.cache and self.cache[file].expiry - 10 > time.time(): - self.cache[file].cache = True - self.cache[file].last_hit = time.time() - return self.cache[file] + async def get(self, hash: str, offset: int = 0) -> File: + if hash in self.cache and self.cache[hash].expiry - 10 > time.time(): + self.cache[hash].cache = True + self.cache[hash].last_hit = time.time() + return self.cache[hash] try: + f = File( + hash, + hash, + size=0, + ) async with aiohttp.ClientSession( auth=aiohttp.BasicAuth(self.username, self.password) ) as session: async with session.get( - self.hostname + self._file_endpoint(file[:2] + "/" + file), + self.hostname + self._file_endpoint(hash[:2] + "/" + hash), allow_redirects=False, ) as resp: - f = File( - file, - file, - size=int(resp.headers.get("Content-Length", 0)), - ) if resp.status == 200: f.headers = {} for field in ( "ETag", "Last-Modified", "Content-Length", - "Content-Range", - "Accept-Ranges", ): if field not in resp.headers: continue f.headers[field] = resp.headers.get(field) + f.size = int(resp.headers.get("Content-Length", 0)) f.set_data(await resp.read()) if CACHE_ENABLE: f.expiry = time.time() + CACHE_TIME - self.cache[file] = f - else: - return f + self.cache[hash] = f elif resp.status // 100 == 3: + f.size = self.get_size(hash) f.path = resp.headers.get("Location") - expiry = min( - ( - 0, - *( - float(n) - for n in utils.parse_cache_control( - resp.headers.get("Cache-Control", "") - ).values() - if str(n).isnumeric() - ), - ) - ) + expiry = re.search(r"max-age=(\d+)", resp.headers.get("Cache-Control", "")) or 0 if expiry == 0: return f f.expiry = time.time() + expiry if CACHE_ENABLE: - self.cache[file] = f - else: - return f - return self.cache[file] + self.cache[hash] = f + return f except Exception: storages.disable(self) logger.error(traceback.format_exc())