mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-10-07 18:12:12 -03:00
The sidebar's folder tree merges every model root into one relative-path
namespace, but folder operations turned a node into a path by prefixing
default_*_root. A folder living under another root failed to delete with
"Folder no longer exists" (recipes under the primary lora root while
default_lora_root is the extra one), and where the same relative folder
exists in both roots the operation silently hit the other copy — 14 of the
16 top-level folders in the reporting library are shared, so guessing a root
was never safe.
Backend:
* ModelMoveService.resolve_folder() and GET /api/lm/{prefix}/resolve-folder
answer which directories a library-relative folder maps to
(folder_path/root/is_symlink), in scanner root order, skipping directories
no root holds and refusing absolute or climbing paths.
* delete_folder/rename_folder tag a vanished directory with code "missing"
so the sidebar can tell "this node is stale, refresh" from a failed
operation.
Frontend:
* _resolveFolderCandidates() is the single place that turns a node into
absolute paths: default root first, the old root-prefix fallback only
while a single root is configured, and an explicit unresolved error for a
multi-root library — nothing is guessed silently any more.
* One copy keeps the single-target modal, which now names the resolved
absolute path. Several copies render one checkbox row per copy, each
dry-run against the delete guard ("no models" / "contains N model
file(s)..." / a deletion is still pending / no longer exists / symbolic
link): a blocked copy is unticked, disabled and explained, the button
reads "Delete N folders", every ticked copy is deleted and guarded on its
own, and a partial failure is reported without discarding the successes.
* Rows are built once per open and only their status text is updated, so
ticking a box no longer rebuilds the list, steals focus or resizes the
modal mid-click; the action row keeps a fixed button width.
* Rename offers a root picker in its inline row, create inherits the
parent's root when the parent resolves to exactly one directory, and the
undo restores every copy a delete removed.
i18n: 26 new keys (sidebar.deleteFolderModal.*, .deleteFolderResult.*,
.renameFolderResult.*, .folderRoot.*, .folderResult.*) translated in all 9
locales, with the en wording normalized to the established "model root" noun
(it had said "library root") and the new terminology recorded in
docs/i18n-translation-guidelines.md.
Verified: pytest 3686 passed, vitest 1473 passed (86 in the folder-management
suite), pytest tests/i18n 20 passed, sync_translation_keys.py --dry-run
clean. A sandboxed standalone instance with two roots confirmed that deleting
one copy leaves the node in place, that the twin's model card survives the
purge, and that deleting both copies and undoing restores both directories.
241 lines
8.7 KiB
JavaScript
241 lines
8.7 KiB
JavaScript
import { state } from '../state/index.js';
|
|
|
|
/**
|
|
* API Configuration
|
|
* Centralized configuration for all model types and their endpoints
|
|
*/
|
|
|
|
// Model type definitions
|
|
export const MODEL_TYPES = {
|
|
LORA: 'loras',
|
|
CHECKPOINT: 'checkpoints',
|
|
EMBEDDING: 'embeddings',
|
|
OTHER: 'other'
|
|
};
|
|
|
|
// Base API configuration for each model type
|
|
export const MODEL_CONFIG = {
|
|
[MODEL_TYPES.LORA]: {
|
|
displayName: 'LoRA',
|
|
singularName: 'lora',
|
|
defaultPageSize: 100,
|
|
supportsLetterFilter: true,
|
|
supportsBulkOperations: true,
|
|
supportsMove: true,
|
|
supportsFolderManagement: true,
|
|
templateName: 'loras.html'
|
|
},
|
|
[MODEL_TYPES.CHECKPOINT]: {
|
|
displayName: 'Checkpoint',
|
|
singularName: 'checkpoint',
|
|
defaultPageSize: 100,
|
|
supportsLetterFilter: false,
|
|
supportsBulkOperations: true,
|
|
supportsMove: true,
|
|
supportsFolderManagement: true,
|
|
templateName: 'checkpoints.html'
|
|
},
|
|
[MODEL_TYPES.EMBEDDING]: {
|
|
displayName: 'Embedding',
|
|
singularName: 'embedding',
|
|
defaultPageSize: 100,
|
|
supportsLetterFilter: true,
|
|
supportsBulkOperations: true,
|
|
supportsMove: true,
|
|
supportsFolderManagement: true,
|
|
templateName: 'embeddings.html'
|
|
},
|
|
[MODEL_TYPES.OTHER]: {
|
|
displayName: 'Other Model',
|
|
singularName: 'other',
|
|
defaultPageSize: 100,
|
|
supportsLetterFilter: false,
|
|
supportsBulkOperations: true,
|
|
supportsMove: true,
|
|
supportsFolderManagement: true,
|
|
templateName: 'other.html'
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Generate API endpoints for a given model type
|
|
* @param {string} modelType - The model type (e.g., 'loras', 'checkpoints')
|
|
* @returns {Object} Object containing all API endpoints for the model type
|
|
*/
|
|
export function getApiEndpoints(modelType) {
|
|
return {
|
|
// Base CRUD operations
|
|
list: `/api/lm/${modelType}/list`,
|
|
excluded: `/api/lm/${modelType}/excluded`,
|
|
delete: `/api/lm/${modelType}/delete`,
|
|
exclude: `/api/lm/${modelType}/exclude`,
|
|
unexclude: `/api/lm/${modelType}/unexclude`,
|
|
rename: `/api/lm/${modelType}/rename`,
|
|
save: `/api/lm/${modelType}/save-metadata`,
|
|
cancelTask: `/api/lm/${modelType}/cancel-task`,
|
|
|
|
// Bulk operations
|
|
bulkDelete: `/api/lm/${modelType}/bulk-delete`,
|
|
|
|
// Tag operations
|
|
addTags: `/api/lm/${modelType}/add-tags`,
|
|
|
|
// Move operations (now common for all model types that support move)
|
|
moveModel: `/api/lm/${modelType}/move_model`,
|
|
moveBulk: `/api/lm/${modelType}/move_models_bulk`,
|
|
createFolder: `/api/lm/${modelType}/create-folder`,
|
|
deleteFolder: `/api/lm/${modelType}/delete-folder`,
|
|
renameFolder: `/api/lm/${modelType}/rename-folder`,
|
|
// Resolves a tree-relative folder onto the root(s) that hold it: the
|
|
// unified folder tree merges every root, so a node does not carry its
|
|
// own absolute path.
|
|
resolveFolder: `/api/lm/${modelType}/resolve-folder`,
|
|
|
|
// CivitAI integration
|
|
fetchCivitai: `/api/lm/${modelType}/fetch-civitai`,
|
|
fetchAllCivitai: `/api/lm/${modelType}/fetch-all-civitai`,
|
|
relinkCivitai: `/api/lm/${modelType}/relink-civitai`,
|
|
civitaiVersions: `/api/lm/${modelType}/civitai/versions`,
|
|
refreshUpdates: `/api/lm/${modelType}/updates/refresh`,
|
|
fetchMissingLicenses: `/api/lm/${modelType}/updates/fetch-missing-license`,
|
|
modelUpdateStatus: `/api/lm/${modelType}/updates/status`,
|
|
modelUpdateVersions: `/api/lm/${modelType}/updates/versions`,
|
|
ignoreModelUpdate: `/api/lm/${modelType}/updates/ignore`,
|
|
ignoreVersionUpdate: `/api/lm/${modelType}/updates/ignore-version`,
|
|
|
|
// Price alerts are app-wide (all model types in one query), so they are
|
|
// not part of this per-type endpoint map; see UpdateService.js.
|
|
|
|
// Preview management
|
|
replacePreview: `/api/lm/${modelType}/replace-preview`,
|
|
setPreviewFromUrl: `/api/lm/${modelType}/set-preview-from-url`,
|
|
|
|
// Query operations
|
|
scan: `/api/lm/${modelType}/scan`,
|
|
topTags: `/api/lm/${modelType}/top-tags`,
|
|
searchTags: `/api/lm/${modelType}/search-tags`,
|
|
baseModels: `/api/lm/${modelType}/base-models`,
|
|
roots: `/api/lm/${modelType}/roots`,
|
|
folders: `/api/lm/${modelType}/folders`,
|
|
folderTree: `/api/lm/${modelType}/folder-tree`,
|
|
unifiedFolderTree: `/api/lm/${modelType}/unified-folder-tree`,
|
|
duplicates: `/api/lm/${modelType}/find-duplicates`,
|
|
conflicts: `/api/lm/${modelType}/find-filename-conflicts`,
|
|
verify: `/api/lm/${modelType}/verify-duplicates`,
|
|
metadata: `/api/lm/${modelType}/metadata`,
|
|
modelDescription: `/api/lm/${modelType}/model-description`,
|
|
|
|
// Auto-organize operations
|
|
autoOrganize: `/api/lm/${modelType}/auto-organize`,
|
|
autoOrganizeProgress: `/api/lm/${modelType}/auto-organize-progress`,
|
|
|
|
// Filename template operations
|
|
applyFilenameTemplate: `/api/lm/${modelType}/apply-filename-template`,
|
|
|
|
// Model-specific endpoints (will be merged with specific configs)
|
|
specific: {}
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Model-specific endpoint configurations
|
|
*/
|
|
export const MODEL_SPECIFIC_ENDPOINTS = {
|
|
[MODEL_TYPES.LORA]: {
|
|
letterCounts: `/api/lm/${MODEL_TYPES.LORA}/letter-counts`,
|
|
notes: `/api/lm/${MODEL_TYPES.LORA}/get-notes`,
|
|
triggerWords: `/api/lm/${MODEL_TYPES.LORA}/get-trigger-words`,
|
|
previewUrl: `/api/lm/${MODEL_TYPES.LORA}/preview-url`,
|
|
civitaiUrl: `/api/lm/${MODEL_TYPES.LORA}/civitai-url`,
|
|
metadata: `/api/lm/${MODEL_TYPES.LORA}/metadata`,
|
|
getTriggerWordsPost: `/api/lm/${MODEL_TYPES.LORA}/get_trigger_words`,
|
|
civitaiModelByVersion: `/api/lm/${MODEL_TYPES.LORA}/civitai/model/version`,
|
|
civitaiModelByHash: `/api/lm/${MODEL_TYPES.LORA}/civitai/model/hash`,
|
|
},
|
|
[MODEL_TYPES.CHECKPOINT]: {
|
|
info: `/api/lm/${MODEL_TYPES.CHECKPOINT}/info`,
|
|
checkpoints_roots: `/api/lm/${MODEL_TYPES.CHECKPOINT}/checkpoints_roots`,
|
|
unet_roots: `/api/lm/${MODEL_TYPES.CHECKPOINT}/unet_roots`,
|
|
metadata: `/api/lm/${MODEL_TYPES.CHECKPOINT}/metadata`,
|
|
},
|
|
[MODEL_TYPES.EMBEDDING]: {
|
|
metadata: `/api/lm/${MODEL_TYPES.EMBEDDING}/metadata`,
|
|
},
|
|
[MODEL_TYPES.OTHER]: {
|
|
metadata: `/api/lm/${MODEL_TYPES.OTHER}/metadata`,
|
|
roots_by_subtype: `/api/lm/${MODEL_TYPES.OTHER}/roots_by_subtype`,
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Get complete API configuration for a model type
|
|
* @param {string} modelType - The model type
|
|
* @returns {Object} Complete API configuration
|
|
*/
|
|
export function getCompleteApiConfig(modelType) {
|
|
const baseEndpoints = getApiEndpoints(modelType);
|
|
const specificEndpoints = MODEL_SPECIFIC_ENDPOINTS[modelType] || {};
|
|
const config = MODEL_CONFIG[modelType];
|
|
|
|
return {
|
|
modelType,
|
|
config,
|
|
endpoints: {
|
|
...baseEndpoints,
|
|
specific: specificEndpoints
|
|
}
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Validate if a model type is supported
|
|
* @param {string} modelType - The model type to validate
|
|
* @returns {boolean} True if valid, false otherwise
|
|
*/
|
|
export function isValidModelType(modelType) {
|
|
return Object.values(MODEL_TYPES).includes(modelType);
|
|
}
|
|
|
|
/**
|
|
* Get model type from current page or explicit parameter
|
|
* @param {string} [explicitType] - Explicitly provided model type
|
|
* @returns {string} The model type
|
|
*/
|
|
export function getCurrentModelType(explicitType = null) {
|
|
if (explicitType && isValidModelType(explicitType)) {
|
|
return explicitType;
|
|
}
|
|
|
|
return state.currentPageType || MODEL_TYPES.LORA;
|
|
}
|
|
|
|
// Download API endpoints (shared across all model types)
|
|
export const DOWNLOAD_ENDPOINTS = {
|
|
download: '/api/lm/download-model',
|
|
downloadGet: '/api/lm/download-model-get',
|
|
cancelGet: '/api/lm/cancel-download-get',
|
|
progress: '/api/lm/download-progress',
|
|
routing: '/api/lm/download/routing',
|
|
exampleImages: '/api/lm/force-download-example-images', // Re-process example images ignoring previous status
|
|
exampleImagesMissing: '/api/lm/download-example-images' // Download only missing example images
|
|
};
|
|
|
|
// External model source endpoints (Hugging Face / ModelScope).
|
|
// The hf-* paths are the historical names, kept as server-side aliases.
|
|
export const MODEL_SOURCE_ENDPOINTS = {
|
|
repoFiles: '/api/lm/model-source-files',
|
|
download: '/api/lm/download-model-source',
|
|
sources: '/api/lm/model-sources',
|
|
};
|
|
|
|
/** @deprecated use MODEL_SOURCE_ENDPOINTS */
|
|
export const HF_ENDPOINTS = {
|
|
repoFiles: MODEL_SOURCE_ENDPOINTS.repoFiles,
|
|
download: MODEL_SOURCE_ENDPOINTS.download,
|
|
};
|
|
|
|
// WebSocket endpoints
|
|
export const WS_ENDPOINTS = {
|
|
fetchProgress: '/ws/fetch-progress'
|
|
};
|