summaryrefslogtreecommitdiffstats
path: root/module/web/json_app.py
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2011-05-12 21:57:53 +0200
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2011-05-12 21:57:53 +0200
commite269bec1053f059ba0fd701c1e7fa1ad424726bc (patch)
tree70e4ddb3578f7eef435ed563a9d6b7f9bbd9ddbb /module/web/json_app.py
parentfixed js (diff)
downloadpyload-e269bec1053f059ba0fd701c1e7fa1ad424726bc.tar.xz
some fixes, closed #306
Diffstat (limited to 'module/web/json_app.py')
-rw-r--r--module/web/json_app.py180
1 files changed, 68 insertions, 112 deletions
diff --git a/module/web/json_app.py b/module/web/json_app.py
index 5b3b9f1fd..9cf1d236d 100644
--- a/module/web/json_app.py
+++ b/module/web/json_app.py
@@ -25,6 +25,7 @@ def format_time(seconds):
minutes, seconds = divmod(seconds, 60)
return "%.2i:%.2i:%.2i" % (hours, minutes, seconds)
+
def get_sort_key(item):
return item["order"]
@@ -66,6 +67,7 @@ def links():
except Exception, e:
return HTTPError()
+
@route("/json/queue")
@login_required('see_downloads')
def queue():
@@ -104,6 +106,7 @@ def cancel():
except:
return HTTPError()
+
@route("/json/packages")
@login_required('see_downloads')
def packages():
@@ -120,6 +123,7 @@ def packages():
except:
return HTTPError()
+
@route("/json/package/:id")
@validate(id=int)
@login_required('see_downloads')
@@ -151,16 +155,18 @@ def package(id):
except:
return HTTPError()
+
@route("/json/package_order/:ids")
@login_required('add')
def package_order(ids):
try:
pid, pos = ids.split("|")
PYLOAD.order_package(int(pid), int(pos))
- return {"response" : "success"}
+ return {"response": "success"}
except:
return HTTPError()
+
@route("/json/link/:id")
@validate(id=int)
@login_required('see_downloads')
@@ -171,46 +177,51 @@ def link(id):
except:
return HTTPError()
+
@route("/json/remove_link/:id")
@validate(id=int)
@login_required('delete')
def remove_link(id):
try:
PYLOAD.del_links([id])
- return {"response" : "success"}
+ return {"response": "success"}
except Exception, e:
return HTTPError()
+
@route("/json/restart_link/:id")
@validate(id=int)
@login_required('add')
def restart_link(id):
try:
PYLOAD.restart_file(id)
- return {"response" : "success"}
+ return {"response": "success"}
except Exception:
return HTTPError()
+
@route("/json/abort_link/:id")
@validate(id=int)
@login_required('delete')
def abort_link(id):
try:
PYLOAD.stop_download("link", id)
- return {"response" : "success"}
+ return {"response": "success"}
except:
return HTTPError()
+
@route("/json/link_order/:ids")
@login_required('add')
def link_order(ids):
try:
pid, pos = ids.split("|")
PYLOAD.order_file(int(pid), int(pos))
- return {"response" : "success"}
+ return {"response": "success"}
except:
return HTTPError()
+
@route("/json/add_package")
@route("/json/add_package", method="POST")
@login_required('add')
@@ -253,31 +264,34 @@ def add_package():
def remove_package(id):
try:
PYLOAD.del_packages([id])
- return {"response" : "success"}
+ return {"response": "success"}
except Exception, e:
return HTTPError()
+
@route("/json/restart_package/:id")
@validate(id=int)
@login_required('add')
def restart_package(id):
try:
PYLOAD.restart_package(id)
- return {"response" : "success"}
+ return {"response": "success"}
except Exception:
print_exc()
return HTTPError()
+
@route("/json/move_package/:dest/:id")
@validate(dest=int, id=int)
@login_required('add')
def move_package(dest, id):
try:
PYLOAD.move_package(dest, id)
- return {"response" : "success"}
+ return {"response": "success"}
except:
return HTTPError()
+
@route("/json/edit_package", method="POST")
@login_required('add')
def edit_package():
@@ -289,11 +303,12 @@ def edit_package():
"password": request.forms.get("pack_pws").decode("utf8", "ignore")}
PYLOAD.set_package_data(id, data)
- return {"response" : "success"}
+ return {"response": "success"}
except:
return HTTPError()
+
@route("/json/set_captcha")
@route("/json/set_captcha", method="POST")
@login_required('add')
@@ -320,18 +335,19 @@ def set_captcha():
def delete_finished():
return {"del": PYLOAD.delete_finished()}
+
@route("/json/restart_failed")
@login_required('delete')
def restart_failed():
restart = PYLOAD.restart_failed()
if restart: return restart
- return {"response" : "success"}
+ return {"response": "success"}
+
@route("/json/load_config/:category/:section")
@login_required("settings")
def load_config(category, section):
-
conf = None
if category == "general":
conf = PYLOAD.get_config()
@@ -348,14 +364,14 @@ def load_config(category, section):
return render_to_response("settings_item.html", {"skey": section, "section": conf[section]})
+
@route("/json/save_config/:category", method="POST")
@login_required("settings")
def save_config(category):
-
for key, value in request.POST.iteritems():
try:
section, option = key.split("|")
- except :
+ except:
continue
if category == "general": category = "core"
@@ -366,17 +382,16 @@ def save_config(category):
@route("/json/add_account", method="POST")
@login_required("settings")
def add_account():
-
login = request.POST["account_login"]
password = request.POST["account_password"]
type = request.POST["account_type"]
PYLOAD.update_account(type, login, password)
+
@route("/json/update_accounts", method="POST")
@login_required("settings")
def update_accounts():
-
for name, value in request.POST.iteritems():
tmp, user = name.split(";")
plugin, action = tmp.split("|")
@@ -387,124 +402,65 @@ def update_accounts():
PYLOAD.update_account(plugin, user, options={"time": [value]})
elif action == "delete" and value:
PYLOAD.remove_account(plugin, user)
-
+
+
@route("/json/filemanager/rename", method="POST")
@login_required('filemanager')
def rename_dir():
try:
- path = request.forms.get("path").decode("utf8", "ignore")
- old_name = path + "/" + request.forms.get("old_name").decode("utf8", "ignore")
- new_name = path + "/" + request.forms.get("new_name").decode("utf8", "ignore")
-
+ path = decode(request.forms.get("path"))
+ old_name = path + "/" + decode(request.forms.get("old_name"))
+ new_name = path + "/" + decode(request.forms.get("new_name"))
+
try:
- #check if file exists
- os.rename(old_name, new_name);
- except Exception as (errno, strerror):
- return { "response": "fail", "error" : strerror + "\n" + old_name + " => " + new_name }
-
- return {"response" : "success"}
+ #check if file exists
+ os.rename(old_name, new_name)
+ except Exception, e:
+ return {"response": "fail", "error": str(e) + "\n" + old_name + " => " + new_name}
- except:
- return HTTPError()
-
-@route("/json/filemanager/delete", method="POST")
-@login_required('filemanager')
-def rename_dir():
- try:
-
- try:
- path = request.forms.get("path").decode("utf8", "ignore")
- name = request.forms.get("name").decode("utf8", "ignore")
-
- shutil.rmtree(path + "/" + name)
- except Exception as (errno, strerror):
- return { "response": "fail", "error": strerror + "\n" + path + "/" + name }
-
- return {"response" : "success"}
+ return {"response": "success"}
except:
return HTTPError()
-
-@route("/json/filemanager/mkdir", method="POST")
-@login_required('filemanager')
-def make_dir():
- try:
- path = request.forms.get("path").decode("utf8", "ignore")
- name = request.forms.get("name").decode("utf8", "ignore")
- try:
- #i = 1
- #full_name = path + "/" + name
- #while os.path.exists(full_name)
- # full_name = full_name + i
- # i = i + 1
- #
- #os.mkdir(full_name)
-
- os.mkdir(path + "/" + name)
- except Exception as (errno, strerror):
- return { "response": "fail", "error": strerror + "\nUnable to create directory: " + path + "/" + name }
-
- return {"response" : "success", "path": path, "name": name}
- except:
- return HTTPError()
-@route("/json/filemanager/rename", method="POST")
-@login_required('filemanager')
-def rename_dir():
- try:
- path = request.forms.get("path").decode("utf8", "ignore")
- old_name = path + "/" + request.forms.get("old_name").decode("utf8", "ignore")
- new_name = path + "/" + request.forms.get("new_name").decode("utf8", "ignore")
-
- try:
- #check if file exists
- os.rename(old_name, new_name);
- except Exception as (errno, strerror):
- return { "response": "fail", "error" : strerror + "\n" + old_name + " => " + new_name }
-
- return {"response" : "success"}
- except:
- return HTTPError()
-
@route("/json/filemanager/delete", method="POST")
@login_required('filemanager')
-def rename_dir():
+def delete_dir():
try:
-
- try:
- path = request.forms.get("path").decode("utf8", "ignore")
- name = request.forms.get("name").decode("utf8", "ignore")
-
- shutil.rmtree(path + "/" + name)
- except Exception as (errno, strerror):
- return { "response": "fail", "error": strerror + "\n" + path + "/" + name }
-
- return {"response" : "success"}
+ try:
+ path = decode(request.forms.get("path"))
+ name = decode(request.forms.get("name"))
+ shutil.rmtree(path + "/" + name)
+ except Exception, e:
+ return {"response": "fail", "error": str(e) + "\n" + path + "/" + name}
+
+ return {"response": "success"}
except:
return HTTPError()
-
+
+
@route("/json/filemanager/mkdir", method="POST")
@login_required('filemanager')
def make_dir():
try:
- path = request.forms.get("path").decode("utf8", "ignore")
- name = request.forms.get("name").decode("utf8", "ignore")
- try:
- #i = 1
- #full_name = path + "/" + name
- #while os.path.exists(full_name)
- # full_name = full_name + i
- # i = i + 1
- #
- #os.mkdir(full_name)
-
- os.mkdir(path + "/" + name)
- except Exception as (errno, strerror):
- return { "response": "fail", "error": strerror + "\nUnable to create directory: " + path + "/" + name }
-
- return {"response" : "success", "path": path, "name": name}
+ path = decode(request.forms.get("path"))
+ name = decode(request.forms.get("name"))
+ try:
+ #i = 1
+ #full_name = path + "/" + name
+ #while os.path.exists(full_name)
+ # full_name = full_name + i
+ # i = i + 1
+ #
+ #os.mkdir(full_name)
+
+ os.mkdir(path + "/" + name)
+ except Exception, e:
+ return {"response": "fail", "error": str(e) + "\nUnable to create directory: " + path + "/" + name}
+
+ return {"response": "success", "path": path, "name": name}
except:
return HTTPError() \ No newline at end of file