This commit closes #9
This commit is contained in:
@@ -96,7 +96,7 @@ async def random_pic(token: Union[str, None] = None) -> Tuple[str, str]:
|
||||
|
||||
async def upload_pic(
|
||||
filepath: str, allow_duplicates: bool = False, token: Union[str, None] = None
|
||||
) -> Tuple[bool, list, str]:
|
||||
) -> Tuple[bool, list, Union[str, None]]:
|
||||
token = await authorize() if token is None else token
|
||||
try:
|
||||
pic_name = path.basename(filepath)
|
||||
@@ -117,6 +117,7 @@ async def upload_pic(
|
||||
headers={"Authorization": f"Bearer {token}"},
|
||||
data=formdata,
|
||||
)
|
||||
response_json = await response.json()
|
||||
if response.status != 200 and response.status != 409:
|
||||
logWrite(
|
||||
f"Could not upload '{filepath}' to API: HTTP {response.status} with message '{response.content}'"
|
||||
@@ -124,21 +125,22 @@ async def upload_pic(
|
||||
raise SubmissionUploadError(
|
||||
str(filepath), response.status, response.content
|
||||
)
|
||||
id = response_json["id"] if "id" in await response.json() else None
|
||||
duplicates = []
|
||||
if "duplicates" in (await response.json()):
|
||||
for index, duplicate in enumerate((await response.json())["duplicates"]):
|
||||
if (await response.json())["access_token"] is None:
|
||||
if "duplicates" in response_json:
|
||||
for index, duplicate in enumerate(response_json)["duplicates"]: # type: ignore
|
||||
if response_json["access_token"] is None:
|
||||
duplicates.append(
|
||||
f'`{duplicate["id"]}`:\n{configGet("address_external", "posting", "api")}/photos/{duplicate["id"]}'
|
||||
)
|
||||
else:
|
||||
duplicates.append(
|
||||
f'`{duplicate["id"]}`:\n{configGet("address_external", "posting", "api")}/token/photo/{(await response.json())["access_token"]}?id={index}'
|
||||
f'`{duplicate["id"]}`:\n{configGet("address_external", "posting", "api")}/token/photo/{response_json["access_token"]}?id={index}'
|
||||
)
|
||||
return True, duplicates, (await response.json())["id"]
|
||||
return True, duplicates, id
|
||||
except Exception as exp:
|
||||
print_exc()
|
||||
return False, [], ""
|
||||
return False, [], None
|
||||
|
||||
|
||||
async def find_pic(
|
||||
|
Reference in New Issue
Block a user