Files
Azornes-Comfyui-Model-Resolver/web/resolver/utils/url_utils.js
T
Dariusz L e0a765af61 Translate url_utils.js comments to English
Translate JSDoc comments for the getModelCardUrl function from Polish to English for better accessibility and consistency across the codebase.
2026-07-02 04:24:11 +02:00

45 lines
1.4 KiB
JavaScript

/**
* URL Utilities for Model Resolver
*/
/**
* Parses the download URL and returns the model card URL.
* Supports HuggingFace and CivitAI platforms.
* @param {string} downloadUrl
* @returns {string|null} Model card URL or null on failure
*/
export function getModelCardUrl(downloadUrl) {
if (!downloadUrl) return null;
try {
// HuggingFace URLs
if (downloadUrl.includes('huggingface.co')) {
const fileMatch = downloadUrl.match(/huggingface\.co\/([^\/]+\/[^\/]+)\/(?:resolve|blob)\/([^\/]+)\/(.+)$/);
if (fileMatch) {
const repo = fileMatch[1];
const revision = fileMatch[2];
const filePath = fileMatch[3].split(/[?#]/)[0];
return `https://huggingface.co/${repo}/blob/${revision}/${filePath}`;
}
const match = downloadUrl.match(/huggingface\.co\/([^\/]+\/[^\/]+)/);
if (match) {
return `https://huggingface.co/${match[1]}`;
}
}
// CivitAI URLs
if (downloadUrl.includes('civitai.com')) {
// Format: /api/download/models/123456 or /models/123456/...
const modelIdMatch = downloadUrl.match(/models\/(\d+)/);
if (modelIdMatch) {
return `https://civitai.com/models/${modelIdMatch[1]}`;
}
}
} catch (e) {
console.error('Error parsing model card URL:', e);
}
return null;
}