From 011b6f6d91ae0318518ac796b699d91c38a36aa5 Mon Sep 17 00:00:00 2001 From: Krateng Date: Sun, 24 Mar 2019 16:04:44 +0100 Subject: [PATCH] Modularized Javascript --- database.py | 23 +++++----- website/common/header.html | 85 +---------------------------------- website/issues.html | 70 +++++++---------------------- website/javascript/cookies.js | 44 ++++++++++++++++++ website/javascript/search.js | 79 ++++++++++++++++++++++++++++++++ website/setup.html | 49 +++++++++++++------- website/setup.py | 20 +++++++-- 7 files changed, 203 insertions(+), 167 deletions(-) create mode 100644 website/javascript/cookies.js create mode 100644 website/javascript/search.js diff --git a/database.py b/database.py index 38c1332..319cd2a 100644 --- a/database.py +++ b/database.py @@ -670,17 +670,20 @@ def issues(): @dbserver.post("/importrules") def import_rulemodule(): keys = FormsDict.decode(request.forms) - filename = keys.get("filename") - remove = keys.get("remove") is not None - validchars = "'-_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" - filename = "".join(c for c in filename if c in validchars) + apikey = keys.pop("key",None) - if remove: - log("Deactivating predefined rulefile " + filename) - os.remove("rules/" + filename + ".tsv") - else: - log("Importing predefined rulefile " + filename) - os.symlink("predefined/" + filename + ".tsv","rules/" + filename + ".tsv") + if (checkAPIkey(apikey)): + filename = keys.get("filename") + remove = keys.get("remove") is not None + validchars = "-_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" + filename = "".join(c for c in filename if c in validchars) + + if remove: + log("Deactivating predefined rulefile " + filename) + os.remove("rules/" + filename + ".tsv") + else: + log("Importing predefined rulefile " + filename) + os.symlink("predefined/" + filename + ".tsv","rules/" + filename + ".tsv") diff --git a/website/common/header.html b/website/common/header.html index cee4d3c..2f0c4a3 100644 --- a/website/common/header.html +++ b/website/common/header.html @@ -1,86 +1,3 @@ - - - - + diff --git a/website/issues.html b/website/issues.html index 4b58bc4..a1e8d8b 100644 --- a/website/issues.html +++ b/website/issues.html @@ -4,17 +4,18 @@ Maloja - Issues + - - + + - + @@ -22,21 +23,12 @@

Possible Issues


with your library

KEY_ISSUES Issues

- +

Maloja can identify possible problems with consistency or redundancy in your library. After making any changes, you should rebuild your library.
Your API key is required to make any changes to the server:

KEY_ISSUESLIST - + - + diff --git a/website/javascript/cookies.js b/website/javascript/cookies.js new file mode 100644 index 0000000..13ed0f6 --- /dev/null +++ b/website/javascript/cookies.js @@ -0,0 +1,44 @@ +apikeycorrect = false; + +function insertAPIKeyFromCookie() { + cookies = decodeURIComponent(document.cookie).split(';'); + for(var i = 0; i + Artists + ` + + for (var i=0;i + + + ` + } + + html += `
+ ` + name + `
+
+

+ Tracks + ` + + for (var i=0;i "artist=" + encodeURIComponent(x)).join("&"); + uristr = uristr.replace("'","\\'"); + image = "/image?" + uristr; + link = "/track?" + uristr; + + html += ` + + + ` + + } + + html += `
+ ` + artists + `
+ ` + title + ` +
+ ` + + + document.getElementById("resultwrap").innerHTML = html; + } +} + + function clearresults() { + window.setTimeout(reallyclear,500) + } + function reallyclear() { + document.getElementById("resultwrap").innerHTML = ""; + } + + function goto(link) { + window.location = link +} diff --git a/website/setup.html b/website/setup.html index b90bb59..bd817b2 100644 --- a/website/setup.html +++ b/website/setup.html @@ -4,8 +4,11 @@ Maloja - Setup + @@ -53,7 +64,7 @@ - + " + + validchars = "-_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" for f in os.listdir("rules/predefined"): if f.endswith(".tsv"): + rawf = f.replace(".tsv","") + valid = True + for char in rawf: + if char not in validchars: + valid = False + break # don't even show up invalid filenames + + if not valid: continue + if not "_" in rawf: continue + try: with open("rules/predefined/" + f) as tsvfile: line1 = tsvfile.readline() @@ -16,21 +28,21 @@ def instructions(keys): if "# NAME: " in line1: name = line1.replace("# NAME: ","") - else: name = f + else: name = rawf.split("_")[1] if "# DESC: " in line2: desc = line2.replace("# DESC: ","") else: desc = "" - author = f.split("_")[0] + author = rawf.split("_")[0] except: continue html += "" if os.path.exists("rules/" + f): - html += "" + html += "" else: - html += "" + html += "" html += "" html += "" html += ""
@@ -99,7 +110,11 @@ After you've scrobbled for a bit, you might want to check the Issues page to see if you need to set up some rules. You can also manually add rules in your server's "rules" directory - just add your own .tsv file and read the instructions on how to declare a rule.

- You can also set up some predefined rulesets right away! + You can also set up some predefined rulesets right away! Enter your API key and click the buttons. +
+ API Key: + +

KEY_PREDEFINED_RULESETS @@ -117,4 +132,6 @@ Done! Visit yourserver.tld (or your public / proxy URL) to look at your overview page. Almost everything is clickable! + + diff --git a/website/setup.py b/website/setup.py index 5b67892..efb75a9 100644 --- a/website/setup.py +++ b/website/setup.py @@ -6,9 +6,21 @@ def instructions(keys): html += "
ModuleAuthorDescription
Remove:Remove:Add:Add:" + name + "" + author + "" + desc + "