Refactored path building and caching on /pp/ route
This commit is contained in:
parent
658eacb45d
commit
ea98d51fb2
2 changed files with 36 additions and 4 deletions
|
@ -1080,6 +1080,7 @@ def remove_follow(username, v):
|
|||
return {"message": "Follower removed!"}
|
||||
|
||||
from urllib.parse import urlparse
|
||||
import re
|
||||
|
||||
@app.get("/pp/<id>")
|
||||
@app.get("/uid/<id>/pic")
|
||||
|
@ -1096,14 +1097,22 @@ def user_profile_uid(v, id):
|
|||
path = cache.get(name)
|
||||
tout = 5 * 60 # 5 min
|
||||
|
||||
# if the path isn't cached then make it
|
||||
if not path:
|
||||
user = get_account(id)
|
||||
path = urlparse(user.profile_url).path
|
||||
if path.startswith('/assets'):
|
||||
path = path.lstrip('/')
|
||||
path = os.path.join(app.root_path, path)
|
||||
cache.set(name,path,timeout=tout)
|
||||
|
||||
|
||||
# if not found, search relative to the root
|
||||
if not os.path.exists(path):
|
||||
path = os.path.join(app.root_path,path.lstrip('/'))
|
||||
cache.set(name,path,timeout=tout)
|
||||
|
||||
# if not found, fail
|
||||
if not os.path.exists(path):
|
||||
cache.set(name,None)
|
||||
abort(404)
|
||||
|
||||
return send_file(path)
|
||||
|
||||
@app.get("/@<username>/pic")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue