Skip to content

Commit

Permalink
Get global content
Browse files Browse the repository at this point in the history
  • Loading branch information
pylover committed Jan 19, 2020
1 parent 4b2dd4a commit b431f61
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions fittonia.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@


usersroute = app.route(r'/users/([a-zA-Z0-9_]+)(/.*)?')
globalroute = app.route(r'/(.*)?')


class Resource(db.Entity):
Expand All @@ -33,23 +34,6 @@ class Resource(db.Entity):
content = Required(Json)


@usersroute
@dbsession
@json
def get(req, username, path=None):
path = f'/users/{username}{path or ""}'
if path.endswith('/'):
path = path[:-1]

query = Resource.select(lambda r: r.path == path)
resource = query.first()
if resource is None:
raise statuses.notfound()

return resource.content



def ensurepath(req, username, path):
if req.identity.name != username:
raise statuses.forbidden()
Expand Down Expand Up @@ -97,6 +81,22 @@ def update(req, username, path=None):
return req.form


@globalroute
@dbsession
@json
def get(req, path=None):
if path.endswith('/'):
path = path[:-1]

path = f'/{path}'
query = Resource.select(lambda r: r.path == path)
resource = query.first()
if resource is None:
raise statuses.notfound()

return resource.content


if 'SERVER_SOFTWARE' in os.environ: # pragma: no cover
app.ready()

0 comments on commit b431f61

Please sign in to comment.