Skip to content

Commit

Permalink
Fixed file download issue
Browse files Browse the repository at this point in the history
- this was introduced on 0ceea48
  • Loading branch information
m-haisham committed Feb 23, 2021
1 parent 48c4d9a commit a262324
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
28 changes: 17 additions & 11 deletions qrshare/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ def create_endpoints(self):
def home(id):
# this is used to differentiate from client internal request which requests json
# and browser requests which require html
return_json = request.args.get('json') or False
if return_json:
if request.args.get('raw'):
return {
'name': '~/',
'path': '/',
Expand Down Expand Up @@ -100,20 +99,25 @@ def public_access_point(path):
@self.app.route('/path/<path:path>')
@self.auth.require_auth
def general_access_point(path):
return_json = request.args.get('json') or False
request_raw = request.args.get('raw') or False

route = head = None
try:
route = self.route_map[path]
except KeyError:
if return_json:
route = self.detect(path)
else:
route = self.get_head(path)
head = self.get_head(path)

if route is None:
if route is not None:
is_file = route.is_file
elif head is not None:
is_file = (head.path.parent / path).is_file()
else:
return abort(404)

if return_json:
if is_file or request_raw:
if route is None:
route = self.detect(path, head)

self.map(route)

return route.get()
Expand Down Expand Up @@ -187,14 +191,16 @@ def get_head(self, path) -> Optional[Route]:
if requested_path.exists():
return r

def detect(self, path) -> Optional[Route]:
def detect(self, path, head=None) -> Optional[Route]:
"""
recursively maps upto the given path
:param path: path to map upto
:param head: the head route
:return: route corresponding to the path, if path does not exist returns None
"""
head = self.get_head(path)
if head is None:
head = self.get_head(path)

# get head method can return nothing, in which case the path does not exist
if head is None:
Expand Down
2 changes: 1 addition & 1 deletion qrshare/client/src/pages/main/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
*/
export async function updateStore(path) {
// get data
let data = await requestJson(path + "?json=true");
let data = await requestJson(path + "?raw=true");

// overwrite on the current store
let current = (({ routes, ...others }) => others)(data);
Expand Down

0 comments on commit a262324

Please sign in to comment.