added server side directory adding, validation and redirecting, show directory path and mention 'files' near filecount in panel header

This commit is contained in:
Xevion
2020-10-31 18:34:54 -05:00
parent 4cc1402d21
commit 688ffe88dd
3 changed files with 27 additions and 5 deletions

View File

@@ -1,7 +1,8 @@
import os
from django.http import FileResponse, HttpResponse
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
@@ -61,4 +62,25 @@ def add(request):
def submit_new(request):
return HttpResponse('')
try:
s = ServedDirectory(
path=request.POST['path'],
regex_pattern=request.POST.get('regex'),
regex=request.POST.get('regex') is not None,
match_filename=request.POST.get('match_filename', False),
recursive=request.POST.get('recursive', False)
)
if not os.path.isdir(request.POST['path']):
raise ValueError('A invalid Directory was specified in the request.')
s.save()
except KeyError:
return render(request, 'message.html', status=403,
context={'title': 'Invalid Options',
'message': 'The POST request you sent did not have the options required to complete '
'the request.'})
except ValueError:
return render(request, 'message.html', status=400,
context={'title': 'Invalid Directory',
'message': 'The directory you specified was not a valid directory, either it doesn\'t '
'exist or it isn\'t a directory.'})
return HttpResponseRedirect(reverse('browse', args=(s.id,)))