From e707591b02198991f7b6834dcb58b9fc8b42beea Mon Sep 17 00:00:00 2001 From: filoxenace Date: Tue, 6 Jan 2026 14:56:04 -0500 Subject: [PATCH] Fix duplicatee shirts/pants --- src/database.py | 30 +++++++++++++++++++++--------- src/main.py | 6 +++--- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/database.py b/src/database.py index 4943ba8..0dab0a3 100644 --- a/src/database.py +++ b/src/database.py @@ -11,10 +11,12 @@ def init_db(): cursor = conn.cursor() cursor.execute(""" CREATE TABLE IF NOT EXISTS uploaded_assets ( - image_hash TEXT PRIMARY KEY, + image_hash TEXT, + asset_type INTEGER, original_asset_id INTEGER NOT NULL, new_asset_id INTEGER NOT NULL, - created_at DATETIME DEFAULT CURRENT_TIMESTAMP + created_at DATETIME DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (image_hash, asset_type) ) """) cursor.execute(""" @@ -30,29 +32,39 @@ def init_db(): next_retry DATETIME DEFAULT CURRENT_TIMESTAMP ) """) + + # Migration: Add asset_type to uploaded_assets if it doesn't exist + cursor.execute("PRAGMA table_info(uploaded_assets)") + columns = [column[1] for column in cursor.fetchall()] + if "asset_type" not in columns: + cursor.execute("ALTER TABLE uploaded_assets ADD COLUMN asset_type INTEGER") + print("Added asset_type column to uploaded_assets table.") + # Note: Existing items will have asset_type = null, which is fine for now + # as the query handles it. + conn.commit() -def get_uploaded_asset(image_hash: str) -> Optional[int]: +def get_uploaded_asset(image_hash: str, asset_type: int) -> Optional[int]: """ - Checks if an image hash already exists in the database. + Checks if an image hash and asset type already exists in the database. Returns the new_asset_id if found, else None. """ with sqlite3.connect(DB_PATH) as conn: cursor = conn.cursor() cursor.execute( - "SELECT new_asset_id FROM uploaded_assets WHERE image_hash = ?", - (image_hash,) + "SELECT new_asset_id FROM uploaded_assets WHERE image_hash = ? AND asset_type = ?", + (image_hash, asset_type) ) row = cursor.fetchone() return row[0] if row else None -def save_uploaded_asset(image_hash: str, original_asset_id: int, new_asset_id: int): +def save_uploaded_asset(image_hash: str, asset_type: int, original_asset_id: int, new_asset_id: int): """Saves a new upload record to the database.""" with sqlite3.connect(DB_PATH) as conn: cursor = conn.cursor() cursor.execute( - "INSERT INTO uploaded_assets (image_hash, original_asset_id, new_asset_id) VALUES (?, ?, ?)", - (image_hash, original_asset_id, new_asset_id) + "INSERT INTO uploaded_assets (image_hash, asset_type, original_asset_id, new_asset_id) VALUES (?, ?, ?, ?)", + (image_hash, asset_type, original_asset_id, new_asset_id) ) conn.commit() diff --git a/src/main.py b/src/main.py index 3654c25..0c03083 100644 --- a/src/main.py +++ b/src/main.py @@ -117,10 +117,10 @@ async def reupload_asset(asset_id: int, _: str = Depends(verify_api_key)): async with upload_locks[image_hash]: # Double-check database inside the lock - existing_new_id = database.get_uploaded_asset(image_hash) + existing_new_id = database.get_uploaded_asset(image_hash, asset.asset_type) if existing_new_id: - print(f"Asset already uploaded (hash match): {existing_new_id}") + print(f"Asset already uploaded (hash and type match): {existing_new_id}") return {"uploaded": {"asset_id": existing_new_id}} # Prepare description with original URL @@ -137,7 +137,7 @@ async def reupload_asset(asset_id: int, _: str = Depends(verify_api_key)): new_asset_id = uploaded.get("asset_id") if new_asset_id: # Save to database - database.save_uploaded_asset(image_hash, asset_id, new_asset_id) + database.save_uploaded_asset(image_hash, asset.asset_type, asset_id, new_asset_id) try: onsale = await roblox_service.onsale_asset(