From cc9d3bff4219f17b5794c2ac9a6adba7ec613dd8 Mon Sep 17 00:00:00 2001 From: Will Miao Date: Wed, 9 Sep 2026 11:47:17 +0800 Subject: [PATCH] fix(download): accept HuggingFace blob URLs in download dialog detectUrlType only matched /resolve/ links, so pasting a HF web preview (/blob/) URL fell through to direct-http and surfaced a misleading 'Invalid CivitAI URL format' error. Treat blob URLs as hf-resolve. --- static/js/managers/DownloadManager.js | 5 +++-- tests/frontend/utils/hfUrlDetection.test.js | 12 ++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/static/js/managers/DownloadManager.js b/static/js/managers/DownloadManager.js index 21327a4c..c5ab53fc 100644 --- a/static/js/managers/DownloadManager.js +++ b/static/js/managers/DownloadManager.js @@ -489,8 +489,9 @@ export class DownloadManager { return { type: 'civitai' }; } - // Hugging Face resolve URL → direct file - const hfResolveMatch = trimmed.match(/huggingface\.co\/([^/\s]+\/[^/\s]+)\/resolve\/([^/\s]+)\/(.+)/i); + // Hugging Face resolve/blob URL → direct file + // "blob" is the web preview page; it maps 1:1 to the "resolve" download URL + const hfResolveMatch = trimmed.match(/huggingface\.co\/([^/\s]+\/[^/\s]+)\/(?:resolve|blob)\/([^/\s]+)\/(.+)/i); if (hfResolveMatch) { return { type: 'hf-resolve', diff --git a/tests/frontend/utils/hfUrlDetection.test.js b/tests/frontend/utils/hfUrlDetection.test.js index 8598d453..76f878fe 100644 --- a/tests/frontend/utils/hfUrlDetection.test.js +++ b/tests/frontend/utils/hfUrlDetection.test.js @@ -55,6 +55,18 @@ describe('DownloadManager.detectUrlType — HF URL detection', () => { }); }); + it('detects HF blob (web preview) URL as resolve', () => { + const result = DownloadManager.detectUrlType( + 'https://huggingface.co/Comfy-Org/z_image_turbo/blob/main/split_files/diffusion_models/z_image_turbo_bf16.safetensors' + ); + expect(result).toEqual({ + type: 'hf-resolve', + repo: 'Comfy-Org/z_image_turbo', + revision: 'main', + filename: 'split_files/diffusion_models/z_image_turbo_bf16.safetensors', + }); + }); + it('detects CivitAI URL', () => { const result = DownloadManager.detectUrlType( 'https://civitai.com/models/123/some-model'