diff options
Diffstat (limited to 'module/web/ajax')
-rw-r--r-- | module/web/ajax/__init__.py | 0 | ||||
-rw-r--r-- | module/web/ajax/models.py | 2 | ||||
-rw-r--r-- | module/web/ajax/tests.py | 23 | ||||
-rw-r--r-- | module/web/ajax/urls.py | 31 | ||||
-rw-r--r-- | module/web/ajax/views.py | 256 |
5 files changed, 0 insertions, 312 deletions
diff --git a/module/web/ajax/__init__.py b/module/web/ajax/__init__.py deleted file mode 100644 index e69de29bb..000000000 --- a/module/web/ajax/__init__.py +++ /dev/null diff --git a/module/web/ajax/models.py b/module/web/ajax/models.py deleted file mode 100644 index 35e0d6486..000000000 --- a/module/web/ajax/models.py +++ /dev/null @@ -1,2 +0,0 @@ - -# Create your models here. diff --git a/module/web/ajax/tests.py b/module/web/ajax/tests.py deleted file mode 100644 index 2247054b3..000000000 --- a/module/web/ajax/tests.py +++ /dev/null @@ -1,23 +0,0 @@ -""" -This file demonstrates two different styles of tests (one doctest and one -unittest). These will both pass when you run "manage.py test". - -Replace these with more appropriate tests for your application. -""" - -from django.test import TestCase - -class SimpleTest(TestCase): - def test_basic_addition(self): - """ - Tests that 1 + 1 always equals 2. - """ - self.failUnlessEqual(1 + 1, 2) - -__test__ = {"doctest": """ -Another way to test that 1 + 1 is equal to 2. - ->>> 1 + 1 == 2 -True -"""} - diff --git a/module/web/ajax/urls.py b/module/web/ajax/urls.py deleted file mode 100644 index a32a00d89..000000000 --- a/module/web/ajax/urls.py +++ /dev/null @@ -1,31 +0,0 @@ -# -*- coding: utf-8 -*- -from django.conf.urls.defaults import * - - -urlpatterns = patterns('ajax', - # Example: - # (r'^pyload/', include('pyload.foo.urls')), - - # Uncomment the admin/doc line below and add 'django.contrib.admindocs' - # to INSTALLED_APPS to enable admin documentation: - # (r'^admin/doc/', include('django.contrib.admindocs.urls')), - - # Uncomment the next line to enable the admin: - (r'^add_package$', 'views.add_package'), - (r'^abort_link/(\d+)$', 'views.abort_link'), - (r'^status$', 'views.status'), - (r'^links$', 'views.links'), #currently active links - (r'^queue$', 'views.queue'), - (r'^pause$', 'views.pause'), - (r'^unpause$', 'views.unpause'), - (r'^cancel$', 'views.cancel'), - (r'^packages$', 'views.packages'), - (r'^package/(\d+)$', 'views.package'), - (r'^link/(\d+)$', 'views.link'), - (r'^remove_package/(\d+)$', 'views.remove_package'), - (r'^restart_package/(\d+)$', 'views.restart_package'), - (r'^remove_link/(\d+)$', 'views.remove_link'), - (r'^restart_link/(\d+)$', 'views.restart_link'), - (r'^push_to_queue/(\d+)$', 'views.push_to_queue'), - (r'^set_captcha$', 'views.set_captcha'), - )
\ No newline at end of file diff --git a/module/web/ajax/views.py b/module/web/ajax/views.py deleted file mode 100644 index 82e478af3..000000000 --- a/module/web/ajax/views.py +++ /dev/null @@ -1,256 +0,0 @@ -# Create your views here. -from os.path import join -import time - -from django.conf import settings -from django.core.serializers import json -from django.http import HttpResponse -from django.http import HttpResponseForbidden -from django.http import HttpResponseServerError -from django.utils import simplejson -from django.utils.translation import ugettext as _ -import base64 - -from traceback import print_exc - -def format_time(seconds): - seconds = int(seconds) - - hours, seconds = divmod(seconds, 3600) - minutes, seconds = divmod(seconds, 60) - return "%.2i:%.2i:%.2i" % (hours, minutes, seconds) - - -def permission(perm): - def _dec(view_func): - def _view(request, * args, ** kwargs): - if request.user.has_perm(perm) and request.user.is_authenticated(): - return view_func(request, * args, ** kwargs) - else: - return HttpResponseForbidden() - - _view.__name__ = view_func.__name__ - _view.__dict__ = view_func.__dict__ - _view.__doc__ = view_func.__doc__ - - return _view - - return _dec - -class JsonResponse(HttpResponse): - def __init__(self, object): - content = simplejson.dumps( - object, indent=2, cls=json.DjangoJSONEncoder, - ensure_ascii=False) - super(JsonResponse, self).__init__( - content)#, content_type='application/json') #@TODO uncomment - self['Cache-Control'] = 'no-cache, must-revalidate' - - -@permission('pyload.can_add') -def add_package(request): - - name = request.POST['add_name'] - - queue = int(request.POST['add_dest']) - - links = request.POST['add_links'].replace(" ", "\n").split("\n") - - try: - f = request.FILES['add_file'] - - if name == None or name == "": - name = f.name - - fpath = join(settings.PYLOAD.get_conf_val("general","download_folder"), "tmp_"+ f.name) - destination = open(fpath, 'wb') - for chunk in f.chunks(): - destination.write(chunk) - destination.close() - links.insert(0, fpath) - except: - pass - - if name == None or name == "": - return HttpResponseServerError() - - links = map(lambda x: x.strip(), links) - links = filter(lambda x: x != "", links) - - - settings.PYLOAD.add_package(name, links, queue) - - return JsonResponse("success") - -@permission('pyload.can_add') -def remove_link(request, id): - try: - settings.PYLOAD.del_links([int(id)]) - return JsonResponse("sucess") - except Exception, e: - return HttpResponseServerError() - -@permission('pyload.can_see_dl') -def status(request): - try: - status = settings.PYLOAD.status_server() - status['captcha'] = settings.PYLOAD.is_captcha_waiting() - return JsonResponse(status) - except: - return HttpResponseServerError() - -@permission('pyload.can_see_dl') -def links(request): - try: - links = settings.PYLOAD.status_downloads() - ids = [] - for link in links: - ids.append(link['id']) - - if link['status'] == 12: - link['info'] = "%s @ %s kb/s" % (link['format_eta'], round(link['speed'], 2)) - elif link['status'] == 5: - link['percent'] = 0 - link['size'] = 0 - link['kbleft'] = 0 - link['info'] = _("waiting %s") % link['format_wait'] - else: - link['info'] = "" - - - data = {} - data['links'] = links - data['ids'] = ids - return JsonResponse(data) - except Exception, e: - return HttpResponseServerError() - -@permission('pyload.can_see_dl') -def queue(request): - try: - return JsonResponse(settings.PYLOAD.get_queue()) - - except: - return HttpResponseServerError() - - -@permission('pyload.can_change_satus') -def pause(request): - try: - return JsonResponse(settings.PYLOAD.pause_server()) - - except: - return HttpResponseServerError() - - -@permission('pyload.can_change_status') -def unpause(request): - try: - return JsonResponse(settings.PYLOAD.unpause_server()) - - except: - return HttpResponseServerError() - - -@permission('pyload.can_change_status') -def cancel(request): - try: - return JsonResponse(settings.PYLOAD.stop_downloads()) - except: - return HttpResponseServerError() - -@permission('pyload.can_see_dl') -def packages(request): - try: - data = settings.PYLOAD.get_queue() - - for package in data: - package['links'] = [] - for file in settings.PYLOAD.get_package_files(package['id']): - package['links'].append(settings.PYLOAD.get_file_info(file)) - - return JsonResponse(data) - - except: - return HttpResponseServerError() - -@permission('pyload.can_see_dl') -def package(request, id): - try: - data = settings.PYLOAD.get_package_data(int(id)) - data['links'] = [] - for file in settings.PYLOAD.get_package_files(data['id']): - data['links'].append(settings.PYLOAD.get_file_info(file)) - - return JsonResponse(data) - - except: - return HttpResponseServerError() - -@permission('pyload.can_see_dl') -def link(request, id): - try: - data = settings.PYLOAD.get_file_info(int(id)) - return JsonResponse(data) - - except: - return HttpResponseServerError() - -@permission('pyload.can_add_dl') -def remove_package(request, id): - try: - settings.PYLOAD.del_packages([int(id)]) - return JsonResponse("sucess") - except Exception, e: - print_exc() - return HttpResponseServerError() - -@permission('pyload.can_add_dl') -def restart_package(request, id): - try: - settings.PYLOAD.restart_package(int(id)) - return JsonResponse("sucess") - except Exception: - return HttpResponseServerError() - -@permission('pyload.can_add_dl') -def restart_link(request, id): - try: - settings.PYLOAD.restart_file(int(id)) - return JsonResponse("sucess") - except Exception: - return HttpResponseServerError() - -@permission('pyload.can_add_dl') -def abort_link(request, id): - try: - settings.PYLOAD.stop_download("link", int(id)) - return JsonResponse("sucess") - except: - return HttpResponseServerError() - -@permission('pyload.can_add_dl') -def push_to_queue(request, id): - try: - settings.PYLOAD.push_package_to_queue(int(id)) - return JsonResponse("sucess") - except: - return HttpResponseServerError() - -@permission('pyload.can_add_dl') -def set_captcha(request): - if request.META['REQUEST_METHOD'] == "POST": - try: - settings.PYLOAD.set_captcha_result(request.POST["cap_id"], request.POST["cap_text"]) - except: - pass - - id, binary, typ = settings.PYLOAD.get_captcha_task() - - if id: - binary = base64.standard_b64encode(str(binary)) - src = "data:image/%s;base64,%s" % (typ, binary) - - return JsonResponse({'captcha': True, 'src': src, 'id': id}) - else: - return JsonResponse({'captcha': False}) |