mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-25 07:05:43 -03:00
feat: Refactor model type determination to use state for saving metadata and handling events
This commit is contained in:
@@ -61,12 +61,6 @@ export async function loadModelDescription(modelId, filePath) {
|
|||||||
// Determine API endpoint based on file path or context
|
// Determine API endpoint based on file path or context
|
||||||
let apiEndpoint = `/api/lora-model-description?model_id=${modelId}&file_path=${encodeURIComponent(filePath)}`;
|
let apiEndpoint = `/api/lora-model-description?model_id=${modelId}&file_path=${encodeURIComponent(filePath)}`;
|
||||||
|
|
||||||
// If this is a checkpoint (can be determined from file path or other context)
|
|
||||||
if (filePath.includes('.safetensors') || filePath.includes('.ckpt')) {
|
|
||||||
// For now, use the same endpoint - can be updated later if checkpoint-specific endpoint is needed
|
|
||||||
apiEndpoint = `/api/lora-model-description?model_id=${modelId}&file_path=${encodeURIComponent(filePath)}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try to get model description from API
|
// Try to get model description from API
|
||||||
const response = await fetch(apiEndpoint);
|
const response = await fetch(apiEndpoint);
|
||||||
|
|
||||||
|
|||||||
@@ -114,9 +114,7 @@ export function setupModelNameEditing(filePath) {
|
|||||||
// Get the file path from the dataset
|
// Get the file path from the dataset
|
||||||
const filePath = this.dataset.filePath;
|
const filePath = this.dataset.filePath;
|
||||||
|
|
||||||
// Determine model type based on file extension
|
const saveFunction = state.currentPageType === 'checkpoints' ? saveCheckpointMetadata : saveLoraMetadata;
|
||||||
const isCheckpoint = filePath.includes('.safetensors') || filePath.includes('.ckpt');
|
|
||||||
const saveFunction = isCheckpoint ? saveCheckpointMetadata : saveLoraMetadata;
|
|
||||||
|
|
||||||
await saveFunction(filePath, { model_name: newModelName });
|
await saveFunction(filePath, { model_name: newModelName });
|
||||||
|
|
||||||
@@ -297,9 +295,7 @@ async function saveBaseModel(filePath, originalValue) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Determine model type based on file extension
|
const saveFunction = state.currentPageType === 'checkpoints' ? saveCheckpointMetadata : saveLoraMetadata;
|
||||||
const isCheckpoint = filePath.includes('.safetensors') || filePath.includes('.ckpt');
|
|
||||||
const saveFunction = isCheckpoint ? saveCheckpointMetadata : saveLoraMetadata;
|
|
||||||
|
|
||||||
await saveFunction(filePath, { base_model: newBaseModel });
|
await saveFunction(filePath, { base_model: newBaseModel });
|
||||||
|
|
||||||
@@ -421,19 +417,10 @@ export function setupFileNameEditing(filePath) {
|
|||||||
// Get the file path from the dataset
|
// Get the file path from the dataset
|
||||||
const filePath = this.dataset.filePath;
|
const filePath = this.dataset.filePath;
|
||||||
|
|
||||||
// Determine model type and use appropriate rename function
|
|
||||||
const isCheckpoint = filePath.includes('.safetensors') || filePath.includes('.ckpt');
|
|
||||||
let result;
|
let result;
|
||||||
|
|
||||||
if (isCheckpoint) {
|
if (state.currentPageType === 'checkpoints') {
|
||||||
// Use checkpoint rename function if it exists, otherwise fallback to generic approach
|
result = await renameCheckpointFile(filePath, newFileName);
|
||||||
if (typeof renameCheckpointFile === 'function') {
|
|
||||||
result = await renameCheckpointFile(filePath, newFileName);
|
|
||||||
} else {
|
|
||||||
// Fallback: use checkpoint metadata save function
|
|
||||||
await saveCheckpointMetadata(filePath, { file_name: newFileName });
|
|
||||||
result = { success: true };
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// Use LoRA rename function
|
// Use LoRA rename function
|
||||||
result = await renameLoraFile(filePath, newFileName);
|
result = await renameLoraFile(filePath, newFileName);
|
||||||
|
|||||||
@@ -150,12 +150,9 @@ export function showModelModal(model, modelType) {
|
|||||||
</div>
|
</div>
|
||||||
${typeSpecificContent}
|
${typeSpecificContent}
|
||||||
<div class="info-item notes">
|
<div class="info-item notes">
|
||||||
<label>Additional Notes ${modelType === 'lora' ? '<i class="fas fa-info-circle notes-hint" title="Press Enter to save, Shift+Enter for new line"></i>' : ''}</label>
|
<label>Additional Notes <i class="fas fa-info-circle notes-hint" title="Press Enter to save, Shift+Enter for new line"></i></label>
|
||||||
<div class="editable-field">
|
<div class="editable-field">
|
||||||
<div class="notes-content" contenteditable="true" spellcheck="false">${model.notes || 'Add your notes here...'}</div>
|
<div class="notes-content" contenteditable="true" spellcheck="false">${model.notes || 'Add your notes here...'}</div>
|
||||||
${modelType === 'checkpoint' ? `<button class="save-btn" onclick="saveModelNotes('${model.file_path}', '${modelType}')">
|
|
||||||
<i class="fas fa-save"></i>
|
|
||||||
</button>` : ''}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="info-item full-width">
|
<div class="info-item full-width">
|
||||||
@@ -283,7 +280,7 @@ function setupEventHandlers(filePath) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set up editable fields in the model modal
|
* Set up editable fields (notes and usage tips) in the model modal
|
||||||
* @param {string} filePath - The full file path of the model
|
* @param {string} filePath - The full file path of the model
|
||||||
* @param {string} modelType - Type of model ('lora' or 'checkpoint')
|
* @param {string} modelType - Type of model ('lora' or 'checkpoint')
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
import { showToast } from '../../utils/uiHelpers.js';
|
import { showToast } from '../../utils/uiHelpers.js';
|
||||||
import { saveModelMetadata as saveLoraMetadata } from '../../api/loraApi.js';
|
import { saveModelMetadata as saveLoraMetadata } from '../../api/loraApi.js';
|
||||||
import { saveModelMetadata as saveCheckpointMetadata } from '../../api/checkpointApi.js';
|
import { saveModelMetadata as saveCheckpointMetadata } from '../../api/checkpointApi.js';
|
||||||
|
import { state } from '../../state/index.js';
|
||||||
|
|
||||||
// Preset tag suggestions
|
// Preset tag suggestions
|
||||||
const PRESET_TAGS = [
|
const PRESET_TAGS = [
|
||||||
@@ -164,9 +165,7 @@ async function saveTags() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Determine model type and use appropriate save function
|
const saveFunction = state.currentPageType === 'checkpoints' ? saveCheckpointMetadata : saveLoraMetadata;
|
||||||
const isCheckpoint = filePath.includes('.safetensors') || filePath.includes('.ckpt');
|
|
||||||
const saveFunction = isCheckpoint ? saveCheckpointMetadata : saveLoraMetadata;
|
|
||||||
|
|
||||||
// Save tags metadata
|
// Save tags metadata
|
||||||
await saveFunction(filePath, { tags: tags });
|
await saveFunction(filePath, { tags: tags });
|
||||||
|
|||||||
Reference in New Issue
Block a user