Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added support for file downloading

  • Loading branch information...
commit a61bd3092c4af3ade8ca5a95bf3253090401cb51 1 parent 4c44dd0
Håkan Nilsson authored
Showing with 16 additions and 4 deletions.
  1. +12 −0 krabapple.py
  2. +2 −2 static/krabapple.coffee
  3. +2 −2 static/krabapple.js
View
12 krabapple.py
@@ -46,6 +46,18 @@ def json_list(path=''):
content = [file_info(path, f) for f in files if is_visible(f)]
return {"content": content
}
+
+@get('/file/:path#.+#')
+def get_file(path):
+ real_path = os.path.join(ROOT_PATH, path)
+ print real_path
+ if not os.path.exists(real_path):
+ raise HTTPError(404, "File doesn't exist") # Not found
+ if not os.path.isfile(real_path):
+ raise HTTPError(403, "Not a file") # Forbidden
+ return static_file(path, root=ROOT_PATH, download=os.path.basename(path))
+
+
@route('/static/:filename')
def server_static(filename):
return static_file(filename, root='static')
View
4 static/krabapple.coffee
@@ -25,7 +25,7 @@ make_link = (item, div) ->
$(this).parent().parent().children().removeClass('hilight')
$(this).parent().addClass('hilight')
).append(item['name'])
- else
- item['name']
+ else if item['type'] is 'file'
+ $('<a>').attr('href', '/file/' + item['rel_path']).append(item['name'])
$(document).ready(main)
View
4 static/krabapple.js
@@ -34,8 +34,8 @@
$(this).parent().parent().children().removeClass('hilight');
return $(this).parent().addClass('hilight');
}).append(item['name']);
- } else {
- return item['name'];
+ } else if (item['type'] === 'file') {
+ return $('<a>').attr('href', '/file/' + item['rel_path']).append(item['name']);
}
};
Please sign in to comment.
Something went wrong with that request. Please try again.