From 3c6887b839507e8c4029c1028d55846cbbfd845e Mon Sep 17 00:00:00 2001 From: RaNaN Date: Wed, 11 Sep 2013 12:27:33 +0200 Subject: container upload and url parser for linkgrabber --- pyload/web/api_app.py | 9 ++++- .../web/app/scripts/views/linkgrabber/modalView.js | 45 ++++++++++++++++++++-- .../app/templates/default/linkgrabber/modal.html | 12 ++++-- pyload/web/middlewares.py | 1 + 4 files changed, 57 insertions(+), 10 deletions(-) (limited to 'pyload/web') diff --git a/pyload/web/api_app.py b/pyload/web/api_app.py index b13e3bed9..66cdd58fd 100644 --- a/pyload/web/api_app.py +++ b/pyload/web/api_app.py @@ -2,7 +2,6 @@ # -*- coding: utf-8 -*- from urllib import unquote -from itertools import chain from traceback import format_exc, print_exc from bottle import route, request, response, HTTPError, parse_auth @@ -60,8 +59,14 @@ def call_api(func, args=""): if request.json: kwargs = request.json + # file upload, reads whole file into memory + for name, f in request.files.iteritems(): + print f.length + kwargs["filename"] = f.filename + kwargs[name] = f.value + # convert arguments from json to obj separately - for x, y in chain(request.GET.iteritems(), request.POST.iteritems()): + for x, y in request.params.iteritems(): if not x or not y or x == "session": continue kwargs[x] = loads(unquote(y)) diff --git a/pyload/web/app/scripts/views/linkgrabber/modalView.js b/pyload/web/app/scripts/views/linkgrabber/modalView.js index 808d67f59..8e24f259b 100644 --- a/pyload/web/app/scripts/views/linkgrabber/modalView.js +++ b/pyload/web/app/scripts/views/linkgrabber/modalView.js @@ -6,7 +6,11 @@ define(['jquery', 'underscore', 'backbone', 'app', 'models/CollectorPackage', 'v className: 'modal linkgrabber', events: { - 'keyup #inputLinks': 'addOnKeyUp' + 'keyup #inputLinks': 'addOnKeyUp', + 'click .btn-container': 'selectContainer', + 'change #inputContainer': 'checkContainer', + 'keyup #inputURL': 'checkURL', + 'click .btn-remove-all': 'clearAll' }, template: template, @@ -25,19 +29,19 @@ define(['jquery', 'underscore', 'backbone', 'app', 'models/CollectorPackage', 'v addOnKeyUp: function(e) { // Enter adds the links if (e.keyCode === 13) - this.parseLinks(); + this.checkLinks(); var inputSize = this.$('#inputLinks').val().length; // TODO: checkbox to disable this // add links when several characters was pasted into box if (inputSize > this.inputSize + 4) - this.parseLinks(); + this.checkLinks(); else this.inputSize = inputSize; }, - parseLinks: function() { + checkLinks: function() { var self = this; // split, trim and remove empty links var links = _.filter(_.map(this.$('#inputLinks').val().split('\n'), function(link) { @@ -59,6 +63,39 @@ define(['jquery', 'underscore', 'backbone', 'app', 'models/CollectorPackage', 'v this.inputSize = 0; }, + selectContainer: function(e) { + this.$('#inputContainer').trigger('click'); + }, + + checkContainer: function(e) { + this.$('form').attr('action', App.apiUrl('api/checkContainer')); + this.$('form').trigger('submit'); + }, + + checkURL: function(e) { + // check is triggered on enter + if (e.keyCode !== 13) + return; + + var self = this; + $.ajax(App.apiRequest('checkHTML', { + html: '', + url: $(e.target).val() + }, { + success: function(data) { + self.collectorView.updateData(data); + } + })); + + $(e.target).val(''); + }, + + // deletes every package + clearAll: function(e) { + this.collectorView.collection.reset(); + + }, + // Hide when there are no more packages onAdded: function() { if (this.collectorView !== null) { diff --git a/pyload/web/app/templates/default/linkgrabber/modal.html b/pyload/web/app/templates/default/linkgrabber/modal.html index 750613663..3c50aa037 100755 --- a/pyload/web/app/templates/default/linkgrabber/modal.html +++ b/pyload/web/app/templates/default/linkgrabber/modal.html @@ -14,18 +14,22 @@
-

{{_ "Container" }}

- +
+

{{_ "Container" }}

+ + +
+

{{_ "URL" }}

- +
- {{_ "Packages" }} + {{_ "Packages" }}
diff --git a/pyload/web/middlewares.py b/pyload/web/middlewares.py index 913e714bb..aeb65fde5 100644 --- a/pyload/web/middlewares.py +++ b/pyload/web/middlewares.py @@ -113,6 +113,7 @@ class GzipResponse(object): # TODO: also writes large files to stringbuffer # avoids optimized send_file and causes memory shortage + # pre-gzipped resources would make this obsolete def finish_response(self, app_iter): if self.compressible: output = gzip.GzipFile(mode='wb', compresslevel=self.compress_level, -- cgit v1.2.3