diff --git a/d2warehouse/app/main.py b/d2warehouse/app/main.py index 30fb10c..afd8347 100644 --- a/d2warehouse/app/main.py +++ b/d2warehouse/app/main.py @@ -5,7 +5,7 @@ import shutil from datetime import datetime import psutil -from d2warehouse.item import Item +from d2warehouse.item import Item, Quality from d2warehouse.parser import parse_stash import d2warehouse.db as base_db from d2warehouse.app.db import get_db, close_db @@ -142,6 +142,38 @@ def list_storage(stash_name: str): ) +@app.route("/storage//") +def list_storage_category(stash_name: str, category: str): + if stash_name not in DB_FILES: + abort(404) + + db = get_stash_db(stash_name) + + if category == "uniques": + q = db.execute( + "SELECT id FROM item INNER JOIN item_extra ON id = item_id WHERE deleted IS NULL AND quality = ?", + (int(Quality.UNIQUE),), + ) + elif category == "sets": + q = db.execute( + "SELECT id FROM item INNER JOIN item_extra ON id = item_id WHERE deleted IS NULL AND quality = ?", + (int(Quality.SET),), + ) + elif category == "misc": + q = db.execute("SELECT id FROM item WHERE deleted IS NULL AND is_simple = TRUE") + else: + return "Unexpected category", 400 + + rows = q.fetchall() + items = {} + for row in rows: + items[row["id"]] = Item.load_from_db(row["id"], db=db) + + return render_template( + "list_storage.html", stash_name=stash_name, storage_items=items + ) + + def backup_stash(stash_name: str) -> None: stash_path = save_path() / STASH_FILES[stash_name] backup_path = save_path() / "backups"