Acccept pk sk as well as path when updating post

This commit is contained in:
simonwt 2026-04-13 21:56:42 +01:00
parent 921b6f5d95
commit 0a76b6e7f8
3 changed files with 98 additions and 13 deletions

View file

@ -1,6 +1,6 @@
from trustcafeapiwrapper.utils import get_post_pksk, get_parent_pksk_from_path
def update_post(parent_path, post_path, post_text, blur_label=None, card_url=None, collaborative=False):
def update_post( post_text, post_path=None, parent_path='/', post_key=None, blur_label=None, card_url=None, collaborative=False):
"""
Updates an existing post.
@ -15,21 +15,38 @@ def update_post(parent_path, post_path, post_text, blur_label=None, card_url=Non
Returns:
dict: The updated post data.
"""
parent_pksk = get_parent_pksk_from_path(parent_path)
post_pksk = get_post_pksk(parent_pksk, post_path)
if post_key is not None:
post_pksk = {
'pk': post_key.get('pk', None),
'sk': post_key.get('sk', None)
}
elif post_path is not None and parent_path is not None:
parent_pksk = get_parent_pksk_from_path(parent_path)
post_pksk = get_post_pksk(parent_pksk, post_path)
else:
raise ValueError("Either post_path and parent_path or post_key must be provided.")
if post_text is None:
raise ValueError("post_text is required.")
payload = {
"key": {
"pk": post_pksk.get('pk', None),
"sk": post_pksk.get('sk', None)
},
"postSlug": post_path.strip('/post/'),
"blurLabel": blur_label,
"cardUrl": card_url,
"postText": post_text,
"collaborative": collaborative,
"postSlug": post_pksk.get('sk', '').replace('post#', ''),
"postText": post_text
}
if collaborative is not None:
payload["collaborative"] = collaborative
if blur_label is not None:
payload["blurLabel"] = blur_label
if card_url is not None:
payload["cardUrl"] = card_url
return {
"job_function": "post.update",