mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-05-06 16:36:45 -03:00
fix(civitai): support civitai.red URLs (#897)
This commit is contained in:
21
tests/frontend/components/modelContextMenuMixin.test.js
Normal file
21
tests/frontend/components/modelContextMenuMixin.test.js
Normal file
@@ -0,0 +1,21 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { ModelContextMenuMixin } from '../../../static/js/components/ContextMenu/ModelContextMenuMixin.js';
|
||||
|
||||
describe('ModelContextMenuMixin.extractModelVersionId', () => {
|
||||
it('accepts civitai.red model URLs', () => {
|
||||
expect(
|
||||
ModelContextMenuMixin.extractModelVersionId(
|
||||
'https://civitai.red/models/65423/nijimecha-artstyle?modelVersionId=777'
|
||||
)
|
||||
).toEqual({ modelId: '65423', modelVersionId: '777' });
|
||||
});
|
||||
|
||||
it('rejects model-like URLs from unsupported hosts', () => {
|
||||
expect(
|
||||
ModelContextMenuMixin.extractModelVersionId(
|
||||
'https://example.com/models/65423?modelVersionId=777'
|
||||
)
|
||||
).toEqual({ modelId: null, modelVersionId: null });
|
||||
});
|
||||
});
|
||||
@@ -136,4 +136,14 @@ describe('DownloadManager version history badges', () => {
|
||||
expect(items[1].querySelector('.local-path')?.textContent).toContain('/models/still-local.safetensors');
|
||||
expect(items[1].querySelector('.downloaded-badge')).toBeNull();
|
||||
});
|
||||
|
||||
it('extracts model and version ids from civitai.red URLs', () => {
|
||||
const manager = new DownloadManager();
|
||||
|
||||
expect(
|
||||
manager.extractModelId('https://civitai.red/models/65423/nijimecha-artstyle?modelVersionId=777')
|
||||
).toBe('65423');
|
||||
expect(manager.modelVersionId).toBe('777');
|
||||
expect(manager.source).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,7 +4,10 @@ import {
|
||||
getOptimizedUrl,
|
||||
getShowcaseUrl,
|
||||
getThumbnailUrl,
|
||||
extractCivitaiImageId,
|
||||
extractCivitaiModelUrlParts,
|
||||
isCivitaiUrl,
|
||||
isSupportedCivitaiPageHost,
|
||||
OptimizationMode
|
||||
} from '../../../static/js/utils/civitaiUtils.js';
|
||||
|
||||
@@ -217,4 +220,43 @@ describe('civitaiUtils', () => {
|
||||
expect(isCivitaiUrl('not-a-url')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isSupportedCivitaiPageHost', () => {
|
||||
it('accepts civitai.com and civitai.red page hosts', () => {
|
||||
expect(isSupportedCivitaiPageHost('civitai.com')).toBe(true);
|
||||
expect(isSupportedCivitaiPageHost('civitai.red')).toBe(true);
|
||||
});
|
||||
|
||||
it('rejects unrelated hosts', () => {
|
||||
expect(isSupportedCivitaiPageHost('www.civitai.com')).toBe(false);
|
||||
expect(isSupportedCivitaiPageHost('www.civitai.red')).toBe(false);
|
||||
expect(isSupportedCivitaiPageHost('example.com')).toBe(false);
|
||||
expect(isSupportedCivitaiPageHost('')).toBe(false);
|
||||
expect(isSupportedCivitaiPageHost(null)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('extractCivitaiModelUrlParts', () => {
|
||||
it('extracts model and version ids from civitai.red model URLs', () => {
|
||||
expect(
|
||||
extractCivitaiModelUrlParts('https://civitai.red/models/65423/name?modelVersionId=98765')
|
||||
).toEqual({ modelId: '65423', modelVersionId: '98765' });
|
||||
});
|
||||
|
||||
it('rejects model-like URLs from unsupported hosts', () => {
|
||||
expect(
|
||||
extractCivitaiModelUrlParts('https://example.com/models/65423?modelVersionId=98765')
|
||||
).toEqual({ modelId: null, modelVersionId: null });
|
||||
});
|
||||
});
|
||||
|
||||
describe('extractCivitaiImageId', () => {
|
||||
it('extracts image ids from civitai.red image URLs', () => {
|
||||
expect(extractCivitaiImageId('https://civitai.red/images/126920345')).toBe('126920345');
|
||||
});
|
||||
|
||||
it('rejects image-like URLs from unsupported hosts', () => {
|
||||
expect(extractCivitaiImageId('https://example.com/images/126920345')).toBe(null);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -635,6 +635,39 @@ async def test_import_remote_video_recipe(monkeypatch, tmp_path: Path) -> None:
|
||||
assert call["extension"] == ".mp4"
|
||||
|
||||
|
||||
async def test_import_remote_recipe_supports_civitai_red(monkeypatch, tmp_path: Path) -> None:
|
||||
async def fake_get_default_metadata_provider():
|
||||
return SimpleNamespace(get_model_version_info=lambda id: ({}, None))
|
||||
|
||||
monkeypatch.setattr(
|
||||
"py.recipes.enrichment.get_default_metadata_provider",
|
||||
fake_get_default_metadata_provider,
|
||||
)
|
||||
|
||||
async with recipe_harness(monkeypatch, tmp_path) as harness:
|
||||
harness.civitai.image_info["126920345"] = {
|
||||
"id": 126920345,
|
||||
"url": "https://image.civitai.com/x/y/original=true/sample.jpeg",
|
||||
"type": "image",
|
||||
}
|
||||
|
||||
response = await harness.client.get(
|
||||
"/api/lm/recipes/import-remote",
|
||||
params={
|
||||
"image_url": "https://civitai.red/images/126920345",
|
||||
"name": "Red Recipe",
|
||||
"resources": json.dumps([]),
|
||||
"base_model": "Flux",
|
||||
},
|
||||
)
|
||||
|
||||
payload = await response.json()
|
||||
assert response.status == 200
|
||||
assert payload["success"] is True
|
||||
assert harness.downloader.urls
|
||||
assert "width=450,optimized=true" in harness.downloader.urls[0]
|
||||
|
||||
|
||||
async def test_analyze_uploaded_image_error_path(monkeypatch, tmp_path: Path) -> None:
|
||||
async with recipe_harness(monkeypatch, tmp_path) as harness:
|
||||
harness.analysis.raise_for_uploaded = RecipeValidationError(
|
||||
|
||||
@@ -581,6 +581,7 @@ class TestInputValidation:
|
||||
assert service._validate_url("https://example.com/image.png") is True
|
||||
assert service._validate_url("http://example.com/image.png") is True
|
||||
assert service._validate_url("https://civitai.com/images/123") is True
|
||||
assert service._validate_url("https://civitai.red/images/123") is True
|
||||
|
||||
def test_validate_invalid_url(self, service):
|
||||
assert service._validate_url("not-a-url") is False
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
from py.utils.civitai_utils import build_license_flags, resolve_license_info, resolve_license_payload
|
||||
from py.utils.civitai_utils import (
|
||||
build_license_flags,
|
||||
extract_civitai_image_id,
|
||||
extract_civitai_model_url_parts,
|
||||
is_supported_civitai_page_host,
|
||||
resolve_license_info,
|
||||
resolve_license_payload,
|
||||
)
|
||||
|
||||
|
||||
def test_resolve_license_payload_defaults():
|
||||
@@ -78,3 +85,40 @@ def test_build_license_flags_parses_aggregate_inside_list():
|
||||
flags = build_license_flags(source)
|
||||
expected_flags = (1 << 0) | (7 << 1) | (1 << 5)
|
||||
assert flags == expected_flags
|
||||
|
||||
|
||||
def test_supported_civitai_page_hosts_include_red():
|
||||
assert is_supported_civitai_page_host("civitai.com") is True
|
||||
assert is_supported_civitai_page_host("civitai.red") is True
|
||||
assert is_supported_civitai_page_host("www.civitai.com") is False
|
||||
assert is_supported_civitai_page_host("www.civitai.red") is False
|
||||
assert is_supported_civitai_page_host("example.com") is False
|
||||
|
||||
|
||||
def test_extract_civitai_model_url_parts_supports_red():
|
||||
model_id, version_id = extract_civitai_model_url_parts(
|
||||
"https://civitai.red/models/65423/nijimecha-artstyle?modelVersionId=777"
|
||||
)
|
||||
|
||||
assert model_id == "65423"
|
||||
assert version_id == "777"
|
||||
|
||||
|
||||
def test_extract_civitai_model_url_parts_rejects_non_civitai_host():
|
||||
model_id, version_id = extract_civitai_model_url_parts(
|
||||
"https://example.com/models/65423?modelVersionId=777"
|
||||
)
|
||||
|
||||
assert model_id is None
|
||||
assert version_id is None
|
||||
|
||||
|
||||
def test_extract_civitai_image_id_supports_red():
|
||||
assert (
|
||||
extract_civitai_image_id("https://civitai.red/images/126920345")
|
||||
== "126920345"
|
||||
)
|
||||
|
||||
|
||||
def test_extract_civitai_image_id_rejects_non_civitai_host():
|
||||
assert extract_civitai_image_id("https://example.com/images/126920345") is None
|
||||
|
||||
Reference in New Issue
Block a user