From 1df4cde0d825e33fb804f59fe9fe33c19060d7f8 Mon Sep 17 00:00:00 2001 From: freamon Date: Sat, 18 Jan 2025 00:35:20 +0000 Subject: [PATCH] API: fixes for post create / edit with the app --- app/api/alpha/utils/post.py | 10 +++++++--- app/shared/post.py | 7 ++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/app/api/alpha/utils/post.py b/app/api/alpha/utils/post.py index 12510c8d..c5ee29a0 100644 --- a/app/api/alpha/utils/post.py +++ b/app/api/alpha/utils/post.py @@ -167,7 +167,9 @@ def post_post(auth, data): language_id = 2 # change when Polls are supported - type = None + type = POST_TYPE_ARTICLE + if url: + type = POST_TYPE_LINK input = {'title': title, 'body': body, 'url': url, 'nsfw': nsfw, 'language_id': language_id, 'notify_author': True} community = Community.query.filter_by(id=community_id).one() @@ -193,11 +195,13 @@ def put_post(auth, data): language_id = 2 # change when Polls are supported - type = None + type = POST_TYPE_ARTICLE + if url: + type = POST_TYPE_LINK input = {'title': title, 'body': body, 'url': url, 'nsfw': nsfw, 'language_id': language_id, 'notify_author': True} post = Post.query.filter_by(id=post_id).one() - user_id, post = edit_post(input, post, type, SRC_API, auth) + user_id, post = edit_post(input, post, type, SRC_API, auth=auth) post_json = post_view(post=post, variant=4, user_id=user_id) return post_json diff --git a/app/shared/post.py b/app/shared/post.py index 7804fb12..5116b9d8 100644 --- a/app/shared/post.py +++ b/app/shared/post.py @@ -275,9 +275,10 @@ def edit_post(input, post, type, src, user=None, auth=None, uploaded_file=None, if remove_file: remove_file.delete_from_disk() post.image_id = None - domain = domain_from_url(post.url) - if domain: - domain.post_count -= 1 + if post.url: + domain = domain_from_url(post.url) + if domain: + domain.post_count -= 1 # remove any old tags db.session.execute(text('DELETE FROM "post_tag" WHERE post_id = :post_id'), {'post_id': post.id})