mirror of https://github.com/sc0tfree/updog.git
Merge 5dec63dbb1
into 28a1ac1612
This commit is contained in:
commit
31872de5d7
|
@ -106,7 +106,7 @@ def main():
|
|||
if os.path.exists(requested_path):
|
||||
# Read the files
|
||||
try:
|
||||
directory_files = process_files(os.scandir(requested_path), base_directory)
|
||||
directory_files = process_files(os.scandir(requested_path), base_directory, requested_path)
|
||||
except PermissionError:
|
||||
abort(403, 'Read Permission Denied: ' + requested_path)
|
||||
|
||||
|
|
|
@ -75,14 +75,20 @@
|
|||
{% for file in files %}
|
||||
<tr>
|
||||
<td> <!-- Icon -->
|
||||
{% if file.is_dir %}
|
||||
{% if not file.exists %}
|
||||
<button class="file_ic"><i class="far"></i></button><!-- Dead Symlink -->
|
||||
{% elif file.is_dir %}
|
||||
<button class="file_ic"><i class="far fa-folder"></i></button><!-- Directory icon -->
|
||||
{% else %}
|
||||
<button class="file_ic"><i class="far fa-file"></i></button><!-- File icon -->
|
||||
{% endif %}
|
||||
</td>
|
||||
<td> <!-- Name -->
|
||||
{% if file.exists %}
|
||||
<a href="/{{ file.rel_path }}">{{ file.name }}{% if file.is_dir %}/{% endif %}</a>
|
||||
{% else %}
|
||||
{{ file.name }}{% if file.is_dir %}/{% endif %}
|
||||
{% endif %}
|
||||
</td>
|
||||
<td data-order="{{ file.size_sort }}"> <!-- File size -->
|
||||
{{ file.size }}
|
||||
|
@ -91,7 +97,9 @@
|
|||
{{ file.last_modified }}
|
||||
</td>
|
||||
<td> <!-- View file -->
|
||||
{% if not file.is_dir %}
|
||||
{% if file.is_symlink and not file.exists %}
|
||||
Dead Symbolic Link
|
||||
{% elif not file.is_dir %}
|
||||
<a href="/{{ file.rel_path }}?view">View in browser</a>
|
||||
{% endif %}
|
||||
</td>
|
||||
|
@ -115,4 +123,4 @@
|
|||
<script src="{{ url_for('static', filename='js/main.js') }}"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
|
|
@ -28,23 +28,42 @@ def human_readable_file_size(size):
|
|||
return '{:.4g} {}'.format(size / (1 << (order * 10)), _suffixes[order])
|
||||
|
||||
|
||||
def process_files(directory_files, base_directory):
|
||||
def process_files(directory_files, base_directory, requested_path):
|
||||
files = []
|
||||
for file in directory_files:
|
||||
if file.is_dir():
|
||||
size = '--'
|
||||
size_sort = -1
|
||||
else:
|
||||
size = human_readable_file_size(file.stat().st_size)
|
||||
size_sort = file.stat().st_size
|
||||
|
||||
for file_entry in directory_files:
|
||||
|
||||
path = os.path.join(requested_path, file_entry.name)
|
||||
|
||||
# Default values for display/sort fields
|
||||
|
||||
# Size
|
||||
size = '--'
|
||||
size_sort = -1
|
||||
|
||||
# Last-Modified date
|
||||
last_modified = '???'
|
||||
last_modified_sort = -1
|
||||
|
||||
if os.path.exists(path):
|
||||
last_modified_sort = file_entry.stat().st_mtime
|
||||
last_modified = ctime(last_modified_sort)
|
||||
|
||||
if os.path.isfile(path):
|
||||
# Existing item is a file or a symlink points to a real file
|
||||
size_sort = file_entry.stat().st_size
|
||||
size = human_readable_file_size(size_sort)
|
||||
|
||||
files.append({
|
||||
'name': file.name,
|
||||
'is_dir': file.is_dir(),
|
||||
'rel_path': get_relative_path(file.path, base_directory),
|
||||
'name': file_entry.name,
|
||||
'is_dir': os.path.isdir(path),
|
||||
'rel_path': get_relative_path(file_entry.path, base_directory),
|
||||
'size': size,
|
||||
'size_sort': size_sort,
|
||||
'last_modified': ctime(file.stat().st_mtime),
|
||||
'last_modified_sort': file.stat().st_mtime
|
||||
'last_modified': last_modified,
|
||||
'last_modified_sort': last_modified_sort,
|
||||
'is_symlink': file_entry.is_symlink(),
|
||||
'exists': os.path.exists(path)
|
||||
})
|
||||
return files
|
||||
|
||||
|
|
Loading…
Reference in New Issue