From 232daa82f2289dfc9bf58d4b96602dfb88379728 Mon Sep 17 00:00:00 2001 From: Antoine Delplace <34864698+antoinedelplace@users.noreply.github.com> Date: Tue, 28 Nov 2023 11:54:52 +0100 Subject: [PATCH 1/2] Storm prepare by chunk Fix storm prepare to send blocks by chunk --- transferwee.py | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/transferwee.py b/transferwee.py index 8815e93..f1eaefd 100755 --- a/transferwee.py +++ b/transferwee.py @@ -381,16 +381,27 @@ def _storm_prepare(authorization: str, filenames: List[str]) -> dict[Any, Any]: "User-Agent": WETRANSFER_USER_AGENT, }, ) - r = requests.post( - _storm_urls(authorization)["WETRANSFER_STORM_BLOCK"], - json=j, - headers={ - "Authorization": f"Bearer {authorization}", - "Origin": "https://wetransfer.com", - "User-Agent": WETRANSFER_USER_AGENT, - }, - ) - return r.json() + + response = {"ok":True, "data":{"blocks":[]}} + chunk_size = 100 + for i in range(0, len(filenames), chunk_size): + j = { + "blocks": [_storm_prepare_item(f) for f in filenames[i:i+chunk_size]], + } + r = requests.post( + _storm_urls(authorization)["WETRANSFER_STORM_BLOCK"], + json=j, + headers={ + "Authorization": f"Bearer {authorization}", + "Origin": "https://wetransfer.com", + "User-Agent": WETRANSFER_USER_AGENT, + }, + ) + + response["ok"] = response["ok"] and r.json()["ok"] + response["data"]["blocks"] += r.json()["data"]["blocks"] + + return response def _storm_finalize_item( From 36a5ce1ce2821e87af73f92eb93a774ee4f3a9c4 Mon Sep 17 00:00:00 2001 From: Antoine Delplace <34864698+antoinedelplace@users.noreply.github.com> Date: Tue, 28 Nov 2023 12:05:37 +0100 Subject: [PATCH 2/2] Fix copy paste typo Fix copy paste typo --- transferwee.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/transferwee.py b/transferwee.py index f1eaefd..66a465e 100755 --- a/transferwee.py +++ b/transferwee.py @@ -370,9 +370,6 @@ def _storm_prepare(authorization: str, filenames: List[str]) -> dict[Any, Any]: Return the parsed JSON response. """ - j = { - "blocks": [_storm_prepare_item(f) for f in filenames], - } requests.options( _storm_urls(authorization)["WETRANSFER_STORM_BLOCK"], headers={