From 8bafd0cb35c629aa34cad565e80a309e61274343 Mon Sep 17 00:00:00 2001 From: Profitroll <47523801+profitrollgame@users.noreply.github.com> Date: Sun, 19 Feb 2023 20:44:00 +0100 Subject: [PATCH] This commit closes #3 --- classes/poster_client.py | 2 +- config.json | 1 + modules/api_client.py | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/classes/poster_client.py b/classes/poster_client.py index 51c43cd..9c1c876 100644 --- a/classes/poster_client.py +++ b/classes/poster_client.py @@ -42,7 +42,7 @@ class PosterClient(Client): except: raise SubmissionUnavailableError() - response = await upload_pic(str(filepath)) + response = await upload_pic(str(filepath), allow_duplicates=configGet("allow_duplicates", "submission")) if len(response[1]) > 0: raise SubmissionDuplicatesError(str(filepath), response[1]) diff --git a/config.json b/config.json index e8a78cd..cbf9518 100644 --- a/config.json +++ b/config.json @@ -91,6 +91,7 @@ "timeout": 30, "file_size": 15728640, "tmp_size": 15728640, + "allow_duplicates": false, "require_confirmation": { "users": true, "admins": true diff --git a/modules/api_client.py b/modules/api_client.py index 7e7c487..1dd6f6b 100644 --- a/modules/api_client.py +++ b/modules/api_client.py @@ -52,12 +52,12 @@ async def random_pic(token: Union[str, None] = None) -> Tuple[str, str]: pic = choice(resp.json()["results"]) return pic["id"], pic["filename"] -async def upload_pic(filepath: str, token: Union[str, None] = None) -> Tuple[bool, list]: +async def upload_pic(filepath: str, allow_duplicates: bool = False, token: Union[str, None] = None) -> Tuple[bool, list]: token = await authorize() if token is None else token 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', params={"caption": "queue", "compress": False}, headers={"Authorization": f"Bearer {token}"}, files=files) + response = post(f'{configGet("address", "posting", "api")}/albums/{configGet("album", "posting", "api")}/photos', params={"caption": "queue", "compress": False, "ignore_duplicates": allow_duplicates}, 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}'") raise SubmissionUploadError(str(filepath), response.status_code, response.content)