mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-21 21:22:11 -03:00
Merge branch 'willmiao:main' into main
This commit is contained in:
@@ -351,8 +351,8 @@
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
margin-left: 20px;
|
||||
margin-top: 4px;
|
||||
align-items: center;
|
||||
height: 21px;
|
||||
}
|
||||
|
||||
.create-folder-form input {
|
||||
@@ -395,9 +395,16 @@
|
||||
border: 1px dashed var(--border-color);
|
||||
}
|
||||
|
||||
.path-preview label {
|
||||
display: block;
|
||||
margin-bottom: 8px;
|
||||
.path-preview-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 12px;
|
||||
gap: var(--space-2);
|
||||
}
|
||||
|
||||
.path-preview-header label {
|
||||
margin: 0;
|
||||
color: var(--text-color);
|
||||
font-size: 0.9em;
|
||||
opacity: 0.8;
|
||||
@@ -416,6 +423,70 @@
|
||||
border-radius: var(--border-radius-xs);
|
||||
}
|
||||
|
||||
/* Inline Toggle Styles */
|
||||
.inline-toggle-container {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.inline-toggle-label {
|
||||
font-size: 0.85em;
|
||||
color: var(--text-color);
|
||||
opacity: 0.9;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.inline-toggle-container .toggle-switch {
|
||||
position: relative;
|
||||
width: 36px;
|
||||
height: 18px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.inline-toggle-container .toggle-switch input {
|
||||
opacity: 0;
|
||||
width: 0;
|
||||
height: 0;
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
.inline-toggle-container .toggle-slider {
|
||||
position: absolute;
|
||||
cursor: pointer;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background-color: var(--border-color);
|
||||
transition: all 0.3s ease;
|
||||
border-radius: 18px;
|
||||
}
|
||||
|
||||
.inline-toggle-container .toggle-slider:before {
|
||||
position: absolute;
|
||||
content: "";
|
||||
height: 12px;
|
||||
width: 12px;
|
||||
left: 3px;
|
||||
bottom: 3px;
|
||||
background-color: white;
|
||||
transition: all 0.3s ease;
|
||||
border-radius: 50%;
|
||||
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
.inline-toggle-container .toggle-switch input:checked + .toggle-slider {
|
||||
background-color: var(--lora-accent);
|
||||
}
|
||||
|
||||
.inline-toggle-container .toggle-switch input:checked + .toggle-slider:before {
|
||||
transform: translateX(18px);
|
||||
}
|
||||
|
||||
/* Dark theme adjustments */
|
||||
[data-theme="dark"] .version-item {
|
||||
background: var(--lora-surface);
|
||||
@@ -426,8 +497,18 @@
|
||||
border-color: var(--lora-border);
|
||||
}
|
||||
|
||||
[data-theme="dark"] .toggle-slider:before {
|
||||
background-color: #f0f0f0;
|
||||
}
|
||||
|
||||
/* Enhance the local badge to make it more noticeable */
|
||||
.version-item.exists-locally {
|
||||
background: oklch(var(--lora-accent) / 0.05);
|
||||
border-left: 4px solid var(--lora-accent);
|
||||
}
|
||||
|
||||
.manual-path-selection.disabled {
|
||||
opacity: 0.5;
|
||||
pointer-events: none;
|
||||
user-select: none;
|
||||
}
|
||||
@@ -482,4 +482,99 @@ input:checked + .toggle-slider:before {
|
||||
[data-theme="dark"] .base-model-select option {
|
||||
background-color: #2d2d2d;
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
/* Template Configuration Styles */
|
||||
.placeholder-info {
|
||||
margin-top: var(--space-1);
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: var(--space-1);
|
||||
}
|
||||
|
||||
.placeholder-tag {
|
||||
display: inline-block;
|
||||
background: var(--lora-accent);
|
||||
color: white;
|
||||
padding: 2px 6px;
|
||||
border-radius: 3px;
|
||||
font-family: monospace;
|
||||
font-size: 1em;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.template-custom-row {
|
||||
margin-top: 8px;
|
||||
animation: slideDown 0.2s ease-out;
|
||||
}
|
||||
|
||||
@keyframes slideDown {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(-10px);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
.template-custom-input {
|
||||
width: 96%;
|
||||
padding: 6px 10px;
|
||||
border-radius: var(--border-radius-xs);
|
||||
border: 1px solid var(--border-color);
|
||||
background-color: var(--lora-surface);
|
||||
color: var(--text-color);
|
||||
font-size: 0.95em;
|
||||
font-family: monospace;
|
||||
height: 24px;
|
||||
transition: border-color 0.2s;
|
||||
}
|
||||
|
||||
.template-custom-input:focus {
|
||||
border-color: var(--lora-accent);
|
||||
outline: none;
|
||||
box-shadow: 0 0 0 2px rgba(var(--lora-accent-rgb, 79, 70, 229), 0.1);
|
||||
}
|
||||
|
||||
.template-custom-input::placeholder {
|
||||
color: var(--text-color);
|
||||
opacity: 0.5;
|
||||
font-family: inherit;
|
||||
}
|
||||
|
||||
.template-validation {
|
||||
margin-top: 6px;
|
||||
font-size: 0.85em;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
min-height: 20px;
|
||||
}
|
||||
|
||||
.template-validation.valid {
|
||||
color: var(--lora-success, #22c55e);
|
||||
}
|
||||
|
||||
.template-validation.invalid {
|
||||
color: var(--lora-error, #ef4444);
|
||||
}
|
||||
|
||||
.template-validation i {
|
||||
width: 12px;
|
||||
}
|
||||
|
||||
/* Dark theme specific adjustments */
|
||||
[data-theme="dark"] .template-custom-input {
|
||||
background-color: rgba(30, 30, 30, 0.9);
|
||||
}
|
||||
|
||||
/* Responsive adjustments */
|
||||
@media (max-width: 768px) {
|
||||
.placeholder-info {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
}
|
||||
}
|
||||
@@ -613,7 +613,7 @@ export class BaseModelApiClient {
|
||||
}
|
||||
}
|
||||
|
||||
async downloadModel(modelId, versionId, modelRoot, relativePath, downloadId) {
|
||||
async downloadModel(modelId, versionId, modelRoot, relativePath, useDefaultPaths = false, downloadId) {
|
||||
try {
|
||||
const response = await fetch(DOWNLOAD_ENDPOINTS.download, {
|
||||
method: 'POST',
|
||||
@@ -623,6 +623,7 @@ export class BaseModelApiClient {
|
||||
model_version_id: versionId,
|
||||
model_root: modelRoot,
|
||||
relative_path: relativePath,
|
||||
use_default_paths: useDefaultPaths,
|
||||
download_id: downloadId
|
||||
})
|
||||
});
|
||||
|
||||
@@ -175,7 +175,18 @@ export class FolderTreeManager {
|
||||
renderTree() {
|
||||
const folderTree = document.getElementById(this.getElementId('folderTree'));
|
||||
if (!folderTree) return;
|
||||
|
||||
|
||||
// Show placeholder if treeData is empty
|
||||
if (!this.treeData || Object.keys(this.treeData).length === 0) {
|
||||
folderTree.innerHTML = `
|
||||
<div class="folder-tree-placeholder" style="padding:24px;text-align:center;color:var(--text-color);opacity:0.7;">
|
||||
<i class="fas fa-folder-open" style="font-size:2em;opacity:0.5;"></i>
|
||||
<div>No folders found.<br/>You can create a new folder using the button above.</div>
|
||||
</div>
|
||||
`;
|
||||
return;
|
||||
}
|
||||
|
||||
folderTree.innerHTML = this.renderTreeNode(this.treeData, '');
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { modalManager } from './ModalManager.js';
|
||||
import { showToast } from '../utils/uiHelpers.js';
|
||||
import { state } from '../state/index.js';
|
||||
import { LoadingManager } from './LoadingManager.js';
|
||||
import { getModelApiClient, resetAndReload } from '../api/modelApiFactory.js';
|
||||
import { getStorageItem, setStorageItem } from '../utils/storageHelpers.js';
|
||||
@@ -16,7 +17,8 @@ export class DownloadManager {
|
||||
this.initialized = false;
|
||||
this.selectedFolder = '';
|
||||
this.apiClient = null;
|
||||
|
||||
this.useDefaultPath = false;
|
||||
|
||||
this.loadingManager = new LoadingManager();
|
||||
this.folderTreeManager = new FolderTreeManager();
|
||||
this.folderClickHandler = null;
|
||||
@@ -29,6 +31,7 @@ export class DownloadManager {
|
||||
this.handleBackToUrl = this.backToUrl.bind(this);
|
||||
this.handleBackToVersions = this.backToVersions.bind(this);
|
||||
this.handleCloseModal = this.closeModal.bind(this);
|
||||
this.handleToggleDefaultPath = this.toggleDefaultPath.bind(this);
|
||||
}
|
||||
|
||||
showDownloadModal() {
|
||||
@@ -73,6 +76,9 @@ export class DownloadManager {
|
||||
document.getElementById('backToUrlBtn').addEventListener('click', this.handleBackToUrl);
|
||||
document.getElementById('backToVersionsBtn').addEventListener('click', this.handleBackToVersions);
|
||||
document.getElementById('closeDownloadModal').addEventListener('click', this.handleCloseModal);
|
||||
|
||||
// Default path toggle handler
|
||||
document.getElementById('useDefaultPath').addEventListener('change', this.handleToggleDefaultPath);
|
||||
}
|
||||
|
||||
updateModalLabels() {
|
||||
@@ -126,6 +132,9 @@ export class DownloadManager {
|
||||
if (this.folderTreeManager) {
|
||||
this.folderTreeManager.clearSelection();
|
||||
}
|
||||
|
||||
// Reset default path toggle
|
||||
this.loadDefaultPathSetting();
|
||||
}
|
||||
|
||||
async validateAndFetchVersions() {
|
||||
@@ -329,12 +338,63 @@ export class DownloadManager {
|
||||
this.updateTargetPath();
|
||||
});
|
||||
|
||||
// Load default path setting for current model type
|
||||
this.loadDefaultPathSetting();
|
||||
|
||||
this.updateTargetPath();
|
||||
} catch (error) {
|
||||
showToast(error.message, 'error');
|
||||
}
|
||||
}
|
||||
|
||||
loadDefaultPathSetting() {
|
||||
const modelType = this.apiClient.modelType;
|
||||
const storageKey = `use_default_path_${modelType}`;
|
||||
this.useDefaultPath = getStorageItem(storageKey, false);
|
||||
|
||||
const toggleInput = document.getElementById('useDefaultPath');
|
||||
if (toggleInput) {
|
||||
toggleInput.checked = this.useDefaultPath;
|
||||
this.updatePathSelectionUI();
|
||||
}
|
||||
}
|
||||
|
||||
toggleDefaultPath(event) {
|
||||
this.useDefaultPath = event.target.checked;
|
||||
|
||||
// Save to localStorage per model type
|
||||
const modelType = this.apiClient.modelType;
|
||||
const storageKey = `use_default_path_${modelType}`;
|
||||
setStorageItem(storageKey, this.useDefaultPath);
|
||||
|
||||
this.updatePathSelectionUI();
|
||||
this.updateTargetPath();
|
||||
}
|
||||
|
||||
updatePathSelectionUI() {
|
||||
const manualSelection = document.getElementById('manualPathSelection');
|
||||
|
||||
// Always show manual path selection, but disable/enable based on useDefaultPath
|
||||
manualSelection.style.display = 'block';
|
||||
if (this.useDefaultPath) {
|
||||
manualSelection.classList.add('disabled');
|
||||
// Disable all inputs and buttons inside manualSelection
|
||||
manualSelection.querySelectorAll('input, select, button').forEach(el => {
|
||||
el.disabled = true;
|
||||
el.tabIndex = -1;
|
||||
});
|
||||
} else {
|
||||
manualSelection.classList.remove('disabled');
|
||||
manualSelection.querySelectorAll('input, select, button').forEach(el => {
|
||||
el.disabled = false;
|
||||
el.tabIndex = 0;
|
||||
});
|
||||
}
|
||||
|
||||
// Always update the main path display
|
||||
this.updateTargetPath();
|
||||
}
|
||||
|
||||
backToUrl() {
|
||||
document.getElementById('versionStep').style.display = 'none';
|
||||
document.getElementById('urlStep').style.display = 'block';
|
||||
@@ -362,8 +422,16 @@ export class DownloadManager {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get selected folder path from folder tree manager
|
||||
const targetFolder = this.folderTreeManager.getSelectedPath();
|
||||
// Determine target folder and use_default_paths parameter
|
||||
let targetFolder = '';
|
||||
let useDefaultPaths = false;
|
||||
|
||||
if (this.useDefaultPath) {
|
||||
useDefaultPaths = true;
|
||||
targetFolder = ''; // Not needed when using default paths
|
||||
} else {
|
||||
targetFolder = this.folderTreeManager.getSelectedPath();
|
||||
}
|
||||
|
||||
try {
|
||||
const updateProgress = this.loadingManager.showDownloadProgress(1);
|
||||
@@ -402,12 +470,13 @@ export class DownloadManager {
|
||||
console.error('WebSocket error:', error);
|
||||
};
|
||||
|
||||
// Start download
|
||||
// Start download with use_default_paths parameter
|
||||
await this.apiClient.downloadModel(
|
||||
this.modelId,
|
||||
this.currentVersion.id,
|
||||
modelRoot,
|
||||
targetFolder,
|
||||
useDefaultPaths,
|
||||
downloadId
|
||||
);
|
||||
|
||||
@@ -418,19 +487,22 @@ export class DownloadManager {
|
||||
|
||||
// Update state and trigger reload
|
||||
const pageState = this.apiClient.getPageState();
|
||||
pageState.activeFolder = targetFolder;
|
||||
|
||||
// Save the active folder preference
|
||||
setStorageItem(`${this.apiClient.modelType}_activeFolder`, targetFolder);
|
||||
|
||||
// Update UI folder selection
|
||||
document.querySelectorAll('.folder-tags .tag').forEach(tag => {
|
||||
const isActive = tag.dataset.folder === targetFolder;
|
||||
tag.classList.toggle('active', isActive);
|
||||
if (isActive && !tag.parentNode.classList.contains('collapsed')) {
|
||||
tag.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
|
||||
}
|
||||
});
|
||||
if (!useDefaultPaths) {
|
||||
pageState.activeFolder = targetFolder;
|
||||
|
||||
// Save the active folder preference
|
||||
setStorageItem(`${this.apiClient.modelType}_activeFolder`, targetFolder);
|
||||
|
||||
// Update UI folder selection
|
||||
document.querySelectorAll('.folder-tags .tag').forEach(tag => {
|
||||
const isActive = tag.dataset.folder === targetFolder;
|
||||
tag.classList.toggle('active', isActive);
|
||||
if (isActive && !tag.parentNode.classList.contains('collapsed')) {
|
||||
tag.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
await resetAndReload(true);
|
||||
|
||||
@@ -517,9 +589,23 @@ export class DownloadManager {
|
||||
let fullPath = modelRoot || `Select a ${config.displayName} root directory`;
|
||||
|
||||
if (modelRoot) {
|
||||
const selectedPath = this.folderTreeManager ? this.folderTreeManager.getSelectedPath() : '';
|
||||
if (selectedPath) {
|
||||
fullPath += '/' + selectedPath;
|
||||
if (this.useDefaultPath) {
|
||||
// Show actual template path
|
||||
try {
|
||||
const singularType = this.apiClient.modelType.replace(/s$/, '');
|
||||
const templates = state.global.settings.download_path_templates;
|
||||
const template = templates[singularType];
|
||||
fullPath += `/${template}`;
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch template:', error);
|
||||
fullPath += '/[Auto-organized by path template]';
|
||||
}
|
||||
} else {
|
||||
// Show manual path selection
|
||||
const selectedPath = this.folderTreeManager ? this.folderTreeManager.getSelectedPath() : '';
|
||||
if (selectedPath) {
|
||||
fullPath += '/' + selectedPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import { showToast } from '../utils/uiHelpers.js';
|
||||
import { state } from '../state/index.js';
|
||||
import { resetAndReload } from '../api/modelApiFactory.js';
|
||||
import { setStorageItem, getStorageItem } from '../utils/storageHelpers.js';
|
||||
import { DOWNLOAD_PATH_TEMPLATES, MAPPABLE_BASE_MODELS } from '../utils/constants.js';
|
||||
import { DOWNLOAD_PATH_TEMPLATES, MAPPABLE_BASE_MODELS, PATH_TEMPLATE_PLACEHOLDERS, DEFAULT_PATH_TEMPLATES } from '../utils/constants.js';
|
||||
|
||||
export class SettingsManager {
|
||||
constructor() {
|
||||
@@ -73,11 +73,30 @@ export class SettingsManager {
|
||||
// We can delete the old setting, but keeping it for backwards compatibility
|
||||
}
|
||||
|
||||
// Set default for download path template if undefined
|
||||
if (state.global.settings.download_path_template === undefined) {
|
||||
state.global.settings.download_path_template = DOWNLOAD_PATH_TEMPLATES.BASE_MODEL_TAG.value;
|
||||
// Migrate legacy download_path_template to new structure
|
||||
if (state.global.settings.download_path_template && !state.global.settings.download_path_templates) {
|
||||
const legacyTemplate = state.global.settings.download_path_template;
|
||||
state.global.settings.download_path_templates = {
|
||||
lora: legacyTemplate,
|
||||
checkpoint: legacyTemplate,
|
||||
embedding: legacyTemplate
|
||||
};
|
||||
delete state.global.settings.download_path_template;
|
||||
setStorageItem('settings', state.global.settings);
|
||||
}
|
||||
|
||||
// Set default for download path templates if undefined
|
||||
if (state.global.settings.download_path_templates === undefined) {
|
||||
state.global.settings.download_path_templates = { ...DEFAULT_PATH_TEMPLATES };
|
||||
}
|
||||
|
||||
// Ensure all model types have templates
|
||||
Object.keys(DEFAULT_PATH_TEMPLATES).forEach(modelType => {
|
||||
if (typeof state.global.settings.download_path_templates[modelType] === 'undefined') {
|
||||
state.global.settings.download_path_templates[modelType] = DEFAULT_PATH_TEMPLATES[modelType];
|
||||
}
|
||||
});
|
||||
|
||||
// Set default for base model path mappings if undefined
|
||||
if (state.global.settings.base_model_path_mappings === undefined) {
|
||||
state.global.settings.base_model_path_mappings = {};
|
||||
@@ -105,7 +124,7 @@ export class SettingsManager {
|
||||
'default_checkpoint_root',
|
||||
'default_embedding_root',
|
||||
'base_model_path_mappings',
|
||||
'download_path_template'
|
||||
'download_path_templates'
|
||||
];
|
||||
|
||||
// Build payload for syncing
|
||||
@@ -113,7 +132,7 @@ export class SettingsManager {
|
||||
|
||||
fieldsToSync.forEach(key => {
|
||||
if (localSettings[key] !== undefined) {
|
||||
if (key === 'base_model_path_mappings') {
|
||||
if (key === 'base_model_path_mappings' || key === 'download_path_templates') {
|
||||
payload[key] = JSON.stringify(localSettings[key]);
|
||||
} else {
|
||||
payload[key] = localSettings[key];
|
||||
@@ -164,6 +183,30 @@ export class SettingsManager {
|
||||
document.querySelectorAll('.toggle-visibility').forEach(button => {
|
||||
button.addEventListener('click', () => this.toggleInputVisibility(button));
|
||||
});
|
||||
|
||||
['lora', 'checkpoint', 'embedding'].forEach(modelType => {
|
||||
const customInput = document.getElementById(`${modelType}CustomTemplate`);
|
||||
if (customInput) {
|
||||
customInput.addEventListener('input', (e) => {
|
||||
const template = e.target.value;
|
||||
settingsManager.validateTemplate(modelType, template);
|
||||
settingsManager.updateTemplatePreview(modelType, template);
|
||||
});
|
||||
|
||||
customInput.addEventListener('blur', (e) => {
|
||||
const template = e.target.value;
|
||||
if (settingsManager.validateTemplate(modelType, template)) {
|
||||
settingsManager.updateTemplate(modelType, template);
|
||||
}
|
||||
});
|
||||
|
||||
customInput.addEventListener('keydown', (e) => {
|
||||
if (e.key === 'Enter') {
|
||||
e.target.blur();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
this.initialized = true;
|
||||
}
|
||||
@@ -211,12 +254,8 @@ export class SettingsManager {
|
||||
autoDownloadExampleImagesCheckbox.checked = state.global.settings.autoDownloadExampleImages || false;
|
||||
}
|
||||
|
||||
// Set download path template setting
|
||||
const downloadPathTemplateSelect = document.getElementById('downloadPathTemplate');
|
||||
if (downloadPathTemplateSelect) {
|
||||
downloadPathTemplateSelect.value = state.global.settings.download_path_template || '';
|
||||
this.updatePathTemplatePreview();
|
||||
}
|
||||
// Load download path templates
|
||||
this.loadDownloadPathTemplates();
|
||||
|
||||
// Set include trigger words setting
|
||||
const includeTriggerWordsCheckbox = document.getElementById('includeTriggerWords');
|
||||
@@ -529,19 +568,184 @@ export class SettingsManager {
|
||||
}
|
||||
}
|
||||
|
||||
updatePathTemplatePreview() {
|
||||
const templateSelect = document.getElementById('downloadPathTemplate');
|
||||
const previewElement = document.getElementById('pathTemplatePreview');
|
||||
if (!templateSelect || !previewElement) return;
|
||||
|
||||
const template = templateSelect.value;
|
||||
const templateInfo = Object.values(DOWNLOAD_PATH_TEMPLATES).find(t => t.value === template);
|
||||
loadDownloadPathTemplates() {
|
||||
const templates = state.global.settings.download_path_templates || DEFAULT_PATH_TEMPLATES;
|
||||
|
||||
if (templateInfo) {
|
||||
previewElement.textContent = templateInfo.example;
|
||||
previewElement.style.display = 'block';
|
||||
Object.keys(templates).forEach(modelType => {
|
||||
this.loadTemplateForModelType(modelType, templates[modelType]);
|
||||
});
|
||||
}
|
||||
|
||||
loadTemplateForModelType(modelType, template) {
|
||||
const presetSelect = document.getElementById(`${modelType}TemplatePreset`);
|
||||
const customRow = document.getElementById(`${modelType}CustomRow`);
|
||||
const customInput = document.getElementById(`${modelType}CustomTemplate`);
|
||||
|
||||
if (!presetSelect) return;
|
||||
|
||||
// Find matching preset
|
||||
const matchingPreset = this.findMatchingPreset(template);
|
||||
|
||||
if (matchingPreset !== null) {
|
||||
presetSelect.value = matchingPreset;
|
||||
if (customRow) customRow.style.display = 'none';
|
||||
} else {
|
||||
previewElement.style.display = 'none';
|
||||
// Custom template
|
||||
presetSelect.value = 'custom';
|
||||
if (customRow) customRow.style.display = 'block';
|
||||
if (customInput) {
|
||||
customInput.value = template;
|
||||
this.validateTemplate(modelType, template);
|
||||
}
|
||||
}
|
||||
|
||||
this.updateTemplatePreview(modelType, template);
|
||||
}
|
||||
|
||||
findMatchingPreset(template) {
|
||||
const presetValues = Object.values(DOWNLOAD_PATH_TEMPLATES)
|
||||
.map(t => t.value)
|
||||
.filter(v => v !== 'custom');
|
||||
|
||||
return presetValues.includes(template) ? template : null;
|
||||
}
|
||||
|
||||
updateTemplatePreset(modelType, value) {
|
||||
const customRow = document.getElementById(`${modelType}CustomRow`);
|
||||
const customInput = document.getElementById(`${modelType}CustomTemplate`);
|
||||
|
||||
if (value === 'custom') {
|
||||
if (customRow) customRow.style.display = 'block';
|
||||
if (customInput) customInput.focus();
|
||||
return;
|
||||
} else {
|
||||
if (customRow) customRow.style.display = 'none';
|
||||
}
|
||||
|
||||
// Update template
|
||||
this.updateTemplate(modelType, value);
|
||||
}
|
||||
|
||||
updateTemplate(modelType, template) {
|
||||
// Validate template if it's custom
|
||||
if (document.getElementById(`${modelType}TemplatePreset`).value === 'custom') {
|
||||
if (!this.validateTemplate(modelType, template)) {
|
||||
return; // Don't save invalid templates
|
||||
}
|
||||
}
|
||||
|
||||
// Update state
|
||||
if (!state.global.settings.download_path_templates) {
|
||||
state.global.settings.download_path_templates = { ...DEFAULT_PATH_TEMPLATES };
|
||||
}
|
||||
state.global.settings.download_path_templates[modelType] = template;
|
||||
|
||||
// Update preview
|
||||
this.updateTemplatePreview(modelType, template);
|
||||
|
||||
// Save settings
|
||||
this.saveDownloadPathTemplates();
|
||||
}
|
||||
|
||||
validateTemplate(modelType, template) {
|
||||
const validationElement = document.getElementById(`${modelType}Validation`);
|
||||
if (!validationElement) return true;
|
||||
|
||||
// Reset validation state
|
||||
validationElement.innerHTML = '';
|
||||
validationElement.className = 'template-validation';
|
||||
|
||||
if (!template) {
|
||||
validationElement.innerHTML = '<i class="fas fa-check"></i> Valid (flat structure)';
|
||||
validationElement.classList.add('valid');
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check for invalid characters
|
||||
const invalidChars = /[<>:"|?*]/;
|
||||
if (invalidChars.test(template)) {
|
||||
validationElement.innerHTML = '<i class="fas fa-times"></i> Invalid characters detected';
|
||||
validationElement.classList.add('invalid');
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check for double slashes
|
||||
if (template.includes('//')) {
|
||||
validationElement.innerHTML = '<i class="fas fa-times"></i> Double slashes not allowed';
|
||||
validationElement.classList.add('invalid');
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if it starts or ends with slash
|
||||
if (template.startsWith('/') || template.endsWith('/')) {
|
||||
validationElement.innerHTML = '<i class="fas fa-times"></i> Cannot start or end with slash';
|
||||
validationElement.classList.add('invalid');
|
||||
return false;
|
||||
}
|
||||
|
||||
// Extract placeholders
|
||||
const placeholderRegex = /\{([^}]+)\}/g;
|
||||
const matches = template.match(placeholderRegex) || [];
|
||||
|
||||
// Check for invalid placeholders
|
||||
const invalidPlaceholders = matches.filter(match =>
|
||||
!PATH_TEMPLATE_PLACEHOLDERS.includes(match)
|
||||
);
|
||||
|
||||
if (invalidPlaceholders.length > 0) {
|
||||
validationElement.innerHTML = `<i class="fas fa-times"></i> Invalid placeholder: ${invalidPlaceholders[0]}`;
|
||||
validationElement.classList.add('invalid');
|
||||
return false;
|
||||
}
|
||||
|
||||
// Template is valid
|
||||
validationElement.innerHTML = '<i class="fas fa-check"></i> Valid template';
|
||||
validationElement.classList.add('valid');
|
||||
return true;
|
||||
}
|
||||
|
||||
updateTemplatePreview(modelType, template) {
|
||||
const previewElement = document.getElementById(`${modelType}Preview`);
|
||||
if (!previewElement) return;
|
||||
|
||||
if (!template) {
|
||||
previewElement.textContent = 'model-name.safetensors';
|
||||
} else {
|
||||
// Generate example preview
|
||||
const exampleTemplate = template
|
||||
.replace('{base_model}', 'Flux.1 D')
|
||||
.replace('{author}', 'authorname')
|
||||
.replace('{first_tag}', 'style');
|
||||
previewElement.textContent = `${exampleTemplate}/model-name.safetensors`;
|
||||
}
|
||||
previewElement.style.display = 'block';
|
||||
}
|
||||
|
||||
async saveDownloadPathTemplates() {
|
||||
try {
|
||||
// Save to localStorage
|
||||
setStorageItem('settings', state.global.settings);
|
||||
|
||||
// Save to backend
|
||||
const response = await fetch('/api/settings', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
download_path_templates: JSON.stringify(state.global.settings.download_path_templates)
|
||||
})
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to save download path templates');
|
||||
}
|
||||
|
||||
showToast('Download path templates updated', 'success');
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error saving download path templates:', error);
|
||||
showToast('Failed to save download path templates: ' + error.message, 'error');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -651,9 +855,6 @@ export class SettingsManager {
|
||||
state.global.settings.compactMode = (value !== 'default');
|
||||
} else if (settingKey === 'card_info_display') {
|
||||
state.global.settings.cardInfoDisplay = value;
|
||||
} else if (settingKey === 'download_path_template') {
|
||||
state.global.settings.download_path_template = value;
|
||||
this.updatePathTemplatePreview();
|
||||
} else {
|
||||
// For any other settings that might be added in the future
|
||||
state.global.settings[settingKey] = value;
|
||||
@@ -664,9 +865,13 @@ export class SettingsManager {
|
||||
|
||||
try {
|
||||
// For backend settings, make API call
|
||||
if (settingKey === 'default_lora_root' || settingKey === 'default_checkpoint_root' || settingKey === 'default_embedding_root' || settingKey === 'download_path_template') {
|
||||
if (settingKey === 'default_lora_root' || settingKey === 'default_checkpoint_root' || settingKey === 'default_embedding_root' || settingKey === 'download_path_templates') {
|
||||
const payload = {};
|
||||
payload[settingKey] = value;
|
||||
if (settingKey === 'download_path_templates') {
|
||||
payload[settingKey] = JSON.stringify(state.global.settings.download_path_templates);
|
||||
} else {
|
||||
payload[settingKey] = value;
|
||||
}
|
||||
|
||||
const response = await fetch('/api/settings', {
|
||||
method: 'POST',
|
||||
|
||||
@@ -114,6 +114,12 @@ export const DOWNLOAD_PATH_TEMPLATES = {
|
||||
description: 'Organize by base model type',
|
||||
example: 'Flux.1 D/model-name.safetensors'
|
||||
},
|
||||
AUTHOR: {
|
||||
value: '{author}',
|
||||
label: 'By Author',
|
||||
description: 'Organize by model author',
|
||||
example: 'authorname/model-name.safetensors'
|
||||
},
|
||||
FIRST_TAG: {
|
||||
value: '{first_tag}',
|
||||
label: 'By First Tag',
|
||||
@@ -125,9 +131,48 @@ export const DOWNLOAD_PATH_TEMPLATES = {
|
||||
label: 'Base Model + First Tag',
|
||||
description: 'Organize by base model and primary tag',
|
||||
example: 'Flux.1 D/style/model-name.safetensors'
|
||||
},
|
||||
BASE_MODEL_AUTHOR: {
|
||||
value: '{base_model}/{author}',
|
||||
label: 'Base Model + Author',
|
||||
description: 'Organize by base model and author',
|
||||
example: 'Flux.1 D/authorname/model-name.safetensors'
|
||||
},
|
||||
AUTHOR_TAG: {
|
||||
value: '{author}/{first_tag}',
|
||||
label: 'Author + First Tag',
|
||||
description: 'Organize by author and primary tag',
|
||||
example: 'authorname/style/model-name.safetensors'
|
||||
},
|
||||
CUSTOM: {
|
||||
value: 'custom',
|
||||
label: 'Custom Template',
|
||||
description: 'Create your own path structure',
|
||||
example: 'Enter custom template...'
|
||||
}
|
||||
};
|
||||
|
||||
// Valid placeholders for path templates
|
||||
export const PATH_TEMPLATE_PLACEHOLDERS = [
|
||||
'{base_model}',
|
||||
'{author}',
|
||||
'{first_tag}'
|
||||
];
|
||||
|
||||
// Default templates for each model type
|
||||
export const DEFAULT_PATH_TEMPLATES = {
|
||||
lora: '{base_model}/{first_tag}',
|
||||
checkpoint: '{base_model}',
|
||||
embedding: '{first_tag}'
|
||||
};
|
||||
|
||||
// Model type labels for UI
|
||||
export const MODEL_TYPE_LABELS = {
|
||||
lora: 'LoRA Models',
|
||||
checkpoint: 'Checkpoint Models',
|
||||
embedding: 'Embedding Models'
|
||||
};
|
||||
|
||||
// Base models available for path mapping (for UI selection)
|
||||
export const MAPPABLE_BASE_MODELS = Object.values(BASE_MODELS).sort();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user