From 61ec16e2448bf0378ad5b6b7722d91fbc99285b7 Mon Sep 17 00:00:00 2001 From: roadscape <roadscape@users.noreply.github.com> Date: Thu, 24 Jan 2019 11:41:31 -0600 Subject: [PATCH] preserve json_md image array --- hive/utils/post.py | 11 +++++++---- tests/utils/test_utils_post.py | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/hive/utils/post.py b/hive/utils/post.py index a1e5a14ba..562b5183c 100644 --- a/hive/utils/post.py +++ b/hive/utils/post.py @@ -19,10 +19,13 @@ def post_basic(post): pass thumb_url = '' - if md and 'image' in md and md['image']: - thumb_url = safe_img_url(first(md['image'])) or '' - if thumb_url: - md['image'] = [thumb_url] + if md and 'image' in md: + if md['image']: + if not isinstance(md['image'], list): + md['image'] = [md['image']] + md['image'] = list(filter(None, map(safe_img_url, md['image']))) + if md['image']: + thumb_url = md['image'][0] else: del md['image'] diff --git a/tests/utils/test_utils_post.py b/tests/utils/test_utils_post.py index 21b0dca52..58332e920 100644 --- a/tests/utils/test_utils_post.py +++ b/tests/utils/test_utils_post.py @@ -62,7 +62,7 @@ POST_1 = { "curator_payout_value": "0.000 SBD", "depth": 0, "id": 4437869, - "json_metadata": "{\"tags\":[\"spam\"],\"image\":[\"https://pbs.twimg.com/media/DBgNm3jXoAAioyE.jpg\"],\"app\":\"steemit/0.1\",\"format\":\"markdown\"}", + "json_metadata": "{\"tags\":[\"spam\"],\"image\":[\"ddd\", \"https://pbs.twimg.com/media/DBgNm3jXoAAioyE.jpg\",\"https://example.com/image.jpg\"],\"app\":\"steemit/0.1\",\"format\":\"markdown\"}", "last_payout": "2017-06-27T15:53:51", "last_update": "2017-06-20T15:53:51", "max_accepted_payout": "1000000.000 SBD", @@ -91,7 +91,7 @@ POST_1 = { def test_post_basic(): ret = post_basic(POST_1) - expect = {'json_metadata': {'tags': ['spam'], 'image': ['https://pbs.twimg.com/media/DBgNm3jXoAAioyE.jpg'], 'app': 'steemit/0.1', 'format': 'markdown'}, + expect = {'json_metadata': {'tags': ['spam'], 'image': ['https://pbs.twimg.com/media/DBgNm3jXoAAioyE.jpg', 'https://example.com/image.jpg'], 'app': 'steemit/0.1', 'format': 'markdown'}, 'image': 'https://pbs.twimg.com/media/DBgNm3jXoAAioyE.jpg', 'tags': {'spam'}, 'is_nsfw': False, -- GitLab