forked from LiveCarta/BookConverter
epub converter: update access.py
This commit is contained in:
@@ -134,6 +134,28 @@ class Access:
|
||||
|
||||
return img_url
|
||||
|
||||
def send_image_by_bytes(self, img_file_path, img_content: bytes, doc_id):
|
||||
if self.is_time_for_refreshing():
|
||||
self.refresh_token()
|
||||
|
||||
self.refreshing.wait()
|
||||
|
||||
files = {
|
||||
'image': (os.path.basename(img_file_path), img_content)
|
||||
}
|
||||
response = requests.post(f'{self.url}/doc-convert/image', files=files, headers=self.headers)
|
||||
|
||||
if response.status_code == 400:
|
||||
self.update_status(doc_id, self.ERROR)
|
||||
raise Exception(f'400 Bad request: {response.json()["message"]}.')
|
||||
elif response.status_code == 200:
|
||||
img_url = response.json()['imageUrl']
|
||||
else:
|
||||
self.update_status(doc_id, self.ERROR)
|
||||
raise Exception(f'{response.status_code}')
|
||||
|
||||
return img_url
|
||||
|
||||
def send_book(self, doc_id, content):
|
||||
if self.is_time_for_refreshing():
|
||||
self.refresh_token()
|
||||
|
||||
Reference in New Issue
Block a user