refactor
This commit is contained in:
124
main.py
124
main.py
@ -1,15 +1,12 @@
|
||||
import asyncio
|
||||
import getpass
|
||||
import traceback
|
||||
from pathlib import Path
|
||||
from shutil import move
|
||||
from time import sleep
|
||||
|
||||
from aiohttp import ClientTimeout
|
||||
from httpwrapper import AsyncClientConfig, BaseAsyncClient
|
||||
from jsoner import json_read_async, json_write_async
|
||||
|
||||
from functions import move_ipa
|
||||
from models import UdidInfo
|
||||
from wrapper import IPAToolClient
|
||||
|
||||
CACHE_DIR = Path("cache")
|
||||
CACHE_DIR.mkdir(exist_ok=True)
|
||||
@ -18,121 +15,7 @@ APPS_DIR = Path("apps")
|
||||
APPS_DIR.mkdir(exist_ok=True)
|
||||
|
||||
|
||||
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)
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
async def __main(client: IPAToolClient, udid: str, info: UdidInfo):
|
||||
async def __main(client: IPAToolClient, udid: str, info: UdidInfo) -> bool:
|
||||
output_path = f"{info.app_name}.ipa"
|
||||
await client.app_delete(output_path)
|
||||
|
||||
@ -174,7 +57,6 @@ async def _main(client: IPAToolClient, udid: str, info: UdidInfo) -> bool:
|
||||
print(udid, "already have version", version)
|
||||
return False
|
||||
print(udid, "new version", version)
|
||||
# await json_write_async(cache_file, {"version": version})
|
||||
if await __main(client, udid, info):
|
||||
await json_write_async(cache_file, {"version": version})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user