From 51c97949f1dd12dad7bc2b49f31d27081b12ab75 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 17 May 2023 21:31:50 +0100 Subject: [PATCH] Alternative license representation. See https://blahaj.zone/notes/9ev0kge0aj --- media.py | 2 ++ posts.py | 1 + webapp_post.py | 9 ++++++++- webapp_utils.py | 19 ++++++++++++++++++- 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/media.py b/media.py index d2641fc3a..cbdc158fd 100644 --- a/media.py +++ b/media.py @@ -630,8 +630,10 @@ def attach_media(base_dir: str, http_prefix: str, ] if content_license_url: attachment_json['schema:license'] = content_license_url + attachment_json['license'] = content_license_url if creator: attachment_json['schema:creator'] = creator + attachment_json['attribution'] = creator if media_type.startswith('image/'): attachment_json['blurhash'] = _get_blur_hash() # find the dimensions of the image and add them as metadata diff --git a/posts.py b/posts.py index 4bb0b6985..96661edaa 100644 --- a/posts.py +++ b/posts.py @@ -1146,6 +1146,7 @@ def _attach_post_license(post_json_object: {}, "value": content_license_url }) post_json_object['schema:license'] = content_license_url + post_json_object['license'] = content_license_url def _attach_buy_link(post_json_object: {}, diff --git a/webapp_post.py b/webapp_post.py index 7305f4d81..ebd3650c1 100644 --- a/webapp_post.py +++ b/webapp_post.py @@ -1819,7 +1819,8 @@ def _get_content_license(post_json_object: {}) -> str: """ if not post_json_object['object'].get('attachment'): if not post_json_object['object'].get('schema:license'): - return None + if not post_json_object['object'].get('license'): + return None if post_json_object['object'].get('schema:license'): value = post_json_object['object']['schema:license'] @@ -1827,6 +1828,12 @@ def _get_content_license(post_json_object: {}) -> str: value = license_link_from_name(value) return value + if post_json_object['object'].get('license'): + value = post_json_object['object']['license'] + if '://' not in value: + value = license_link_from_name(value) + return value + for item in post_json_object['object']['attachment']: if not item.get('name'): continue diff --git a/webapp_utils.py b/webapp_utils.py index bd589486a..030854f20 100644 --- a/webapp_utils.py +++ b/webapp_utils.py @@ -1278,14 +1278,31 @@ def get_post_attachments_as_html(base_dir: str, media_license = attach['schema:license'] else: media_license = attach['schema:license'] + elif attach.get('license'): + if not dangerous_markup(attach['license'], False): + if not is_filtered(base_dir, nickname, domain, + attach['license'], + system_language): + if '://' not in attach['license']: + if len(attach['license']) < 60: + media_license = attach['license'] + else: + media_license = attach['license'] media_creator = '' if attach.get('schema:creator'): - if len(attach['schema:creator']) < 60: + if len(attach['schema:creator']) < 120: if not dangerous_markup(attach['schema:creator'], False): if not is_filtered(base_dir, nickname, domain, attach['schema:creator'], system_language): media_creator = attach['schema:creator'] + elif attach.get('attribution'): + if len(attach['attribution']) < 120: + if not dangerous_markup(attach['attribution'], False): + if not is_filtered(base_dir, nickname, domain, + attach['attribution'], + system_language): + media_creator = attach['attribution'] media_type = attach['mediaType'] image_description = ''