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.
This commit is contained in:
+3
-11
@@ -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:
|
||||
|
||||
@@ -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 || '');
|
||||
|
||||
Reference in New Issue
Block a user