feat(metadata): add OpenModelDB metadata provider and model source for upscalers

Add OpenModelDB (openmodeldb.info) as a metadata and download source for
the existing upscaler model type.

Metadata:
- New OpenModelDBClient: fetches the site's bulk JSON dumps, caches them
  on disk (24h TTL + ETag revalidation), and builds a local sha256 index
- New OpenModelDBModelMetadataProvider adapts catalogue entries to the
  CivitAI-shaped version dict contract; registered in the fallback chain
  behind the enable_openmodeldb_api setting (default on), gated to the
  upscaler sub-type so other model types never trigger the dump download
- Persisted provenance uses metadata_source "openmodeldb" plus a nested
  openmodeldb block (page URL, architecture, scale, license)

Images: paired-image LR/SR URLs are ephemeral imgdiff.net sessions, so
displayable images come from the site-hosted auto-generated thumbnails
(model-level cover leads images[], per-image thumbs for the rest); the
original comparison URL is kept in meta.comparisonUrl.

Downloads:
- New OpenModelDBSource (flat model ids, omdb: group prefix) with
  resource filename derivation that recovers names hidden mid-path
  (mediafire) or synthesizes {id}.{type} for folder links
- HTML-gateway mirrors (mediafire/mega/drive) are rejected with a clear
  manual-download hint instead of silently saving an HTML page as .pth
- ModelSource base gains is_valid_source_id / default_subdir_parts /
  resolve_download_url hooks so flat-id sources need no platform branches

UI: "View on OpenModelDB" link in the model modal (downloaded and
hash-enriched models), settings toggle next to the CivArchive one.
This commit is contained in:
Will Miao
2026-10-03 21:13:07 +08:00
parent 515469054c
commit 35f1ced41a
39 changed files with 2787 additions and 37 deletions
@@ -188,4 +188,41 @@ describe('Model modal source links (#1094)', () => {
expect(civitaiLink()).toBeNull();
expect(hfLink()).toBeNull();
});
it('renders an OpenModelDB link from the enriched civitai payload', async () => {
// Hash-enriched upscalers carry no `source_url`; the page link lives in
// `civitai.openmodeldb.url` instead.
await renderModal(
makeModel({
from_civitai: false,
civitai: {
source: 'openmodeldb',
openmodeldb: { id: '4x-UltraSharp', url: 'https://openmodeldb.info/models/4x-UltraSharp' },
},
})
);
const link = document.querySelector('[data-action="view-model-source"]');
expect(link).not.toBeNull();
expect(link.dataset.sourceUrl).toBe('https://openmodeldb.info/models/4x-UltraSharp');
expect(civitaiLink()).toBeNull();
});
it('prefers source_url over the openmodeldb payload fallback', async () => {
await renderModal(
makeModel({
from_civitai: false,
source_url: 'https://openmodeldb.info/models/1x-DeJPG',
source_platform: 'openmodeldb',
civitai: {
source: 'openmodeldb',
openmodeldb: { id: '4x-UltraSharp', url: 'https://openmodeldb.info/models/4x-UltraSharp' },
},
})
);
const links = document.querySelectorAll('[data-action="view-model-source"]');
expect(links.length).toBe(1);
expect(links[0].dataset.sourceUrl).toBe('https://openmodeldb.info/models/1x-DeJPG');
});
});
@@ -18,6 +18,7 @@ const {
canEnrichModelSource,
getModelSourceViewTitle,
parseModelSourceGroupKey,
isValidSourceId,
openModelSource,
} = await import('../../../static/js/utils/modelSourceHelpers.js');
@@ -28,6 +29,7 @@ describe('modelSourceHelpers', () => {
'modelscope',
'modelscope-ai',
'tensorart',
'openmodeldb',
]);
});
@@ -64,6 +66,16 @@ describe('modelSourceHelpers', () => {
expect(info.url).toBe('https://tensor.art/models/827823520299086029');
});
it('recognises OpenModelDB URLs with flat model ids', () => {
const info = parseModelSourceUrl('https://openmodeldb.info/models/4x-UltraSharp');
expect(info.platform).toBe('openmodeldb');
expect(info.groupPrefix).toBe('omdb');
expect(info.sourceId).toBe('4x-UltraSharp');
expect(info.url).toBe('https://openmodeldb.info/models/4x-UltraSharp');
expect(info.supportsDownload).toBe(true);
expect(info.supportsEnrichment).toBe(true);
});
it('rejects unsupported URLs', () => {
expect(parseModelSourceUrl('https://example.com/x')).toBeNull();
expect(parseModelSourceUrl('')).toBeNull();
@@ -109,6 +121,10 @@ describe('modelSourceHelpers', () => {
expect(getModelSourceGroupKey({ source_url: 'https://tensor.art/models/123' })).toBe(
'ta:123'
);
// OpenModelDB's flat model id is the published-model identity.
expect(
getModelSourceGroupKey({ source_url: 'https://openmodeldb.info/models/4x-UltraSharp' })
).toBe('omdb:4x-UltraSharp');
// ModelScope groups by the site-native published-model id.
expect(
getModelSourceGroupKey({
@@ -181,6 +197,11 @@ describe('modelSourceHelpers', () => {
});
expect(parseModelSourceGroupKey('ms:user/repo').platform).toBe('modelscope');
expect(parseModelSourceGroupKey('ta:123').platform).toBe('tensorart');
expect(parseModelSourceGroupKey('omdb:4x-UltraSharp')).toEqual({
platform: 'openmodeldb',
label: 'OpenModelDB',
sourceId: '4x-UltraSharp',
});
});
it('rejects numeric CivitAI model ids and unknown prefixes', () => {
@@ -192,6 +213,21 @@ describe('modelSourceHelpers', () => {
});
});
describe('isValidSourceId', () => {
it('requires owner/name for repository sites', () => {
expect(isValidSourceId('huggingface', 'user/repo')).toBe(true);
expect(isValidSourceId('huggingface', '4x-UltraSharp')).toBe(false);
expect(isValidSourceId('modelscope', 'u/..')).toBe(false);
});
it('accepts flat model ids for OpenModelDB', () => {
expect(isValidSourceId('openmodeldb', '4x-UltraSharp')).toBe(true);
expect(isValidSourceId('openmodeldb', 'owner/name')).toBe(false);
expect(isValidSourceId('openmodeldb', '../escape')).toBe(false);
expect(isValidSourceId('openmodeldb', '')).toBe(false);
});
});
describe('openModelSource', () => {
it('opens the URL in a new tab', () => {
const openSpy = vi.spyOn(window, 'open').mockImplementation(() => {});
@@ -222,6 +222,17 @@ describe('DownloadManager.detectUrlType — external model source URLs', () => {
expect(intl.platform).toBe('modelscope-ai');
});
it('detects an OpenModelDB model URL with its flat id', () => {
const result = DownloadManager.detectUrlType(
'https://openmodeldb.info/models/4x-UltraSharp'
);
expect(result).toEqual({
type: 'model-source-repo',
platform: 'openmodeldb',
repo: '4x-UltraSharp',
});
});
it('rejects path traversal in either platform', () => {
expect(
DownloadManager.detectUrlType('https://modelscope.cn/models/../etc/passwd')