Fix request handling

This commit is contained in:
1e9abhi1e10
2024-07-26 05:30:42 +05:30
parent 31aeca2340
commit 8664b53991

View File

@@ -214,12 +214,8 @@ class Auradine(StockFirmware):
raise ValueError("Either URL or file path must be provided for firmware upgrade.") raise ValueError("Either URL or file path must be provided for firmware upgrade.")
if url: if url:
# Download the firmware file from the URL result = await self.web.firmware_upgrade(url=url)
response = await self.web.get(url) elif file_path:
if response.status_code != 200:
raise ValueError(f"Failed to download firmware from URL: {url}")
upgrade_contents = response.content
else:
# Read the firmware file contents from the local file path # Read the firmware file contents from the local file path
async with aiofiles.open(file_path, "rb") as f: async with aiofiles.open(file_path, "rb") as f:
upgrade_contents = await f.read() upgrade_contents = await f.read()
@@ -231,11 +227,19 @@ class Auradine(StockFirmware):
await self.ssh.send_command( await self.ssh.send_command(
f"echo {encoded_contents} | base64 -d > /tmp/firmware.tar && sysupgrade /tmp/firmware.tar" f"echo {encoded_contents} | base64 -d > /tmp/firmware.tar && sysupgrade /tmp/firmware.tar"
) )
result = {"success": True} # Assuming success if no exception is raised
else:
result = await self.web.firmware_upgrade(version=version)
if result.get("success", False):
logging.info("Firmware upgrade process completed successfully.") logging.info("Firmware upgrade process completed successfully.")
return True return True
else:
logging.error(f"Firmware upgrade failed: {result.get('error', 'Unknown error')}")
return False
except Exception as e: except Exception as e:
logging.error(f"An error occurred during the firmware upgrade process: {e}", exc_info=True) logging.error(f"An error occurred during the firmware upgrade process: {str(e)}")
return False return False
################################################## ##################################################
@@ -281,7 +285,7 @@ class Auradine(StockFirmware):
except LookupError: except LookupError:
pass pass
async def _get_hashrate(self, rpc_summary: dict = None) -> Optional[AlgoHashRate]: async def _get_hashrate(self, rpc_summary: dict = None) -> Optional[float]:
if rpc_summary is None: if rpc_summary is None:
try: try:
rpc_summary = await self.rpc.summary() rpc_summary = await self.rpc.summary()