From 4b9e8805bc4f74e7b7eb4f04e0e620d10e3d2e16 Mon Sep 17 00:00:00 2001 From: trojvn Date: Thu, 6 Nov 2025 22:54:20 +0300 Subject: [PATCH] refactor --- functions.py | 13 +++++++ wrapper.py | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 121 insertions(+) create mode 100644 functions.py create mode 100644 wrapper.py diff --git a/functions.py b/functions.py new file mode 100644 index 0000000..b81be58 --- /dev/null +++ b/functions.py @@ -0,0 +1,13 @@ +import traceback +from shutil import move +from time import sleep + + +def move_ipa(from_path: str, to_path: str): + while True: + try: + move(from_path, to_path) + return + except Exception: + traceback.print_exc() + sleep(10) diff --git a/wrapper.py b/wrapper.py new file mode 100644 index 0000000..5a20ad3 --- /dev/null +++ b/wrapper.py @@ -0,0 +1,108 @@ +import traceback + +from aiohttp import ClientTimeout +from httpwrapper import AsyncClientConfig, BaseAsyncClient + + +class IPAToolClient(BaseAsyncClient): + def __init__(self, host: str, port: int): + super().__init__( + f"http://{host}:{port}", + config=AsyncClientConfig(timeout=ClientTimeout(300)), + ) + + async def auth(self, user: str, pswd: str) -> bool: + r = await self._post( + "/auth/login", + params={ + "user": user, + "pswd": pswd, + "keychain": pswd, + }, + ) + if r.status != 200: + return False + json_data = await r.json() + if isinstance(json_data, bool): + return json_data + return False + + async def auth_check(self, user: str) -> bool: + r = await self._post("/auth/check", params={"user": user}) + if r.status != 200: + return False + json_data = await r.json() + if isinstance(json_data, bool): + return json_data + return False + + async def app_info(self, query: str, limit: int, keychain: str) -> dict: + r = await self._post( + "/app/search", + params={ + "query": query, + "limit": limit, + "keychain": keychain, + }, + ) + if r.status != 200: + return {} + json_data = await r.json() + if isinstance(json_data, dict): + return json_data + return {} + + async def app_upload(self, output_path: str, save_path: str): + r = await self._get( + "/app/upload", + params={ + "pswd": "81928192", + "output_path": output_path, + }, + ) + if r.status != 200: + return False + try: + content = await r.read() + with open(save_path, "wb") as f: + f.write(content) + return True + except Exception: + traceback.print_exc() + return False + + async def app_download( + self, + bundle_id: str, + output_path: str, + keychain: str, + ) -> bool: + r = await self._post( + "/app/download", + params={ + "keychain": keychain, + "bundle_id": bundle_id, + "output_path": output_path, + }, + ) + if r.status != 200: + return False + json_data = await r.json() + if isinstance(json_data, dict): + return json_data.get("success", False) + return False + + async def app_delete(self, output_path: str) -> bool: + r = await self._delete( + "/app/delete", + params={ + "pswd": "81928192", + "output_path": output_path, + }, + ) + if r.status != 200: + return False + json_data = await r.json() + if isinstance(json_data, bool): + return json_data + return False