From c388f3eec8d782e44246953139b3d7031e438788 Mon Sep 17 00:00:00 2001 From: Juan Treminio Date: Wed, 15 Apr 2026 21:46:17 -0500 Subject: [PATCH 1/2] civitai.com -> civitai.red --- src/WebAPI/ModelsAPI.cs | 12 ++++++++-- src/WebAPI/UserUpstreamApiKeys.cs | 2 +- src/wwwroot/js/genpage/gentab/models.js | 8 ++++++- src/wwwroot/js/genpage/utiltab.js | 29 ++++++++++++++++--------- 4 files changed, 37 insertions(+), 14 deletions(-) diff --git a/src/WebAPI/ModelsAPI.cs b/src/WebAPI/ModelsAPI.cs index 7b873d91c..f15cc2684 100644 --- a/src/WebAPI/ModelsAPI.cs +++ b/src/WebAPI/ModelsAPI.cs @@ -606,8 +606,12 @@ public static async Task DoModelDownloadWS(Session session, WebSocket w } string originalUrl = url; url = url.Before('#'); - Dictionary headers = []; if (url.StartsWith("https://civitai.com/")) + { + url = $"https://civitai.red/{url["https://civitai.com/".Length..]}"; + } + Dictionary headers = []; + if (url.StartsWith("https://civitai.red/")) { string civitaiApiKey = session.User.GetGenericData("civitai_api", "key"); if (!string.IsNullOrEmpty(civitaiApiKey)) @@ -757,7 +761,11 @@ public static async Task GetModelHash(Session session, [API.APIDescription("Forwards a metadata request, eg to civitai API.", "")] public static async Task ForwardMetadataRequest(Session session, string url) { - if (!url.StartsWithFast("https://civitai.com/")) + if (url.StartsWithFast("https://civitai.com/")) + { + url = $"https://civitai.red/{url["https://civitai.com/".Length..]}"; + } + if (!url.StartsWithFast("https://civitai.red/")) { return new JObject() { ["error"] = "Invalid URL." }; } diff --git a/src/WebAPI/UserUpstreamApiKeys.cs b/src/WebAPI/UserUpstreamApiKeys.cs index ce01f0494..3078bad9e 100644 --- a/src/WebAPI/UserUpstreamApiKeys.cs +++ b/src/WebAPI/UserUpstreamApiKeys.cs @@ -30,7 +30,7 @@ public static void Register(ApiKeyInfo keyInfo) static UserUpstreamApiKeys() { Register(new("stability_api", "stability", "Stability AI", "https://platform.stability.ai/account/keys", new("To use the Stability AI API in SwarmUI (via the comfy nodes or simple tab), you must set your key."))); - Register(new("civitai_api", "civitai", "Civitai", "https://civitai.com/user/account", new("If you plan to use the Model Downloader utility to download content from Civitai, you will want to set your Civitai API key below.\n
This will allow you to download gated or early-access content that your Civitai account has access to."))); + Register(new("civitai_api", "civitai", "Civitai", "https://civitai.red/user/account", new("If you plan to use the Model Downloader utility to download content from Civitai, you will want to set your Civitai API key below.\n
This will allow you to download gated or early-access content that your Civitai account has access to."))); Register(new("huggingface_api", "huggingface", "Hugging Face", "https://huggingface.co/settings/tokens", new("If you plan to use the Model Downloader utility to download content from Hugging Face, you may want to set your Hugging Face API key below.\n
This will allow you to download gated or private content that your HuggingFace account has access to."))); } } diff --git a/src/wwwroot/js/genpage/gentab/models.js b/src/wwwroot/js/genpage/gentab/models.js index 306ee4b27..4aa7428f6 100644 --- a/src/wwwroot/js/genpage/gentab/models.js +++ b/src/wwwroot/js/genpage/gentab/models.js @@ -161,11 +161,17 @@ function getCivitUrlGuessFor(model) { } let civitUrl = ''; // (Hacky but we don't have a dedicated datastore for this, just included at the top of descriptions generally) - let civitUrlStartIndex = model.description.indexOf(' { callback(null); }); @@ -382,10 +394,7 @@ class ModelDownloaderUtil { } parseCivitaiUrl(url) { - url = url.trim(); - if (url.startsWith(this.civitGreenPrefix)) { - url = this.civitPrefix + url.substring(this.civitGreenPrefix.length); - } + url = this.normalizeCivitaiUrl(url); let parts = splitWithTail(url.substring(this.civitPrefix.length), '/', 4); // 'models', id, name + sometimes version OR 'api', 'download', 'models', versid if (parts.length == 2 && parts[0] == 'models' && parts[1].includes('?')) { let subparts = splitWithTail(parts[1], '?', 2); @@ -475,7 +484,10 @@ class ModelDownloaderUtil { this.metadataZone.dataset.raw = ''; delete this.metadataZone.dataset.image; this.imageSide.innerHTML = ''; - let url = this.url.value.trim(); + let url = this.normalizeCivitaiUrl(this.url.value); + if (url != this.url.value) { + this.url.value = url; + } this.urlRequestId++; let requestId = this.urlRequestId; if (url.endsWith('.pt') || url.endsWith('.pth') || url.endsWith('.ckpt') || url.endsWith('.bin')) { @@ -519,9 +531,6 @@ class ModelDownloaderUtil { this.button.disabled = false; return; } - if (url.startsWith(this.civitGreenPrefix)) { - url = this.civitPrefix + url.substring(this.civitGreenPrefix.length); - } if (url.startsWith(this.civitPrefix)) { let parts = splitWithTail(url.substring(this.civitPrefix.length), '/', 4); // 'models', id, name + sometimes version OR 'api', 'download', 'models', versid if (parts.length == 2 && parts[0] == 'models' && parts[1].includes('?')) { From bfecf8d0ab02d31dec286f1d532058240b8152e8 Mon Sep 17 00:00:00 2001 From: "Alex \"mcmonkey\" Goodwin" Date: Wed, 15 Apr 2026 21:16:34 -0700 Subject: [PATCH 2/2] swap user exposed links back to .com --- src/WebAPI/UserUpstreamApiKeys.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WebAPI/UserUpstreamApiKeys.cs b/src/WebAPI/UserUpstreamApiKeys.cs index 3078bad9e..ce01f0494 100644 --- a/src/WebAPI/UserUpstreamApiKeys.cs +++ b/src/WebAPI/UserUpstreamApiKeys.cs @@ -30,7 +30,7 @@ public static void Register(ApiKeyInfo keyInfo) static UserUpstreamApiKeys() { Register(new("stability_api", "stability", "Stability AI", "https://platform.stability.ai/account/keys", new("To use the Stability AI API in SwarmUI (via the comfy nodes or simple tab), you must set your key."))); - Register(new("civitai_api", "civitai", "Civitai", "https://civitai.red/user/account", new("If you plan to use the Model Downloader utility to download content from Civitai, you will want to set your Civitai API key below.\n
This will allow you to download gated or early-access content that your Civitai account has access to."))); + Register(new("civitai_api", "civitai", "Civitai", "https://civitai.com/user/account", new("If you plan to use the Model Downloader utility to download content from Civitai, you will want to set your Civitai API key below.\n
This will allow you to download gated or early-access content that your Civitai account has access to."))); Register(new("huggingface_api", "huggingface", "Hugging Face", "https://huggingface.co/settings/tokens", new("If you plan to use the Model Downloader utility to download content from Hugging Face, you may want to set your Hugging Face API key below.\n
This will allow you to download gated or private content that your HuggingFace account has access to."))); } }