diff --git a/myriad/manage.py b/myriad/manage.py index 1fc314c..a63315a 100644 --- a/myriad/manage.py +++ b/myriad/manage.py @@ -62,26 +62,10 @@ def edit(mid): # this specific chunk here is checking whether icons in the myriad/static/icons folder have a link in the database # in case the database was rebuilt, or something else happened, it is a waste of storage keeping an unlinked image - icons = db.execute("SELECT * FROM icons").fetchall() - icon_storage = os.listdir(current_app.config["ICON_UPLOAD_FOLDER"]) - for icon in icon_storage: - in_database = False - for i in icons: - print(i[2], icon) - if i[2] == icon: - in_database = True - if not in_database: - os.remove(os.path.join(current_app.config["ICON_UPLOAD_FOLDER"], icon)) + # and now for the same in reverse - clean the database of references to images that don't exist - for i in icons: - in_storage = False - print(i[2], i[0]) - if i[2] in icon_storage: - in_storage = True - if not in_storage: - db.execute("DELETE FROM icons WHERE id=(?)", (i[0],),) - db.commit() + # the above cleanup operations should be a button in the manage sidebar but for now they are here. @@ -187,4 +171,65 @@ def reset_theme(mid): db.execute("UPDATE member SET card_border=(?), card_bg=(?), heading_bg=(?), heading_border=(?), heading_name=(?), heading_subtitle=(?), card_text=(?), icon_border=(?), a1=(?), a2=(?) WHERE id=(?)",(c9, c10, c11, c12, c13, c14, c15, c16, c21, c22, mid)) db.commit() - return redirect(url_for("manage.edit", mid=mid)) \ No newline at end of file + return redirect(url_for("manage.edit", mid=mid)) + + +@bp.route("/assets") +@login_required +def assets(): + db = get_db() + icons = db.execute("SELECT * FROM icons").fetchall() + icon_storage = os.listdir(current_app.config["ICON_UPLOAD_FOLDER"]) + + i_storage = [] + for icon in icon_storage: + in_database = False + for i in icons: + if i[2] == icon: + in_database = True + if not in_database: + i_storage.append(icon) + + unlinked_icons = [] + for i in icons: + in_storage = False + if i[2] in icon_storage: + in_storage = True + if not in_storage: + unlinked_icons.append(i) + + return render_template("manage/assets.html", icons=unlinked_icons, icon_storage=i_storage) + +@bp.route("/delete_idb") +@login_required +def delete_idb(): + db = get_db() + icons = db.execute("SELECT * FROM icons").fetchall() + icon_storage = os.listdir(current_app.config["ICON_UPLOAD_FOLDER"]) + + for i in icons: + in_storage = False + if i[2] in icon_storage: + in_storage = True + if not in_storage: + db.execute("DELETE FROM icons WHERE id=(?)", (i[0],)) + db.commit() + + return redirect(url_for("manage.assets")) + +@bp.route("/delete_ifiles") +@login_required +def delete_ifiles(): + db = get_db() + icons = db.execute("SELECT * FROM icons").fetchall() + icon_storage = os.listdir(current_app.config["ICON_UPLOAD_FOLDER"]) + + for icon in icon_storage: + in_database = False + for i in icons: + if i[2] == icon: + in_database = True + if not in_database: + os.remove(os.path.join(current_app.config["ICON_UPLOAD_FOLDER"], icon)) + + return redirect(url_for("manage.assets")) \ No newline at end of file diff --git a/myriad/templates/base.html b/myriad/templates/base.html index a3c1778..8fb03cd 100644 --- a/myriad/templates/base.html +++ b/myriad/templates/base.html @@ -14,7 +14,7 @@ {% if g.user %}
Manage
- + {% endif %}
Blog
diff --git a/myriad/templates/manage/assets.html b/myriad/templates/manage/assets.html new file mode 100644 index 0000000..2a7ded0 --- /dev/null +++ b/myriad/templates/manage/assets.html @@ -0,0 +1,41 @@ +{% extends 'base.html' %} + +{% block header %} +
{% block title %}Manage site assets{% endblock %}
+{% endblock %} + +{% block content %} + +
Icons
+ + {% if icon_storage|length > 0 %} + {% for icon in icons %} + + {% endfor %} +
+
+ If there are icons above that won't load, the file itself may be changed or removed

+ Delete links to missing icons from database

+
+ {% else %} +
The database does not contain any moved/deleted icons!
+ {% endif %} + + {% if icon_storage|length > 0 %} + {% for i in icon_storage %} + + {% endfor %} +
+
+ These icons are not linked to any particular member but were found in the icons folder + Delete files in the icons folder that have no link in the database +
+ {% else %} +
There are no images in the icons folder without a database link!
+ {% endif %} + +
Blinkies
+ +
Stamps
+ +{% endblock %} \ No newline at end of file