diff --git a/flask/app.py b/flask/app.py index fa03818..eb9a2ab 100644 --- a/flask/app.py +++ b/flask/app.py @@ -12,7 +12,7 @@ db.startup() app = Flask(__name__) -## CUSTOM FILTERS +########## CUSTOM FILTERS @app.template_filter('ctime') def timectime(s): return datetime.utcfromtimestamp(s).strftime('%Y-%m-%d %H:%M') @@ -27,7 +27,7 @@ def convsize(s): return str("%.2f" % s)+sizes[n] -## WEB FRONTEND +########## WEB FRONTEND @app.route('/') def homepage(): # try to get userdata, else logout state @@ -95,6 +95,15 @@ def loginpage(): else: return render_template("login.html", title="Login") +@app.route('/logout') +def logout(): + sesskey=request.cookies.get('session') + logged_in,userdata=get_login_info(sesskey) + if not logged_in: + return make_response(redirect('/login')) + db.logout_user(sesskey) + return make_response(redirect('/')) + @app.route('/view/') def viewpage(archid:int): logged_in,userdata=get_login_info(request.cookies.get('session')) @@ -137,7 +146,7 @@ def labeleditpage(archid:int): # GET: return normal labels page labels_name_list=[] for i in labels: - labels_name_list.append(i[0]) + labels_name_list.append(i[1]) return render_template("labels.html", title="Edit Labels",userdata=userdata,login=logged_in,archive=archive,res_labels=label_dict,labels_names=labels_name_list) @app.route('/search') @@ -152,8 +161,10 @@ def searchpage(): sorttype="time" try: category=request.args['category'] + label_dict=db.get_label_labeltypes(int(category)) except Exception as e: category=0 + label_dict={} try: keywords=request.args['q'] keywords="".join(keywords).split(" ") @@ -163,13 +174,23 @@ def searchpage(): count=request.args['count'] except Exception as e: count=20 - archives=db.get_n_archives(sorttype,category,keywords,count) + labels=[] + try: + for i in request.args: + try: + int(i) + labels.append(i) + except Exception as e: + continue + except Exception as e: + labels=[] + archives=db.get_n_archives(sorttype,category,keywords,count,labels) htmlcatlist=get_category_selection() - return render_template("search.html", title="Advanced Search",categories=htmlcatlist,userdata=userdata,login=logged_in,archives=archives) + return render_template("search.html", title="Advanced Search",categories=htmlcatlist,userdata=userdata,login=logged_in,archives=archives,res_labels=label_dict,labels=labels) -## FUNCTIONS +########## FUNCTIONS def errorpage(message): return "

ERROR: " + str(message) + "

Go back and try again" diff --git a/flask/func.py b/flask/func.py index ad5acda..0a89a87 100644 --- a/flask/func.py +++ b/flask/func.py @@ -89,7 +89,7 @@ class db: def check_sesskey(self, sesskey:str): self.cur.execute(f"SELECT SESSKEY,USERID FROM Sessions WHERE SESSKEY='{sesskey}'") entry=self.cur.fetchone() - if sesskey in entry: + if entry and sesskey in entry: return True, entry[1] else: return False, "" @@ -98,6 +98,9 @@ class db: def set_sesskey(self, sesskey:str, userid:int, lifetime:int): self.cur.execute(f"INSERT INTO Sessions(SESSKEY,USERID,CREATED,LIFE) VALUES('{sesskey}',{userid},{time.time()},{lifetime})") + def logout_user(self, sesskey:str): + self.cur.execute(f"DELETE FROM Sessions WHERE SESSKEY='{sesskey}'") + ## Gets and returns all user info about one (1) user ## OUTPUT: tuple=(ID:int,UNAME:str,DNAME:str,CREATED:int,STATE:text,PASSHASH:text) def get_user_info(self, userid:int): @@ -132,7 +135,7 @@ class db: ## Returns all relevant information about one (1) archive ## OUTPUT: archive:tuple=(ID:int,NAME:str,HASH:str,SIZE:int,IMPORTED[UNIX]:int,CATEGORY.ID:int,CATEGORY,str,CATEGORY.DESCRIPTION:str,USER.ID:int,DNAME:str), ## category:tuple=(ID:int,CATEGORY:str,DESCRIPTION:str,PID:int,PCAT:str,PDESC:str) - ## labels:array=[…,(LABEL:str,LABTYPE:int,LABDESC:str),…] + ## labels:list=[…,(ID:int,LABEL:str,LABTYPE:int,LABDESC:str),…] def get_archive_info(self, archid:int): # get info about archive itself self.cur.execute(f"""SELECT Archs.ID,Archs.NAME,Archs.HASH,Archs.SIZE,Archs.IMPORTED,Cats.ID,Cats.CATEGORY,Cats.DESCRIPTION,Users.ID,Users.DNAME FROM Archs @@ -145,14 +148,18 @@ class db: WHERE c.ID={archive[5]} AND c.PARENT=p.ID""") category=self.cur.fetchone() # get info about labels of archive - self.cur.execute(f"""SELECT Labs.LABEL,LabType.ID AS LABTYPE,LabType.DESCRIPTION AS LABDESC FROM ArchLab - JOIN Archs ON Archs.ID=ArchLab.ARCHID - JOIN Labs ON Labs.ID=ArchLab.LABID - JOIN LabType ON Labs.TYPE=LabType.ID - WHERE ARCHID={archid};""") - labels=self.cur.fetchall() + + labels=self.get_label_info(archid) return archive, category, labels + def get_label_info(self, archid:int): + self.cur.execute(f"""SELECT Labs.ID,Labs.LABEL,LabType.ID AS LABTYPE,LabType.DESCRIPTION AS LABDESC FROM ArchLab + JOIN Archs ON Archs.ID=ArchLab.ARCHID + JOIN Labs ON Labs.ID=ArchLab.LABID + JOIN LabType ON Labs.TYPE=LabType.ID + WHERE ARCHID={archid};""") + return self.cur.fetchall() + ## Returns all categories. ## OUTPUT: array=[…,(ID:int,CATEGORY:str,PARENT:int,DESCRIPTION:str),…] def get_categories(self): @@ -220,7 +227,7 @@ class db: ## Returns n archives, sorted by (imported )time or size ## OUTPUT: archives:array=[…,(ID:int,NAME:str,SIZE:str,IMPORTED[UNIX]:int),…] - def get_n_archives(self, sorttype:str="time",category:int=0, keywords:list=[], count:int=20): + def get_n_archives(self, sorttype:str="time",category:int=0, keywords:list=[], count:int=20,labels:list=[]): # TODO: CLEANN!!!!! match sorttype: case "size": sorttype="SIZE DESC" @@ -238,7 +245,7 @@ class db: if len(keywords) == 1: keyword_string+=f"OR HASH = '{keywords[0]}' " - # Get all children of category (if exist) and put into query string + # get all children of category (if exist) and put into query string categories=self.get_categories() catlist=[str(category)] for i in categories: @@ -246,11 +253,27 @@ class db: catlist.append(str(i[0])) categories="(" + ",".join(catlist) + ")" - self.cur.execute(f"""SELECT ID,NAME,SIZE,IMPORTED FROM Archs - {"WHERE 1=1" if category==0 else " WHERE CATEGORY IN " + categories} + self.cur.execute(f"""SELECT Archs.ID,Archs.NAME,Archs.SIZE,Archs.IMPORTED FROM Archs + {"WHERE 1=1" if category==0 else "WHERE CATEGORY IN " + categories} {keyword_string} - ORDER BY {sorttype} LIMIT {count};""") + ORDER BY {sorttype} LIMIT {count if count else 20}""") archives=self.cur.fetchall() + ## WARNING: JANK + #positive_archives=[] + #print("LABELS:", labels) + #if len(labels) >= 1: + # for arch in archives: + # archid=arch[0] + # archive_labels=self.get_label_info(archid) + # success=True + # for label in archive_labels: + # if not label[0] in labels: + # success=False + # if success: + # positive_archives.append(arch) + # if len(positive_archives) >= count: + # break + return archives if __name__ == "__main__": diff --git a/flask/static/base.css b/flask/static/base.css index d759416..02e160f 100644 --- a/flask/static/base.css +++ b/flask/static/base.css @@ -34,6 +34,7 @@ header > div#container { .big-button { height: 2em; + min-width: 2em; margin: auto 0.1em; border: none; border-radius: 0.1em; diff --git a/flask/static/labels.css b/flask/static/labels.css index ea0be13..48ef267 100644 --- a/flask/static/labels.css +++ b/flask/static/labels.css @@ -4,5 +4,5 @@ div.flex-container { } div.flex-item { - display: inline-block; + display: block; } \ No newline at end of file diff --git a/flask/static/search.css b/flask/static/search.css index e69de29..75c58c3 100644 --- a/flask/static/search.css +++ b/flask/static/search.css @@ -0,0 +1,11 @@ +div.grid-selection { + display: grid; + grid-template-columns: max-content auto; +} + +div.select-container { + display: inline-grid; + margin: 0.2em auto; + grid-template-columns: min-content min-content; + grid-template-rows: min-content min-content; +} \ No newline at end of file diff --git a/flask/templates/base.html b/flask/templates/base.html index 55e2ece..c30f55b 100644 --- a/flask/templates/base.html +++ b/flask/templates/base.html @@ -13,17 +13,16 @@ favicon {{title}}
- {% if login %} {% endif %} -
{% if login %} + {% else %} {% endif %} diff --git a/flask/templates/search.html b/flask/templates/search.html index 171d52a..73a129c 100644 --- a/flask/templates/search.html +++ b/flask/templates/search.html @@ -2,27 +2,41 @@ {% block meta %} + {% endblock %} {% block content %}
- Sort by: - -
-
- Category: - + + + + + + Category: + + Count: +
+ {# + #}
{% if request.args.get('q') %} @@ -30,7 +44,6 @@ {% endif %} -
{% if archives|length > 0 %}
diff --git a/flask/templates/view.html b/flask/templates/view.html index 09c0e94..e5e14fd 100644 --- a/flask/templates/view.html +++ b/flask/templates/view.html @@ -16,7 +16,7 @@ Labels: {% if login and userdata[0] == archive[8] %}Edit{% endif %}
{% for lab in labels %} -
{{lab[0]}}
+
{{lab[1]}}
{% endfor %}