WIP: API change

This commit is contained in:
2023-03-23 15:03:30 +01:00
parent c948f2e34d
commit 2d0d72b026
6 changed files with 168 additions and 59 deletions

View File

@@ -1,9 +1,8 @@
from http import HTTPStatus
from ujson import loads
from os import path, remove, sep
from shutil import rmtree
from typing import Tuple, Union
from photosapi_client.api.default.photo_upload_albums_album_photos_post import (
asyncio as upload_pic,
)
from photosapi_client.models.body_photo_upload_albums_album_photos_post import (
BodyPhotoUploadAlbumsAlbumPhotosPost,
)
@@ -13,7 +12,7 @@ import aiofiles
from pyrogram.client import Client
from pyrogram.types import Message
from classes.exceptions import SubmissionDuplicatesError, SubmissionUnavailableError
from modules.api_client import client
from modules.api_client import client, photo_upload
from modules.database import col_submitted
from bson import ObjectId
from modules.logger import logWrite
@@ -75,7 +74,7 @@ class PosterClient(Client):
async with aiofiles.open(filepath, "rb") as f:
file_bytes = await f.read()
response = await upload_pic(
response = await photo_upload(
album=configGet("album", "posting", "api"),
client=client,
multipart_data=BodyPhotoUploadAlbumsAlbumPhotosPost(
@@ -86,10 +85,20 @@ class PosterClient(Client):
compress=False,
)
if isinstance(response, HTTPValidationError) > 0:
raise SubmissionDuplicatesError(
str(filepath), response.to_dict()["duplicates"]
)
print(response, flush=True)
if response.status_code == HTTPStatus.CONFLICT:
duplicates = []
for index, duplicate in enumerate(loads(response.content)["duplicates"]): # type: ignore
if loads(response.content)["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/{loads(response.content)["access_token"]}?id={index}'
)
raise SubmissionDuplicatesError(str(filepath), duplicates)
col_submitted.find_one_and_update(
{"_id": ObjectId(id)}, {"$set": {"done": True}}
@@ -112,7 +121,7 @@ class PosterClient(Client):
f"Could not delete '{filepath}' on submission accepted", debug=True
)
return submission, response[2]
return submission, response.parsed.id
async def ban_user(self, id: int) -> None:
pass