Bug fixes.

This commit is contained in:
Aodhan
2025-07-19 21:46:31 +01:00
parent 7bebc95c09
commit c2ecf93abe
12 changed files with 618 additions and 373 deletions

View File

@@ -65,6 +65,8 @@ class ImageSwipeHandler(BaseHTTPRequestHandler):
self.serve_random_image()
elif path == "/selections":
self.serve_selections()
elif path == "/image-count":
self.serve_image_count()
elif path.startswith("/images/"):
self.serve_image(path[8:])
elif path == "/favicon.ico":
@@ -249,6 +251,68 @@ class ImageSwipeHandler(BaseHTTPRequestHandler):
data = {"selections": get_selections()}
self._json_response(data)
def serve_image_count(self) -> None:
"""Return the total count of images available for the current filter."""
parsed = urllib.parse.urlparse(self.path)
query_params = urllib.parse.parse_qs(parsed.query)
orientation_str = query_params.get("orientation", ["all"])[0]
orientations = [o.strip() for o in orientation_str.split(',')]
search_keywords_str = query_params.get("search", [""])[0].strip()
allow_nsfw = query_params.get("allow_nsfw", ["0"])[0] == "1"
search_keywords = [kw.strip() for kw in search_keywords_str.split(',') if kw.strip()]
actions_str = query_params.get("actions", ["Unactioned"])[0]
actions = [a.strip() for a in actions_str.split(',') if a.strip()]
conn = sqlite3.connect(DB_PATH)
cur = conn.cursor()
query = """
SELECT COUNT(*) FROM image_metadata meta
LEFT JOIN prompt_details pd ON meta.path = pd.image_path
"""
params: List[str] = []
where_clauses = ["(meta.actioned IS NULL OR meta.actioned != 'purged')"]
# Action filter
action_conditions = []
action_params = []
if "Unactioned" in actions:
action_conditions.append("meta.actioned IS NULL")
actions.remove("Unactioned")
if actions:
placeholders = ", ".join("?" for _ in actions)
action_conditions.append(f"meta.actioned IN ({placeholders})")
action_params.extend(actions)
if action_conditions:
where_clauses.append(f"({' OR '.join(action_conditions)})")
params.extend(action_params)
# Orientation filter
if "all" not in orientations and orientations:
placeholders = ", ".join("?" for _ in orientations)
where_clauses.append(f"meta.orientation IN ({placeholders})")
params.extend(orientations)
# NSFW filter
if not allow_nsfw:
where_clauses.append("meta.nsfw = 0")
# Keyword filter
if search_keywords:
for keyword in search_keywords:
# Search only the positive prompt (pd.positive_prompt)
where_clauses.append("pd.positive_prompt LIKE ?")
params.append(f"%{keyword}%")
if where_clauses:
query += " WHERE " + " AND ".join(where_clauses)
cur.execute(query, params)
count = cur.fetchone()[0]
conn.close()
self._json_response({"count": count})
def serve_resolutions(self) -> None:
# Collect resolutions across all configured directories
resolutions_set = set()