mirror of
https://github.com/Xevion/simple-viewer.git
synced 2025-12-06 11:16:29 -06:00
added manual refresh functionality, fixed mistake with meaning of File directory field (foreign key not path)
This commit is contained in:
@@ -4,7 +4,6 @@ from django.http import FileResponse, HttpResponseRedirect
|
||||
from django.shortcuts import render, get_object_or_404
|
||||
from django.urls import reverse
|
||||
|
||||
from viewer.helpers import extra_listdir
|
||||
from viewer.models import ServedDirectory
|
||||
|
||||
|
||||
@@ -17,29 +16,29 @@ def index(request):
|
||||
|
||||
|
||||
def browse(request, directory_id):
|
||||
dir = get_object_or_404(ServedDirectory, id=directory_id)
|
||||
directory = get_object_or_404(ServedDirectory, id=directory_id)
|
||||
|
||||
if os.path.isdir(dir.path):
|
||||
if os.path.isdir(directory.path):
|
||||
context = {
|
||||
'title': f'Browse - {os.path.dirname(dir.path)}',
|
||||
'files': extra_listdir(dir.path),
|
||||
'directory': dir
|
||||
'title': f'Browse - {os.path.dirname(directory.path)}',
|
||||
'files': directory.files.all(),
|
||||
'directory': directory
|
||||
}
|
||||
return render(request, 'browse.html', context)
|
||||
else:
|
||||
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'
|
||||
'exists, but is not a directory' if os.path.exists(directory.path) else 'does not exist'
|
||||
)
|
||||
}
|
||||
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)
|
||||
directory = get_object_or_404(ServedDirectory, id=directory_id)
|
||||
if os.path.isdir(directory.path):
|
||||
path = os.path.join(directory.path, file)
|
||||
if os.path.exists(path):
|
||||
return FileResponse(open(path, 'rb'))
|
||||
else:
|
||||
@@ -51,7 +50,7 @@ def file(request, directory_id, file):
|
||||
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'
|
||||
'exists, but is not a directory' if os.path.exists(directory.path) else 'does not exist'
|
||||
)
|
||||
}
|
||||
return render(request, 'message.html', context, status=500)
|
||||
@@ -64,6 +63,13 @@ def add(request):
|
||||
return render(request, 'add.html', context)
|
||||
|
||||
|
||||
def refresh(request, directory_id):
|
||||
"""A simple API view for refreshing a directory. May schedule new thumbnail generation."""
|
||||
directory = get_object_or_404(ServedDirectory, id=directory_id)
|
||||
directory.refresh()
|
||||
return HttpResponseRedirect(reverse('browse', args=(directory.id,)))
|
||||
|
||||
|
||||
def submit_new(request):
|
||||
try:
|
||||
s = ServedDirectory(
|
||||
|
||||
Reference in New Issue
Block a user