Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
H
hivemind
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hive
hivemind
Commits
4866bc6d
Unverified
Commit
4866bc6d
authored
5 years ago
by
roadscape
Committed by
GitHub
5 years ago
Browse files
Options
Downloads
Plain Diff
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
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
hive/indexer/accounts.py
+1
-0
1 addition, 0 deletions
hive/indexer/accounts.py
hive/utils/account.py
+11
-4
11 additions, 4 deletions
hive/utils/account.py
tests/utils/test_utils_account.py
+7
-2
7 additions, 2 deletions
tests/utils/test_utils_account.py
with
19 additions
and
6 deletions
hive/indexer/accounts.py
+
1
−
0
View file @
4866bc6d
...
...
@@ -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
'
],
...
...
This diff is collapsed.
Click to expand it.
hive/utils/account.py
+
11
−
4
View file @
4866bc6d
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
tests/utils/test_utils_account.py
+
7
−
2
View file @
4866bc6d
...
...
@@ -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...
'
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment