diff --git a/hive/utils/post.py b/hive/utils/post.py index a1e5a14ba937c523205807a35285492b2e1b3fbe..562b5183c64c09c389afac12a920c1aaedc9194f 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 21b0dca520faf10da7dab93e44ed780a18d8ab31..58332e920bab71d8bd6a48614ab672741d6f87e5 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,