From 04c3de9533e24fa9a165e070023931e9cf4fc6d1 Mon Sep 17 00:00:00 2001 From: Dariusz L Date: Thu, 16 Jul 2026 10:27:06 +0200 Subject: [PATCH] refactor: reuse shared path and URL normalization utilities Replace inline regex path/URL normalization in resolver.py and missing_browser_methods.js with the existing shared helpers: - core/resolver.py: normalize_workflow_download_url now uses prepare_remote_size_probe_url from type_utils instead of a local huggingface-specific regex substitution. - web/resolver/views/missing_browser_methods.js: path identity generation now uses normalizePathIdentity from html_utils.js rather than ad hoc replace/trim/lowercase logic. This keeps normalization behavior consistent across the codebase and removes duplicated regex patterns. --- core/resolver.py | 14 +++----------- web/resolver/views/missing_browser_methods.js | 4 ++-- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/core/resolver.py b/core/resolver.py index 5b7884c..014d409 100644 --- a/core/resolver.py +++ b/core/resolver.py @@ -24,7 +24,7 @@ from .workflow_analyzer import ( should_scan_as_model_reference, ) from .matcher import find_matches, strip_known_model_extension -from .type_utils import as_dict, as_list, MODEL_EXTENSIONS as _MODEL_EXTENSIONS, unique_ordered_strings, extract_sha256_from_metadata, normalize_sha256 +from .type_utils import as_dict, as_list, MODEL_EXTENSIONS as _MODEL_EXTENSIONS, unique_ordered_strings, extract_sha256_from_metadata, normalize_sha256, prepare_remote_size_probe_url from .workflow_updater import update_workflow_nodes from .sources.civitai import resolve_urn from .sources.huggingface import parse_huggingface_url as parse_hf_url @@ -499,18 +499,10 @@ def workflow_has_potential_model_references(workflow_json: Dict[str, Any]) -> bo for node in iter_active_workflow_nodes(workflow_json) ) - def normalize_workflow_download_url(url: str) -> str: """Convert workflow file-page URLs into direct download URLs when possible.""" - if not isinstance(url, str) or not url: - return url - - # HuggingFace /blob/ pages return HTML. /resolve/ returns the actual file. - return re.sub( - r"(https?://huggingface\.co/[^/]+/[^/]+)/blob/([^/]+)/(.+)", - r"\1/resolve/\2/\3", - url, - ) + normalized = prepare_remote_size_probe_url(url) + return normalized if normalized is not None else url def workflow_url_points_to_file(url: str, filename: str) -> bool: diff --git a/web/resolver/views/missing_browser_methods.js b/web/resolver/views/missing_browser_methods.js index f382208..73cf55b 100644 --- a/web/resolver/views/missing_browser_methods.js +++ b/web/resolver/views/missing_browser_methods.js @@ -1347,12 +1347,12 @@ export const missingBrowserMethods = { const getLocalModelDedupeIdentity = (entry = {}) => { const path = String(entry.fullPath || entry.model?.path || '').trim(); if (path) { - return path.replace(/[\\/]+/g, '/').toLowerCase(); + return normalizePathIdentity(path); } return [ entry.baseDirectory || '', entry.relativePath || entry.model?.relative_path || entry.model?.filename || '' - ].map(value => String(value || '').trim().replace(/[\\/]+/g, '/').toLowerCase()).join('::'); + ].map(normalizePathIdentity).join('::'); }; const getLocalModelCategoryRank = (category = '', preferredCategory = '') => { const normalized = this.normalizeDownloadCategory(category || '');