mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-10-04 00:55:32 -03:00
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:
@@ -1,5 +1,5 @@
|
||||
import { showToast, openCivitai, sendLoraToWorkflow, sendEmbeddingToWorkflow, sendModelPathToWorkflow, buildLoraSyntax, copyToClipboard } from '../../utils/uiHelpers.js';
|
||||
import { getModelSourceInfo, getModelSourceGroupKey, getModelSourceViewTitle, openModelSource } from '../../utils/modelSourceHelpers.js';
|
||||
import { getModelSource, getModelSourceInfo, getModelSourceGroupKey, getModelSourceViewTitle, openModelSource } from '../../utils/modelSourceHelpers.js';
|
||||
import { modalManager } from '../../managers/ModalManager.js';
|
||||
import { MODEL_TYPES } from '../../api/apiConfig.js';
|
||||
import {
|
||||
@@ -32,6 +32,18 @@ function getModalFilePath(fallback = '') {
|
||||
return fallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Source descriptor for a model that was hash-enriched from the OpenModelDB
|
||||
* catalogue: it carries no `source_url`, so `getModelSourceInfo` finds
|
||||
* nothing and the page link lives in the civitai payload instead.
|
||||
*/
|
||||
function getOpenModelDBSourceInfo(model) {
|
||||
const url = model?.civitai?.openmodeldb?.url;
|
||||
if (typeof url !== 'string' || !url) return null;
|
||||
const descriptor = getModelSource('openmodeldb');
|
||||
return descriptor ? { ...descriptor, sourceId: '', url } : null;
|
||||
}
|
||||
|
||||
const COMMERCIAL_ICON_CONFIG = [
|
||||
{
|
||||
key: 'image',
|
||||
@@ -398,7 +410,7 @@ export async function showModelModal(model, modelType) {
|
||||
<div class="civitai-view" title="${translate('modals.model.actions.viewOnCivitai', {}, 'View on Civitai')}" data-action="view-civitai" data-filepath="${escapedFilePathAttr}">
|
||||
<i class="fas fa-globe"></i> ${translate('modals.model.actions.viewOnCivitaiText', {}, 'View on Civitai')}
|
||||
</div>`.trim() : '';
|
||||
const sourceInfo = getModelSourceInfo(modelWithFullData);
|
||||
const sourceInfo = getModelSourceInfo(modelWithFullData) || getOpenModelDBSourceInfo(modelWithFullData);
|
||||
const escapedSourceUrl = sourceInfo?.url ? escapeAttribute(sourceInfo.url) : '';
|
||||
const isHuggingFaceSource = sourceInfo?.platform === 'huggingface';
|
||||
const sourceTitle = sourceInfo ? getModelSourceViewTitle(sourceInfo) : '';
|
||||
|
||||
@@ -18,7 +18,7 @@ import {
|
||||
detectModelSourceDownloadUrl,
|
||||
getModelSource,
|
||||
isExternalModelSource,
|
||||
isValidRepoId,
|
||||
isValidSourceId,
|
||||
} from '../utils/modelSourceHelpers.js';
|
||||
|
||||
export class DownloadManager {
|
||||
@@ -534,7 +534,7 @@ export class DownloadManager {
|
||||
const sourceInfo = detectModelSourceDownloadUrl(trimmed);
|
||||
if (sourceInfo) {
|
||||
// Reject path-traversal patterns like "../.." or "user/.."
|
||||
if (!isValidRepoId(sourceInfo.repo)) {
|
||||
if (!isValidSourceId(sourceInfo.platform, sourceInfo.repo)) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
|
||||
@@ -3711,6 +3711,11 @@ export class SettingsManager {
|
||||
enableCivarchiveApiCheckbox.checked = state.global.settings.enable_civarchive_api ?? true;
|
||||
}
|
||||
|
||||
const enableOpenmodeldbApiCheckbox = document.getElementById('enableOpenmodeldbApi');
|
||||
if (enableOpenmodeldbApiCheckbox) {
|
||||
enableOpenmodeldbApiCheckbox.checked = state.global.settings.enable_openmodeldb_api ?? true;
|
||||
}
|
||||
|
||||
const metadataProviderOrderSelect = document.getElementById('metadataProviderOrder');
|
||||
if (metadataProviderOrderSelect) {
|
||||
metadataProviderOrderSelect.value = state.global.settings.metadata_provider_order || 'civitai_archive_sqlite';
|
||||
|
||||
@@ -16,6 +16,7 @@ const DEFAULT_SETTINGS_BASE = Object.freeze({
|
||||
show_only_sfw: false,
|
||||
enable_metadata_archive_db: false,
|
||||
enable_civarchive_api: true,
|
||||
enable_openmodeldb_api: true,
|
||||
metadata_provider_order: 'civitai_archive_sqlite',
|
||||
proxy_enabled: false,
|
||||
proxy_type: 'http',
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* External model source helpers (Hugging Face / ModelScope / TensorArt).
|
||||
* External model source helpers (Hugging Face / ModelScope / TensorArt / OpenModelDB).
|
||||
*
|
||||
* Mirrors `py/services/model_sources/registry.py` so the frontend and the
|
||||
* backend agree on URL recognition, version-group keys, and which sites
|
||||
@@ -92,6 +92,26 @@ export const MODEL_SOURCES = [
|
||||
canonical: (id) => `https://tensor.art/models/${id}`,
|
||||
filePage: null,
|
||||
},
|
||||
{
|
||||
// Flat catalogue of upscalers: the id IS the published-model identity
|
||||
// (no owner/repo split, no revisions, no per-file page).
|
||||
platform: 'openmodeldb',
|
||||
label: 'OpenModelDB',
|
||||
groupPrefix: 'omdb',
|
||||
groupKey: 'repo',
|
||||
supportsEnrichment: true,
|
||||
supportsDownload: true,
|
||||
defaultRevision: '',
|
||||
defaultSubdir: 'openmodeldb',
|
||||
exampleUrl: 'https://openmodeldb.info/models/4x-UltraSharp',
|
||||
placeholder: 'https://openmodeldb.info/models/4x-UltraSharp',
|
||||
pattern: /^https?:\/\/(?:www\.)?openmodeldb\.info\/models\/([A-Za-z0-9_][A-Za-z0-9_.-]*)/i,
|
||||
filePattern: null,
|
||||
// Flat model ids (no owner/name split).
|
||||
flatId: true,
|
||||
canonical: (id) => `https://openmodeldb.info/models/${id}`,
|
||||
filePage: null,
|
||||
},
|
||||
];
|
||||
|
||||
/** Return the source descriptor for a platform id, or null. */
|
||||
@@ -257,6 +277,18 @@ export function isValidRepoId(repo) {
|
||||
.every((part) => part && part !== '.' && part !== '..' && /^[A-Za-z0-9_][\w.-]*$/.test(part));
|
||||
}
|
||||
|
||||
/**
|
||||
* Source-aware id validation, mirroring `ModelSource.is_valid_source_id`:
|
||||
* `owner/name` for repository sites, a flat token for OpenModelDB.
|
||||
*/
|
||||
export function isValidSourceId(platform, repo) {
|
||||
const source = getModelSource(platform);
|
||||
if (source?.flatId) {
|
||||
return typeof repo === 'string' && /^[A-Za-z0-9_][A-Za-z0-9_.-]*$/.test(repo);
|
||||
}
|
||||
return isValidRepoId(repo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Recognise a downloadable model-source URL.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user