Skip to content

Commit

Permalink
Added modified time to file listing
Browse files Browse the repository at this point in the history
  • Loading branch information
tdorssers committed Mar 16, 2022
1 parent 548fe00 commit a48215c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
17 changes: 13 additions & 4 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@
from collections import OrderedDict
import bottle

##### CONSTANTS ################################################################

BASE_URL = 'http://10.0.0.1:8080/file/' # Default base URL
UPLOAD_DIR = 'uploaded' # Default upload folder
HIDE = r'\..*|autoinstall|media' # Folders to hide

##### FUNCTIONS ################################################################

@bottle.hook('before_request')
def log():
""" Logs request from client to stderr """
Expand Down Expand Up @@ -105,14 +109,19 @@ def post_file():
def get_list():
""" Compiles a list of files and sends it to the web server """
result = []
for root, dirs, files in os.walk('.'):
# Don't visit hidden directories
dirs[:] = [name for name in dirs if not re.match(HIDE, name)]
seen = set()
for root, dirs, files in os.walk('.', followlinks=True):
seen.add(os.path.realpath(root))
# Don't visit hidden and same directories
dirs[:] = [name for name in dirs if not re.match(HIDE, name)
and os.path.realpath(os.path.join(root, name)) not in seen]
if root != '.':
for name in files:
filename = os.path.join(root, name)
stats = os.stat(filename)
mtime = time.strftime('%x %X', time.localtime(stats.st_mtime))
result.append({'file': filename.replace('\\', '/'),
'size': os.path.getsize(filename)})
'time': mtime, 'size': stats.st_size})

# Prepare response header
bottle.response.content_type = 'application/json'
Expand Down
3 changes: 2 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,14 +349,15 @@ function loadList() {
var table = document.createElement('TABLE');
table.id = 'table_file';
var row = table.insertRow(-1);
['path', 'size', 'action'].forEach(function(key) {
['path', 'time', 'size', 'action'].forEach(function(key) {
var cell = document.createElement('TH');
cell.innerHTML = key;
row.appendChild(cell);
});
for (var index = 0; index < files.length; index++) {
var row = table.insertRow(-1);
row.insertCell(-1).innerHTML = files[index].file;
row.insertCell(-1).innerHTML = files[index].time;
row.insertCell(-1).innerHTML = files[index].size;
var cell = row.insertCell(-1);
cell.appendChild(createLink('Download', '/file/' + files[index].file, null));
Expand Down

0 comments on commit a48215c

Please sign in to comment.