From 91d21eefb661301c516a5000636cdaf5472b3d27 Mon Sep 17 00:00:00 2001 From: CalamitousFelicitousness Date: Fri, 20 Mar 2026 04:33:12 +0000 Subject: [PATCH] feat(civitai): allow tag-only and sort-only browsing Relax the empty-query guard so search works with tag, sort, or period alone. Skip exact-match name filtering when no keyword is provided so browse results return the full API response. --- modules/civitai/search_civitai.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/modules/civitai/search_civitai.py b/modules/civitai/search_civitai.py index 07fc7f809..e3b116dc2 100644 --- a/modules/civitai/search_civitai.py +++ b/modules/civitai/search_civitai.py @@ -1,3 +1,4 @@ +import re import time from installer import log from modules.civitai.client_civitai import client @@ -20,12 +21,18 @@ def search_civitai( token: str = None, exact: bool = True, ) -> list[CivitModel]: - if not query: - log.error('CivitAI: empty query') + if not query and not tag and not sort: + log.error('CivitAI: no search criteria provided') return [] t0 = time.time() + # URL query → extract model ID (e.g. https://civitai.com/models/967405/nova-orange-xl) + url_match = re.match(r'https?://civitai\.com/models/(\d+)', query.strip()) + if url_match: + query = url_match.group(1) + log.info(f'CivitAI: extracted model id={query} from URL') + # Numeric query → single model fetch if query.isnumeric(): model = client.get_model(int(query), token=token) @@ -49,7 +56,7 @@ def search_civitai( all_models = response.items exact_models: list[CivitModel] = [] - if exact: + if exact and query: q_lower = query.lower() for model in all_models: names = [model.name.lower()]