mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-05-07 00:46:44 -03:00
fix(civitai): support civitai.red URLs (#897)
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user