Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
fix(models): attach the saved Civitai key to civitai.red downloads (#10383)
Alexander Eichhorn1786167f3df0
diff --git a/docs/src/content/docs/Users Guide/03.Models/01.introduction.mdx b/docs/src/content/docs/Users Guide/03.Models/01.introduction.mdxindex 603f685712..128bea5d77 100644--- a/docs/src/content/docs/Users Guide/03.Models/01.introduction.mdx+++ b/docs/src/content/docs/Users Guide/03.Models/01.introduction.mdx@@ -107,7 +107,7 @@ Add `::` and the subfolder to the repo ID. For the model in the `v2` folder of `::::::note[Gated and login-only downloads]-Some HuggingFace repos are gated and some Civitai models need a login. Add a **HuggingFace** token (stored on the server and checked with HuggingFace) or a **Civitai** key (stored in this browser only, attached to civitai.com downloads) under **API Keys**, and accept the model's license on its download page if asked. An install that is missing a token offers **Add token** in the install queue.+Some HuggingFace repos are gated and some Civitai models need a login. Add a **HuggingFace** token (stored on the server and checked with HuggingFace) or a **Civitai** key (stored in this browser only, attached to civitai.com and civitai.red downloads) under **API Keys**, and accept the model's license on its download page if asked. An install that is missing a token offers **Add token** in the install queue.:::## External modelsdiff --git a/invokeai/frontend/webv2/public/locales/en.json b/invokeai/frontend/webv2/public/locales/en.jsonindex d0eeb5a809..1030f4775f 100644--- a/invokeai/frontend/webv2/public/locales/en.json+++ b/invokeai/frontend/webv2/public/locales/en.json@@ -1477,7 +1477,7 @@"cancelInstall": "Cancel install","changedElsewhere": "This model changed elsewhere; your unsaved edits are kept.","civitaiKey": "Civitai key",- "civitaiKeyDescription": "Attached automatically when installing civitai.com models that require login. Stored in this browser only.",+ "civitaiKeyDescription": "Attached automatically when installing civitai.com or civitai.red models that require login. Stored in this browser only.","civitaiKeyPlaceholder": "32-character key from civitai.com/user/account","cleanupOrphaned": "Clean up orphaned models…","clearSelectedModel": "Clear selected model",diff --git a/invokeai/frontend/webv2/src/features/models/data/apiKeys.test.ts b/invokeai/frontend/webv2/src/features/models/data/apiKeys.test.tsindex 093cdf833b..6fa4b372a1 100644--- a/invokeai/frontend/webv2/src/features/models/data/apiKeys.test.ts+++ b/invokeai/frontend/webv2/src/features/models/data/apiKeys.test.ts@@ -31,11 +31,15 @@ afterEach(() => {});describe('isCivitaiUrl', () => {- it('matches the civitai host and its subdomains only', () => {+ it('matches the civitai hosts and their subdomains only', () => {expect(isCivitaiUrl('https://civitai.com/models/1')).toBe(true);expect(isCivitaiUrl('https://api.civitai.com/download')).toBe(true);+ expect(isCivitaiUrl('https://civitai.red/api/download/models/1')).toBe(true);+ expect(isCivitaiUrl('https://www.civitai.red/models/1')).toBe(true);expect(isCivitaiUrl('https://not-civitai.com/models/1')).toBe(false);+ expect(isCivitaiUrl('https://not-civitai.red/models/1')).toBe(false);expect(isCivitaiUrl('https://civitai.com.evil.example/models/1')).toBe(false);+ expect(isCivitaiUrl('https://civitai.red.evil.example/models/1')).toBe(false);});it('rejects malformed URLs and plain paths', () => {@@ -81,6 +85,7 @@ describe('getAccessTokenForSource', () => {it('returns the saved key only for civitai URLs', () => {setCivitaiApiKey('key-a');expect(getAccessTokenForSource('https://civitai.com/api/download/models/1')).toBe('key-a');+ expect(getAccessTokenForSource('https://civitai.red/api/download/models/1')).toBe('key-a');expect(getAccessTokenForSource('https://huggingface.co/owner/repo')).toBeUndefined();});diff --git a/invokeai/frontend/webv2/src/features/models/data/apiKeys.ts b/invokeai/frontend/webv2/src/features/models/data/apiKeys.tsindex 1f6e63cb54..2d43752d99 100644--- a/invokeai/frontend/webv2/src/features/models/data/apiKeys.ts+++ b/invokeai/frontend/webv2/src/features/models/data/apiKeys.ts@@ -33,11 +33,14 @@ export const clearCivitaiApiKey = (): void => {}};+/** Civitai serves the same API and accounts on its .com (SFW) and .red (mature content) domains. */+const CIVITAI_HOSTS = ['civitai.com', 'civitai.red'];+export const isCivitaiUrl = (source: string): boolean => {try {const host = new URL(source).hostname;- return host === 'civitai.com' || host.endsWith('.civitai.com');+ return CIVITAI_HOSTS.some((civitaiHost) => host === civitaiHost || host.endsWith(`.${civitaiHost}`));} catch {return false;}