Neuroapi fixes

This commit is contained in:
2023-11-22 20:13:11 +03:00
parent ccceb16196
commit f03db54d3a
2 changed files with 19 additions and 13 deletions

View File

@@ -1,14 +1,20 @@
import json
from aiohttp import ClientSession
from .api_method import ApiMethod
class Image(ApiMethod):
async def add(self, post_id: str, file_id: str, has_spoiler: bool, message_id: int):
async def add(self, post_id: str, file_id: str, has_spoiler: bool | None, message_id: int):
payload = {'post_id': post_id, 'file_id': file_id,
'has_spoiler': has_spoiler, 'message_id': message_id}
if has_spoiler is None:
payload.pop('has_spoiler')
payload = json.dumps(payload)
async with ClientSession() as session:
response = await session.post(
self.api_url+'/image/add', data=payload)
self.api_url+'/image/add', data=payload, headers={'Content-Type': 'application/json'})
data = await response.json()
if 'statusCode' in data:
raise Exception(data['message'])