Skip to content

Commit

Permalink
Fixed upload/download region issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
bunnykek authored Jun 24, 2023
1 parent 96b7fcd commit b24dec7
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions WE.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# by bunny
import base64
import json
import re
import time
import requests
import hashlib
import os


class we:
def __init__(self):
"""
Expand All @@ -32,6 +33,7 @@ def upload(self, path: str, display_name: str = '', message: str = ''):
transfer_id = files_response['id']
files = files_response['files']
auth_bearer = files_response['storm_upload_token']
self.endpoints = self.__decodejwt(auth_bearer)
return self.__process_files(files, transfer_id, path, type, auth_bearer)

def download(self, download_url: str, download_path: str = ''):
Expand Down Expand Up @@ -223,9 +225,8 @@ def __batch(self, file_name_bcount, s3_urls, auth_bearer):
'items': items
}
# print(json.dumps(json_data, indent=2))

response = self.__session.post(
'https://storm-eu-west-1.wetransfer.net/api/v2/batch', headers=headers, json=json_data)

response = self.__session.post(self.endpoints['storm.create_batch_url'], headers=headers, json=json_data)
# print(response.status_code)

def __preflight(self, items, auth_bearer: str):
Expand All @@ -238,9 +239,7 @@ def __preflight(self, items, auth_bearer: str):
}

# print(json.dumps(json_data, indent=2))

response = self.__session.post(
'https://storm-eu-west-1.wetransfer.net/api/v2/batch/preflight', json=json_data, headers=headers)
response = self.__session.post(self.endpoints['storm.preflight_batch_url'], json=json_data, headers=headers)

if response.status_code == 200:
return response.json()
Expand All @@ -258,8 +257,7 @@ def __blocks(self, blocks: list, auth_bearer: str):
'blocks': blocks
}

response = self.__session.post(
'https://storm-eu-west-1.wetransfer.net/api/v2/blocks', headers=headers, json=json_data)
response = self.__session.post(self.endpoints['storm.announce_blocks_url'], headers=headers, json=json_data)
rblocks = response.json()['data']['blocks']
for rblock in rblocks:
s3_urls.append([rblock['presigned_put_url'],
Expand Down Expand Up @@ -300,3 +298,8 @@ def __finalize_chunks_upload(self, transfer_id: str):
raise Exception("Finalize error\n", response.text)
else:
return response.json()

def __decodejwt(self, jwt_token):
payload_b64= jwt_token.split('.')[1]
payload = json.loads(base64.b64decode(payload_b64 + '==').decode('utf-8'))
return payload

0 comments on commit b24dec7

Please sign in to comment.