Skip to content
Snippets Groups Projects
Commit 56fb8218 authored by roadscape's avatar roadscape
Browse files

posting_json_md upgrade path

parent 8537a2ef
No related branches found
No related tags found
No related merge requests found
...@@ -185,6 +185,7 @@ class Accounts: ...@@ -185,6 +185,7 @@ class Accounts:
# pull out valid profile md and delete the key # pull out valid profile md and delete the key
profile = safe_profile_metadata(account) profile = safe_profile_metadata(account)
del account['json_metadata']
del account['posting_json_metadata'] del account['posting_json_metadata']
active_at = max(account['created'], active_at = max(account['created'],
......
...@@ -6,12 +6,19 @@ from hive.utils.normalize import trunc ...@@ -6,12 +6,19 @@ from hive.utils.normalize import trunc
def safe_profile_metadata(account): def safe_profile_metadata(account):
"""Given an account, return sanitized profile data.""" """Given an account, return sanitized profile data."""
prof = {} prof = {}
try: try:
# read from posting_json_metadata, if version==2
prof = json.loads(account['posting_json_metadata'])['profile'] prof = json.loads(account['posting_json_metadata'])['profile']
if not isinstance(prof, dict): assert isinstance(prof, dict)
prof = {} assert 'version' in prof and prof['version'] == 2
except Exception: 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 name = str(prof['name']) if 'name' in prof else None
about = str(prof['about']) if 'about' in prof else None about = str(prof['about']) if 'about' in prof else None
......
...@@ -11,6 +11,7 @@ def test_valid_account(): ...@@ -11,6 +11,7 @@ def test_valid_account():
website='http://www.davincilife.com/', website='http://www.davincilife.com/',
cover_image='https://steemitimages.com/0x0/https://pbs.twimg.com/profile_banners/816255358066946050/1483447009/1500x500', 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', profile_image='https://www.parhlo.com/wp-content/uploads/2016/01/tmp617041537745813506.jpg',
version=2,
) )
account = {'name': 'foo', 'posting_json_metadata': json.dumps(dict(profile=raw_profile))} account = {'name': 'foo', 'posting_json_metadata': json.dumps(dict(profile=raw_profile))}
...@@ -26,7 +27,11 @@ def test_invalid_account(): ...@@ -26,7 +27,11 @@ def test_invalid_account():
cover_image='example.com/avatar.jpg', cover_image='example.com/avatar.jpg',
profile_image='https://example.com/valid-url-but-longer-than-1024-chars' + 'x' * 1024, 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) safe_profile = safe_profile_metadata(account)
assert safe_profile['name'] == 'NameIsTooBigByOne...' 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