This commit closes #3

This commit is contained in:
Profitroll 2023-02-19 20:44:00 +01:00
parent fd47217bad
commit 8bafd0cb35
3 changed files with 4 additions and 3 deletions

View File

@ -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])

View File

@ -91,6 +91,7 @@
"timeout": 30,
"file_size": 15728640,
"tmp_size": 15728640,
"allow_duplicates": false,
"require_confirmation": {
"users": true,
"admins": true

View File

@ -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)