Skip to content
Snippets Groups Projects
Unverified Commit 4866bc6d authored by roadscape's avatar roadscape Committed by GitHub
Browse files

Merge pull request #255 from steemit/229-profile-json

use account posting_json_metadata, close #229
parents a50ffb07 56fb8218
No related branches found
No related tags found
No related merge requests found
......@@ -186,6 +186,7 @@ class Accounts:
# pull out valid profile md and delete the key
profile = safe_profile_metadata(account)
del account['json_metadata']
del account['posting_json_metadata']
active_at = max(account['created'],
account['last_account_update'],
......
......@@ -6,12 +6,19 @@ from hive.utils.normalize import trunc
def safe_profile_metadata(account):
"""Given an account, return sanitized profile data."""
prof = {}
try:
prof = json.loads(account['json_metadata'])['profile']
if not isinstance(prof, dict):
prof = {}
# read from posting_json_metadata, if version==2
prof = json.loads(account['posting_json_metadata'])['profile']
assert isinstance(prof, dict)
assert 'version' in prof and prof['version'] == 2
except Exception:
pass
try:
# fallback to json_metadata
prof = json.loads(account['json_metadata'])['profile']
assert isinstance(prof, dict)
except Exception:
prof = {}
name = str(prof['name']) if 'name' in prof else None
about = str(prof['about']) if 'about' in prof else None
......
......@@ -11,8 +11,9 @@ def test_valid_account():
website='http://www.davincilife.com/',
cover_image='https://steemitimages.com/0x0/https://pbs.twimg.com/profile_banners/816255358066946050/1483447009/1500x500',
profile_image='https://www.parhlo.com/wp-content/uploads/2016/01/tmp617041537745813506.jpg',
version=2,
)
account = {'name': 'foo', 'json_metadata': json.dumps(dict(profile=raw_profile))}
account = {'name': 'foo', 'posting_json_metadata': json.dumps(dict(profile=raw_profile))}
safe_profile = safe_profile_metadata(account)
for key, safe_value in safe_profile.items():
......@@ -26,7 +27,11 @@ def test_invalid_account():
cover_image='example.com/avatar.jpg',
profile_image='https://example.com/valid-url-but-longer-than-1024-chars' + 'x' * 1024,
)
account = {'name': 'foo', 'json_metadata': json.dumps(dict(profile=raw_profile))}
ignore_prof = dict(
name='Ignore me -- missing version:2!',
)
account = {'name': 'foo', 'json_metadata': json.dumps(dict(profile=raw_profile)),
'posting_json_metadata': json.dumps(dict(profile=ignore_prof))}
safe_profile = safe_profile_metadata(account)
assert safe_profile['name'] == 'NameIsTooBigByOne...'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment