mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-25 08:49:36 +00:00
Fix download gated HF models (#3004)
This commit is contained in:
@@ -357,3 +357,30 @@ export const isCivitaiModelUrl = (url: string): boolean => {
|
||||
/^\/api\/v1\/models-versions\/(\d+)$/.test(pathname)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a Hugging Face download URL to a repository page URL
|
||||
* @param url The download URL to convert
|
||||
* @returns The repository page URL or the original URL if conversion fails
|
||||
* @example
|
||||
* downloadUrlToHfRepoUrl(
|
||||
* 'https://huggingface.co/bfl/FLUX.1/resolve/main/flux1-canny-dev.safetensors?download=true'
|
||||
* ) // https://huggingface.co/bfl/FLUX.1
|
||||
*/
|
||||
export const downloadUrlToHfRepoUrl = (url: string): string => {
|
||||
try {
|
||||
const urlObj = new URL(url)
|
||||
const pathname = urlObj.pathname
|
||||
|
||||
// Use regex to match everything before /resolve/ or /blob/
|
||||
const regex = /^(.*?)(?:\/resolve\/|\/blob\/|$)/
|
||||
const repoPathMatch = regex.exec(pathname)
|
||||
|
||||
// Extract the repository path and remove leading slash if present
|
||||
const repoPath = repoPathMatch?.[1]?.replace(/^\//, '') || ''
|
||||
|
||||
return `https://huggingface.co/${repoPath}`
|
||||
} catch (error) {
|
||||
return url
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user