Skip to content

Commit 619a7b1

Browse files
civitai.com -> civitai.red (#1349)
* civitai.com -> civitai.red * swap user exposed links back to .com --------- Co-authored-by: Alex "mcmonkey" Goodwin <git_commits@alexgoodwin.dev>
1 parent aa77ba4 commit 619a7b1

3 files changed

Lines changed: 36 additions & 13 deletions

File tree

src/WebAPI/ModelsAPI.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,8 +606,12 @@ public static async Task<JObject> DoModelDownloadWS(Session session, WebSocket w
606606
}
607607
string originalUrl = url;
608608
url = url.Before('#');
609-
Dictionary<string, string> headers = [];
610609
if (url.StartsWith("https://civitai.com/"))
610+
{
611+
url = $"https://civitai.red/{url["https://civitai.com/".Length..]}";
612+
}
613+
Dictionary<string, string> headers = [];
614+
if (url.StartsWith("https://civitai.red/"))
611615
{
612616
string civitaiApiKey = session.User.GetGenericData("civitai_api", "key");
613617
if (!string.IsNullOrEmpty(civitaiApiKey))
@@ -757,7 +761,11 @@ public static async Task<JObject> GetModelHash(Session session,
757761
[API.APIDescription("Forwards a metadata request, eg to civitai API.", "")]
758762
public static async Task<JObject> ForwardMetadataRequest(Session session, string url)
759763
{
760-
if (!url.StartsWithFast("https://civitai.com/"))
764+
if (url.StartsWithFast("https://civitai.com/"))
765+
{
766+
url = $"https://civitai.red/{url["https://civitai.com/".Length..]}";
767+
}
768+
if (!url.StartsWithFast("https://civitai.red/"))
761769
{
762770
return new JObject() { ["error"] = "Invalid URL." };
763771
}

src/wwwroot/js/genpage/gentab/models.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,17 @@ function getCivitUrlGuessFor(model) {
161161
}
162162
let civitUrl = '';
163163
// (Hacky but we don't have a dedicated datastore for this, just included at the top of descriptions generally)
164-
let civitUrlStartIndex = model.description.indexOf('<a href="https://civitai.com/models/');
164+
let civitUrlStartIndex = model.description.indexOf('<a href="https://civitai.red/models/');
165+
if (civitUrlStartIndex == -1) {
166+
civitUrlStartIndex = model.description.indexOf('<a href="https://civitai.com/models/');
167+
}
165168
if (civitUrlStartIndex != -1) {
166169
let end = model.description.indexOf('"', civitUrlStartIndex + '<a href="'.length);
167170
if (end != -1) {
168171
civitUrl = model.description.substring(civitUrlStartIndex + '<a href="'.length, end);
172+
if (civitUrl.startsWith('https://civitai.com/')) {
173+
civitUrl = `https://civitai.red/${civitUrl.substring('https://civitai.com/'.length)}`;
174+
}
169175
if (!civitUrl.includes("?modelVersionId=") || civitUrl.length > 200 || civitUrl.includes("?modelVersionId=null")) {
170176
console.log(`Invalid CivitAI URL (failed sanity check): ${civitUrl}`);
171177
civitUrl = '';

src/wwwroot/js/genpage/utiltab.js

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,23 @@ class ModelDownloaderUtil {
184184
this.activeZone = getRequiredElementById('model_downloader_right_sidebar');
185185
this.folders = getRequiredElementById('model_downloader_folder');
186186
this.hfPrefix = 'https://huggingface.co/';
187-
this.civitPrefix = 'https://civitai.com/';
187+
this.civitPrefix = 'https://civitai.red/';
188+
this.civitOldPrefix = 'https://civitai.com/';
188189
this.civitGreenPrefix = 'https://civitai.green/';
189190
this.urlRequestId = 0;
190191
}
191192

193+
normalizeCivitaiUrl(url) {
194+
url = url.trim();
195+
if (url.startsWith(this.civitGreenPrefix)) {
196+
return this.civitPrefix + url.substring(this.civitGreenPrefix.length);
197+
}
198+
if (url.startsWith(this.civitOldPrefix)) {
199+
return this.civitPrefix + url.substring(this.civitOldPrefix.length);
200+
}
201+
return url;
202+
}
203+
192204
buildFolderSelector(selector) {
193205
if (!coreModelMap) {
194206
return;
@@ -238,7 +250,7 @@ class ModelDownloaderUtil {
238250
callback(null);
239251
return;
240252
}
241-
callback(`https://civitai.com/models/${rawData.response.modelId}?modelVersionId=${rawData.response.id}`);
253+
callback(`https://civitai.red/models/${rawData.response.modelId}?modelVersionId=${rawData.response.id}`);
242254
}, 0, () => {
243255
callback(null);
244256
});
@@ -382,10 +394,7 @@ class ModelDownloaderUtil {
382394
}
383395

384396
parseCivitaiUrl(url) {
385-
url = url.trim();
386-
if (url.startsWith(this.civitGreenPrefix)) {
387-
url = this.civitPrefix + url.substring(this.civitGreenPrefix.length);
388-
}
397+
url = this.normalizeCivitaiUrl(url);
389398
let parts = splitWithTail(url.substring(this.civitPrefix.length), '/', 4); // 'models', id, name + sometimes version OR 'api', 'download', 'models', versid
390399
if (parts.length == 2 && parts[0] == 'models' && parts[1].includes('?')) {
391400
let subparts = splitWithTail(parts[1], '?', 2);
@@ -475,7 +484,10 @@ class ModelDownloaderUtil {
475484
this.metadataZone.dataset.raw = '';
476485
delete this.metadataZone.dataset.image;
477486
this.imageSide.innerHTML = '';
478-
let url = this.url.value.trim();
487+
let url = this.normalizeCivitaiUrl(this.url.value);
488+
if (url != this.url.value) {
489+
this.url.value = url;
490+
}
479491
this.urlRequestId++;
480492
let requestId = this.urlRequestId;
481493
if (url.endsWith('.pt') || url.endsWith('.pth') || url.endsWith('.ckpt') || url.endsWith('.bin')) {
@@ -519,9 +531,6 @@ class ModelDownloaderUtil {
519531
this.button.disabled = false;
520532
return;
521533
}
522-
if (url.startsWith(this.civitGreenPrefix)) {
523-
url = this.civitPrefix + url.substring(this.civitGreenPrefix.length);
524-
}
525534
if (url.startsWith(this.civitPrefix)) {
526535
let parts = splitWithTail(url.substring(this.civitPrefix.length), '/', 4); // 'models', id, name + sometimes version OR 'api', 'download', 'models', versid
527536
if (parts.length == 2 && parts[0] == 'models' && parts[1].includes('?')) {

0 commit comments

Comments
 (0)