mirror of
https://github.com/Xevion/simple-viewer.git
synced 2025-12-06 19:16:29 -06:00
basic file sending/viewing
This commit is contained in:
@@ -37,3 +37,24 @@ def browse(request, directory_id):
|
||||
)
|
||||
}
|
||||
return render(request, 'message.html', context, status=500)
|
||||
|
||||
|
||||
def file(request, directory_id, file):
|
||||
dir = get_object_or_404(ServedDirectory, id=directory_id)
|
||||
if os.path.isdir(dir.path):
|
||||
path = os.path.join(dir.path, file)
|
||||
if os.path.exists(path):
|
||||
return FileResponse(open(path, 'rb'))
|
||||
else:
|
||||
context = {
|
||||
'title': 'Invalid File',
|
||||
'message': 'The file requested from this directory was not found on the server.'
|
||||
}
|
||||
return render(request, 'message.html', context, status=500)
|
||||
context = {
|
||||
'title': 'Invalid Directory',
|
||||
'message': 'The path this server directory points to {}.'.format(
|
||||
'exists, but is not a directory' if os.path.exists(dir.path) else 'does not exist'
|
||||
)
|
||||
}
|
||||
return render(request, 'message.html', context, status=500)
|
||||
|
||||
Reference in New Issue
Block a user