summaryrefslogtreecommitdiffstats
path: root/module/web/pyload
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2009-12-17 16:14:26 +0100
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2009-12-17 16:14:26 +0100
commit511ae48877f8f3fae2a3ba282d979c33f2ea5491 (patch)
tree946b97a81fa6a3efbc181177e805cee922305a47 /module/web/pyload
parentLittle Rapidshare Fix (diff)
downloadpyload-511ae48877f8f3fae2a3ba282d979c33f2ea5491.tar.xz
webinterface: config working, downloadable files
Diffstat (limited to 'module/web/pyload')
-rw-r--r--module/web/pyload/urls.py2
-rw-r--r--module/web/pyload/views.py67
2 files changed, 64 insertions, 5 deletions
diff --git a/module/web/pyload/urls.py b/module/web/pyload/urls.py
index 667a4ed3d..63badeb25 100644
--- a/module/web/pyload/urls.py
+++ b/module/web/pyload/urls.py
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
from os.path import join
@@ -8,6 +9,7 @@ from django.conf.urls.defaults import *
urlpatterns = patterns('pyload',
(r'^home/$', 'views.home'),
(r'^downloads/$', 'views.downloads',{},'downloads'),
+ (r'^download/(?P<path>[a-zA-z\.0-9\-/_%]+)$', 'views.download',{},'download'),
(r'^queue/$', 'views.queue',{}, 'queue'),
(r'^logs/$', 'views.logs',{}, 'logs'),
(r'^$', 'views.home',{}, 'home'),
diff --git a/module/web/pyload/views.py b/module/web/pyload/views.py
index 405bd2753..0cdc87873 100644
--- a/module/web/pyload/views.py
+++ b/module/web/pyload/views.py
@@ -1,11 +1,17 @@
# Create your views here.
+import mimetypes
from django.http import HttpResponse
from django.http import HttpResponseRedirect
+from django.http import HttpResponseNotFound
from django.conf import settings
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.contrib.auth.decorators import login_required
from os.path import join
+from os.path import isdir
+from os.path import isfile
+from os import listdir
+from os import stat
def check_server(function):
@@ -67,13 +73,64 @@ def queue(request):
@permission('pyload.can_download')
@check_server
def downloads(request):
- return render_to_response(join(settings.TEMPLATE,'downloads.html'), RequestContext(request))
-
+ if not isdir(settings.DL_ROOT):
+ return base(request, ['Download directory not found.'])
+ data = {
+ 'folder': [],
+ 'files': []
+ }
+
+ for item in listdir(settings.DL_ROOT):
+ if isdir(join(settings.DL_ROOT, item)):
+ folder = {
+ 'name' : item,
+ 'files' : []
+ }
+ for file in listdir(join(settings.DL_ROOT, item)):
+ if isfile(join(settings.DL_ROOT, item, file)):
+ folder['files'].append(file)
+
+ data['folder'].append(folder)
+ elif isfile(join(settings.DL_ROOT, item)):
+ data['files'].append(item)
+
+
+ return render_to_response(join(settings.TEMPLATE,'downloads.html'), {'files': data}, RequestContext(request))
+
+@login_required
+@permission('pyload.user.can_download')
+@check_server
+def download(request,path):
+ path = path.split("/")
+
+ dir = join(settings.DL_ROOT, path[1].replace('..',''))
+ if isdir(dir) or isfile(dir):
+ if isdir(dir): filepath = join(dir, path[2])
+ elif isfile(dir): filepath = dir
+
+ print filepath
+ if isfile(filepath):
+ try:
+ type, encoding = mimetypes.guess_type(filepath)
+ if type is None:
+ type = 'application/octet-stream'
+
+ response = HttpResponse(mimetype=type)
+ response['Content-Length'] = str(stat(filepath).st_size)
+
+ if encoding is not None:
+ response['Content-Encoding'] = encoding
+
+ response.write(file(filepath, "rb").read())
+ return response
+
+ except Exception, e:
+ return HttpResponseNotFound("File not Found. %s" % str(e))
+
+ return HttpResponseNotFound("File not Found.")
@login_required
@permission('pyload.user.can_see_logs')
@check_server
def logs(request):
- return render_to_response(join(settings.TEMPLATE,'logs.html'), RequestContext(request))
-
- \ No newline at end of file
+ return render_to_response(join(settings.TEMPLATE,'logs.html'), RequestContext(request)) \ No newline at end of file