فهرست منبع

Change some things in library

Tulir Asokan 4 سال پیش
والد
کامیت
84926284a4
3فایلهای تغییر یافته به همراه15 افزوده شده و 10 حذف شده
  1. 1 1
      mauigpapi/http/base.py
  2. 13 8
      mauigpapi/http/upload.py
  3. 1 1
      mauigpapi/mqtt/conn.py

+ 1 - 1
mauigpapi/http/base.py

@@ -136,7 +136,7 @@ class BaseAndroidAPI:
     async def _handle_response(self, resp: ClientResponse) -> JSON:
         self._handle_response_headers(resp)
         body = await resp.json()
-        if body["status"] == "ok":
+        if body.get("status", "fail") == "ok":
             return body
         else:
             await self._raise_response_error(resp)

+ 13 - 8
mauigpapi/http/upload.py

@@ -20,24 +20,29 @@ import time
 import json
 
 from .base import BaseAndroidAPI
-from ..types import UploadPhotoResponse
+from ..types import UploadPhotoResponse, MediaType
 
 
 class UploadAPI(BaseAndroidAPI):
     async def upload_jpeg_photo(self, data: bytes, upload_id: Optional[str] = None,
                                 is_sidecar: bool = False, waterfall_id: Optional[str] = None,
-                                media_type: int = 1) -> UploadPhotoResponse:
+                                media_type: MediaType = MediaType.IMAGE) -> UploadPhotoResponse:
         upload_id = upload_id or str(time.time())
         name = f"{upload_id}_0_{random.randint(1000000000, 9999999999)}"
         params = {
-            "retry_context": json.dumps(
-                {"num_step_auto_retry": 0, "num_reupload": 0, "num_step_manual_retry": 0}),
-            # TODO enum?
-            "media_type": str(media_type),
+            "retry_context": json.dumps({
+                "num_step_auto_retry": 0,
+                "num_reupload": 0,
+                "num_step_manual_retry": 0,
+            }),
+            "media_type": str(media_type.value),
             "upload_id": upload_id,
             "xsharing_user_ids": json.dumps([]),
-            "image_compression": json.dumps(
-                {"lib_name": "moz", "lib_version": "3.1.m", "quality": 80}),
+            "image_compression": json.dumps({
+                "lib_name": "moz",
+                "lib_version": "3.1.m",
+                "quality": 80
+            }),
         }
         if is_sidecar:
             params["is_sidecar"] = "1"

+ 1 - 1
mauigpapi/mqtt/conn.py

@@ -517,7 +517,7 @@ class AndroidMQTT:
     def send_media(self, thread_id: str, media_id: str, text: str = "", shh_mode: bool = False,
                    client_context: Optional[str] = None,
                    offline_threading_id: Optional[str] = None) -> Awaitable[CommandResponse]:
-        return self.send_item(thread_id, text=text, item_id=media_id, shh_mode=shh_mode,
+        return self.send_item(thread_id, text=text, media_id=media_id, shh_mode=shh_mode,
                               item_type=ThreadItemType.MEDIA_SHARE, client_context=client_context,
                               offline_threading_id=offline_threading_id)