WIP: New submission system

This commit is contained in:
2023-02-16 16:41:01 +01:00
parent 05042f01c6
commit 4cd37be5dc
5 changed files with 94 additions and 56 deletions

View File

@@ -55,11 +55,13 @@ async def upload_pic(filepath: str) -> Tuple[bool, list]:
try:
pic_name = path.basename(filepath)
files = {'file': (pic_name, open(filepath, 'rb'), 'image/jpeg')}
response = post(f'{configGet("address", "posting", "api")}/albums/{configGet("album", "posting", "api")}/photos&caption=queue', headers={"Authorization": f"Bearer {token}"}, files=files).json()
print(response, flush=True)
response = post(f'{configGet("address", "posting", "api")}/albums/{configGet("album", "posting", "api")}/photos', params={"caption": "queue", "compress": False}, headers={"Authorization": f"Bearer {token}"}, files=files)
if response.status_code != 200 and response.status_code != 409:
logWrite(f"Could not upload '{filepath}' to API: HTTP {response.status_code} with message '{response.content}'")
return False, []
duplicates = []
if "duplicates" in response:
for duplicate in response["duplicates"]:
if "duplicates" in response.json():
for duplicate in response.json()["duplicates"]:
duplicates.append(f'{configGet("address", "posting", "api")}/photos/{duplicate["id"]}')
return True, duplicates
except: