From 450a1da8b651d31234a010f8d0a37f7556219cbb Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 29 Oct 2023 20:00:43 +0000 Subject: [PATCH] Add a buy button for support links on videos --- video.py | 24 +++++++++++++++++------- webapp_utils.py | 2 +- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/video.py b/video.py index 0eed60f62..06cfc7eb8 100644 --- a/video.py +++ b/video.py @@ -177,13 +177,23 @@ def convert_video_to_note(base_dir: str, nickname: str, domain: str, } if post_json_object.get('support'): - if isinstance(post_json_object['support'], str): - if not dangerous_markup(post_json_object['support'], - False, []): - if not is_filtered(base_dir, nickname, domain, - post_json_object['support'], + support_str = post_json_object['support'] + if isinstance(support_str, str): + if not dangerous_markup(support_str, False, []): + if not is_filtered(base_dir, nickname, domain, support_str, system_language): - new_post['object']['support'] = \ - post_json_object['support'] + new_post['object']['support'] = support_str + # if this is a link + if ' ' not in support_str and \ + '://' in support_str and \ + '.' in support_str: + # add a buy link + new_post['object']['attachment'].append({ + 'type': 'Link', + 'mediaType': 'html', + 'href': support_str, + 'rel': 'support', + 'name': 'Support' + }) return new_post diff --git a/webapp_utils.py b/webapp_utils.py index 3fd95ee51..217125ed5 100644 --- a/webapp_utils.py +++ b/webapp_utils.py @@ -2319,7 +2319,7 @@ def get_buy_links(post_json_object: str, translate: {}, buy_sites: {}) -> {}: if item.get('rel'): if isinstance(item['rel'], str): if item['rel'] in ('payment', 'pay', 'donate', 'donation', - 'buy', 'purchase'): + 'buy', 'purchase', 'support'): links[item_name] = remove_html(item['href']) continue if buy_sites: