handle-no-userid
This commit is contained in:
parent
bf1068d070
commit
6243c27390
|
@ -77,6 +77,8 @@ async def unfollow(_, info, what, slug):
|
||||||
follows = None
|
follows = None
|
||||||
try:
|
try:
|
||||||
user_id = info.context.get('user_id')
|
user_id = info.context.get('user_id')
|
||||||
|
if not user_id:
|
||||||
|
return {"error": "unauthorized"}
|
||||||
follower_query = select(Author).filter(Author.user == user_id)
|
follower_query = select(Author).filter(Author.user == user_id)
|
||||||
[follower] = get_with_stat(follower_query)
|
[follower] = get_with_stat(follower_query)
|
||||||
if follower:
|
if follower:
|
||||||
|
@ -111,10 +113,20 @@ async def unfollow(_, info, what, slug):
|
||||||
|
|
||||||
|
|
||||||
async def get_follows_by_user_id(user_id: str):
|
async def get_follows_by_user_id(user_id: str):
|
||||||
if user_id:
|
if not user_id:
|
||||||
|
return {"error": "unauthorized"}
|
||||||
author = await redis.execute('GET', f'user:{user_id}:author')
|
author = await redis.execute('GET', f'user:{user_id}:author')
|
||||||
|
if isinstance(author, str):
|
||||||
|
author = json.loads(author)
|
||||||
|
if not author:
|
||||||
|
with local_session() as session:
|
||||||
|
author = session.query(Author).filter(Author.user == user_id).first()
|
||||||
|
if not author:
|
||||||
|
return {"error": "cant find author"}
|
||||||
|
author = author.dict()
|
||||||
|
last_seen = author.get('last_seen', 0) if isinstance(author, dict) else 0
|
||||||
follows = DEFAULT_FOLLOWS
|
follows = DEFAULT_FOLLOWS
|
||||||
day_old = int(time.time()) - author.get('last_seen', 0) > 24 * 60 * 60
|
day_old = int(time.time()) - last_seen > 24 * 60 * 60
|
||||||
if day_old:
|
if day_old:
|
||||||
author_id = json.loads(str(author)).get('id')
|
author_id = json.loads(str(author)).get('id')
|
||||||
if author_id:
|
if author_id:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user