[mastodon] Change mastodon_create to accept json instead of URL parameters
This commit is contained in:
parent
36638b1c64
commit
cb88c24e2e
|
@ -24,6 +24,12 @@ class BodyMastodonPublic(BaseModel):
|
||||||
instance: str
|
instance: str
|
||||||
|
|
||||||
|
|
||||||
|
class BodyMastodonAccount(BaseModel):
|
||||||
|
email: str
|
||||||
|
instance_url: str
|
||||||
|
password: str
|
||||||
|
|
||||||
|
|
||||||
async def get_mastodon(mastodon_id, hood=Depends(get_hood)):
|
async def get_mastodon(mastodon_id, hood=Depends(get_hood)):
|
||||||
try:
|
try:
|
||||||
return await MastodonAccount.objects.get(id=mastodon_id, hood=hood)
|
return await MastodonAccount.objects.get(id=mastodon_id, hood=hood)
|
||||||
|
@ -138,24 +144,21 @@ async def mastodon_stop(mastodon=Depends(get_mastodon)):
|
||||||
# TODO response_model
|
# TODO response_model
|
||||||
operation_id="create_mastodon",
|
operation_id="create_mastodon",
|
||||||
)
|
)
|
||||||
async def mastodon_create(instance_url, username, password, hood=Depends(get_hood)):
|
async def mastodon_create(values: BodyMastodonAccount, hood=Depends(get_hood)):
|
||||||
"""Add a Mastodon Account to a Ticketfrei account.
|
"""Add a Mastodon Account to a Ticketfrei account.
|
||||||
|
|
||||||
open questions:
|
open questions:
|
||||||
do we really get the username + password like this?
|
|
||||||
can the instance_url have different ways of writing?
|
can the instance_url have different ways of writing?
|
||||||
|
|
||||||
:param: instance_url: the API base URL of the mastodon server
|
:param: values: a BodyMastodonAccount object in json
|
||||||
:param: username: the username of the Mastodon account
|
|
||||||
:param: password: the password of the Mastodon account
|
|
||||||
:param: hood: the hood ORM object
|
:param: hood: the hood ORM object
|
||||||
"""
|
"""
|
||||||
instance = await get_mastodon_instance(instance_url)
|
instance = await get_mastodon_instance(values.instance_url)
|
||||||
account = Mastodon(
|
account = Mastodon(
|
||||||
instance.client_id, instance.client_secret, api_base_url=instance_url
|
instance.client_id, instance.client_secret, api_base_url=values.instance_url
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
access_token = account.log_in(username, password)
|
access_token = account.log_in(values.email, values.password)
|
||||||
except MastodonError:
|
except MastodonError:
|
||||||
logger.warning("Login to Mastodon failed.", exc_info=True)
|
logger.warning("Login to Mastodon failed.", exc_info=True)
|
||||||
return # show error to user
|
return # show error to user
|
||||||
|
|
Loading…
Reference in a new issue