mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-08-06 14:10:13 -03:00
Compare commits
2 Commits
99e65cccd8
...
dd6bdbf297
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dd6bdbf297 | ||
|
|
b47dde87e4 |
@@ -1562,6 +1562,11 @@ class SettingsHandler:
|
||||
{"success": False, "error": validation_error}
|
||||
)
|
||||
|
||||
if key == "update_channel" and value not in ("release", "nightly"):
|
||||
return web.json_response(
|
||||
{"success": False, "error": "update_channel must be 'release' or 'nightly'"}
|
||||
)
|
||||
|
||||
if value == "__DELETE__" and key in (
|
||||
"proxy_username",
|
||||
"proxy_password",
|
||||
|
||||
@@ -1517,11 +1517,20 @@ export class SettingsManager {
|
||||
return data;
|
||||
}
|
||||
|
||||
async loadLoraRoots() {
|
||||
try {
|
||||
const defaultLoraRootSelect = document.getElementById('defaultLoraRoot');
|
||||
if (!defaultLoraRootSelect) return;
|
||||
showNoRootsPlaceholder(select) {
|
||||
select.innerHTML = '';
|
||||
const option = document.createElement('option');
|
||||
option.value = '';
|
||||
option.textContent = translate('settings.folderSettings.noDefault', {}, 'No Default');
|
||||
select.appendChild(option);
|
||||
select.disabled = true;
|
||||
}
|
||||
|
||||
async loadLoraRoots() {
|
||||
const defaultLoraRootSelect = document.getElementById('defaultLoraRoot');
|
||||
if (!defaultLoraRootSelect) return;
|
||||
|
||||
try {
|
||||
// Fetch lora roots
|
||||
const response = await fetch('/api/lm/loras/roots');
|
||||
if (!response.ok) {
|
||||
@@ -1530,10 +1539,12 @@ export class SettingsManager {
|
||||
|
||||
const data = await response.json();
|
||||
if (!data.roots || data.roots.length === 0) {
|
||||
throw new Error('No LoRA roots found');
|
||||
this.showNoRootsPlaceholder(defaultLoraRootSelect);
|
||||
return;
|
||||
}
|
||||
|
||||
defaultLoraRootSelect.innerHTML = '';
|
||||
defaultLoraRootSelect.disabled = false;
|
||||
|
||||
// Add options for each root
|
||||
data.roots.forEach(root => {
|
||||
@@ -1548,15 +1559,16 @@ export class SettingsManager {
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error loading LoRA roots:', error);
|
||||
this.showNoRootsPlaceholder(defaultLoraRootSelect);
|
||||
showToast('toast.settings.loraRootsFailed', { message: error.message }, 'error');
|
||||
}
|
||||
}
|
||||
|
||||
async loadCheckpointRoots() {
|
||||
try {
|
||||
const defaultCheckpointRootSelect = document.getElementById('defaultCheckpointRoot');
|
||||
if (!defaultCheckpointRootSelect) return;
|
||||
const defaultCheckpointRootSelect = document.getElementById('defaultCheckpointRoot');
|
||||
if (!defaultCheckpointRootSelect) return;
|
||||
|
||||
try {
|
||||
// Fetch checkpoint roots (checkpoint paths only, not unet)
|
||||
const response = await fetch('/api/lm/checkpoints/checkpoints_roots');
|
||||
if (!response.ok) {
|
||||
@@ -1565,10 +1577,12 @@ export class SettingsManager {
|
||||
|
||||
const data = await response.json();
|
||||
if (!data.roots || data.roots.length === 0) {
|
||||
throw new Error('No checkpoint roots found');
|
||||
this.showNoRootsPlaceholder(defaultCheckpointRootSelect);
|
||||
return;
|
||||
}
|
||||
|
||||
defaultCheckpointRootSelect.innerHTML = '';
|
||||
defaultCheckpointRootSelect.disabled = false;
|
||||
|
||||
// Add options for each root
|
||||
data.roots.forEach(root => {
|
||||
@@ -1583,15 +1597,16 @@ export class SettingsManager {
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error loading checkpoint roots:', error);
|
||||
this.showNoRootsPlaceholder(defaultCheckpointRootSelect);
|
||||
showToast('toast.settings.checkpointRootsFailed', { message: error.message }, 'error');
|
||||
}
|
||||
}
|
||||
|
||||
async loadUnetRoots() {
|
||||
try {
|
||||
const defaultUnetRootSelect = document.getElementById('defaultUnetRoot');
|
||||
if (!defaultUnetRootSelect) return;
|
||||
const defaultUnetRootSelect = document.getElementById('defaultUnetRoot');
|
||||
if (!defaultUnetRootSelect) return;
|
||||
|
||||
try {
|
||||
// Fetch unet roots (diffusion model paths only)
|
||||
const response = await fetch('/api/lm/checkpoints/unet_roots');
|
||||
if (!response.ok) {
|
||||
@@ -1600,10 +1615,12 @@ export class SettingsManager {
|
||||
|
||||
const data = await response.json();
|
||||
if (!data.roots || data.roots.length === 0) {
|
||||
throw new Error('No diffusion model roots found');
|
||||
this.showNoRootsPlaceholder(defaultUnetRootSelect);
|
||||
return;
|
||||
}
|
||||
|
||||
defaultUnetRootSelect.innerHTML = '';
|
||||
defaultUnetRootSelect.disabled = false;
|
||||
|
||||
// Add options for each root
|
||||
data.roots.forEach(root => {
|
||||
@@ -1618,15 +1635,16 @@ export class SettingsManager {
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error loading diffusion model roots:', error);
|
||||
this.showNoRootsPlaceholder(defaultUnetRootSelect);
|
||||
showToast('toast.settings.unetRootsFailed', { message: error.message }, 'error');
|
||||
}
|
||||
}
|
||||
|
||||
async loadEmbeddingRoots() {
|
||||
try {
|
||||
const defaultEmbeddingRootSelect = document.getElementById('defaultEmbeddingRoot');
|
||||
if (!defaultEmbeddingRootSelect) return;
|
||||
const defaultEmbeddingRootSelect = document.getElementById('defaultEmbeddingRoot');
|
||||
if (!defaultEmbeddingRootSelect) return;
|
||||
|
||||
try {
|
||||
// Fetch embedding roots
|
||||
const response = await fetch('/api/lm/embeddings/roots');
|
||||
if (!response.ok) {
|
||||
@@ -1635,10 +1653,12 @@ export class SettingsManager {
|
||||
|
||||
const data = await response.json();
|
||||
if (!data.roots || data.roots.length === 0) {
|
||||
throw new Error('No embedding roots found');
|
||||
this.showNoRootsPlaceholder(defaultEmbeddingRootSelect);
|
||||
return;
|
||||
}
|
||||
|
||||
defaultEmbeddingRootSelect.innerHTML = '';
|
||||
defaultEmbeddingRootSelect.disabled = false;
|
||||
|
||||
// Add options for each root
|
||||
data.roots.forEach(root => {
|
||||
@@ -1653,6 +1673,7 @@ export class SettingsManager {
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error loading embedding roots:', error);
|
||||
this.showNoRootsPlaceholder(defaultEmbeddingRootSelect);
|
||||
showToast('toast.settings.embeddingRootsFailed', { message: error.message }, 'error');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import { modalManager } from './ModalManager.js';
|
||||
import {
|
||||
getStorageItem,
|
||||
setStorageItem,
|
||||
getStoredVersionInfo,
|
||||
import {
|
||||
getStorageItem,
|
||||
setStorageItem,
|
||||
getStoredVersionInfo,
|
||||
setStoredVersionInfo,
|
||||
isVersionMatch
|
||||
} from '../utils/storageHelpers.js';
|
||||
import { state } from '../state/index.js';
|
||||
import { bannerService } from './BannerService.js';
|
||||
import { translate } from '../utils/i18nHelpers.js';
|
||||
|
||||
@@ -59,9 +60,6 @@ export class UpdateService {
|
||||
|
||||
// Perform update check if needed
|
||||
this.checkVersionInfo().then(() => {
|
||||
if (this.channelMode === null) {
|
||||
this.channelMode = this.hasGit ? 'nightly' : 'release';
|
||||
}
|
||||
this.checkForUpdates().then(() => {
|
||||
this.updateBadgeVisibility();
|
||||
});
|
||||
@@ -118,6 +116,14 @@ export class UpdateService {
|
||||
|
||||
if (data.success) {
|
||||
this.channelMode = channel;
|
||||
// Persist channel preference to settings.json
|
||||
fetch('/api/lm/settings', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ update_channel: channel })
|
||||
}).then(r => {
|
||||
if (!r.ok) console.warn('Failed to persist update channel:', r.status);
|
||||
}).catch(e => console.warn('Failed to persist update channel:', e));
|
||||
await this.checkForUpdates({ force: true });
|
||||
this.updateModalContent();
|
||||
this.updateChannelUI();
|
||||
@@ -154,6 +160,20 @@ export class UpdateService {
|
||||
}
|
||||
}
|
||||
|
||||
_resolveChannelFromSettings() {
|
||||
const stored = state?.global?.settings?.update_channel;
|
||||
if (stored === 'nightly' || stored === 'release') {
|
||||
return stored;
|
||||
}
|
||||
if (!this.hasGit) {
|
||||
return 'release';
|
||||
}
|
||||
if (this.gitInfo?.branch === 'detached') {
|
||||
return 'release';
|
||||
}
|
||||
return 'nightly';
|
||||
}
|
||||
|
||||
async _confirmChannelSwitch(titleKey, messageKey) {
|
||||
return new Promise((resolve) => {
|
||||
const title = translate(titleKey);
|
||||
@@ -475,6 +495,18 @@ export class UpdateService {
|
||||
}
|
||||
|
||||
async checkForUpdates({ force = false } = {}) {
|
||||
let needsMigration = false;
|
||||
if (this.channelMode === null) {
|
||||
const stored = state?.global?.settings?.update_channel;
|
||||
if (stored === 'nightly' || stored === 'release') {
|
||||
this.channelMode = stored;
|
||||
} else if (!this.hasGit) {
|
||||
this.channelMode = 'release';
|
||||
needsMigration = true;
|
||||
}
|
||||
// hasGit=true with no stored value: wait for gitInfo.branch
|
||||
}
|
||||
|
||||
if (!force && !this.updateNotificationsEnabled) {
|
||||
return;
|
||||
}
|
||||
@@ -493,7 +525,7 @@ export class UpdateService {
|
||||
|
||||
try {
|
||||
// Call backend API to check for updates with nightly flag
|
||||
const nightly = this.channelMode === 'nightly';
|
||||
const nightly = (this.channelMode ?? (this.hasGit ? 'nightly' : 'release')) === 'nightly';
|
||||
const response = await fetch(`/api/lm/check-updates?nightly=${nightly}`);
|
||||
const data = await response.json();
|
||||
|
||||
@@ -503,8 +535,19 @@ export class UpdateService {
|
||||
this.updateInfo = data;
|
||||
this.gitInfo = data.git_info || this.gitInfo;
|
||||
this.hasGit = data.has_git || false;
|
||||
if (this.channelMode === null) {
|
||||
this.channelMode = this.hasGit ? 'nightly' : 'release';
|
||||
|
||||
if (needsMigration || this.channelMode === null) {
|
||||
this.channelMode = this._resolveChannelFromSettings();
|
||||
if (state?.global?.settings) {
|
||||
state.global.settings.update_channel = this.channelMode;
|
||||
}
|
||||
fetch('/api/lm/settings', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ update_channel: this.channelMode })
|
||||
}).then(r => {
|
||||
if (!r.ok) console.warn('Failed to persist update channel:', r.status);
|
||||
}).catch(e => console.warn('Failed to persist update channel:', e));
|
||||
}
|
||||
|
||||
this.updateAvailable = data.update_available;
|
||||
|
||||
@@ -106,6 +106,118 @@ afterEach(() => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('SettingsManager root selects', () => {
|
||||
const rootCases = [
|
||||
{
|
||||
method: 'loadLoraRoots',
|
||||
selectId: 'defaultLoraRoot',
|
||||
endpoint: '/api/lm/loras/roots',
|
||||
errorKey: 'toast.settings.loraRootsFailed',
|
||||
},
|
||||
{
|
||||
method: 'loadCheckpointRoots',
|
||||
selectId: 'defaultCheckpointRoot',
|
||||
endpoint: '/api/lm/checkpoints/checkpoints_roots',
|
||||
errorKey: 'toast.settings.checkpointRootsFailed',
|
||||
},
|
||||
{
|
||||
method: 'loadUnetRoots',
|
||||
selectId: 'defaultUnetRoot',
|
||||
endpoint: '/api/lm/checkpoints/unet_roots',
|
||||
errorKey: 'toast.settings.unetRootsFailed',
|
||||
},
|
||||
{
|
||||
method: 'loadEmbeddingRoots',
|
||||
selectId: 'defaultEmbeddingRoot',
|
||||
endpoint: '/api/lm/embeddings/roots',
|
||||
errorKey: 'toast.settings.embeddingRootsFailed',
|
||||
},
|
||||
];
|
||||
|
||||
const appendRootSelect = (id) => {
|
||||
const select = document.createElement('select');
|
||||
select.id = id;
|
||||
document.body.appendChild(select);
|
||||
return select;
|
||||
};
|
||||
|
||||
it.each(rootCases)(
|
||||
'populates the $method select with roots and keeps it enabled',
|
||||
async ({ method, selectId, endpoint }) => {
|
||||
const manager = createManager();
|
||||
const select = appendRootSelect(selectId);
|
||||
select.disabled = true;
|
||||
|
||||
global.fetch = vi.fn().mockResolvedValue({
|
||||
ok: true,
|
||||
json: async () => ({
|
||||
success: true,
|
||||
roots: ['/models/root-a', '/models/root-b'],
|
||||
}),
|
||||
});
|
||||
|
||||
await manager[method]();
|
||||
|
||||
expect(global.fetch).toHaveBeenCalledWith(endpoint);
|
||||
expect(Array.from(select.options).map(option => option.value)).toEqual([
|
||||
'/models/root-a',
|
||||
'/models/root-b',
|
||||
]);
|
||||
expect(select.disabled).toBe(false);
|
||||
expect(showToast).not.toHaveBeenCalled();
|
||||
}
|
||||
);
|
||||
|
||||
it.each(rootCases)(
|
||||
'shows a placeholder and no error toast when $method has empty roots',
|
||||
async ({ method, selectId, endpoint }) => {
|
||||
const manager = createManager();
|
||||
const select = appendRootSelect(selectId);
|
||||
|
||||
global.fetch = vi.fn().mockResolvedValue({
|
||||
ok: true,
|
||||
json: async () => ({
|
||||
success: true,
|
||||
roots: [],
|
||||
}),
|
||||
});
|
||||
|
||||
await manager[method]();
|
||||
|
||||
expect(global.fetch).toHaveBeenCalledWith(endpoint);
|
||||
expect(select.options).toHaveLength(1);
|
||||
expect(select.options[0].value).toBe('');
|
||||
expect(select.options[0].textContent).toBe('No Default');
|
||||
expect(select.disabled).toBe(true);
|
||||
expect(showToast).not.toHaveBeenCalled();
|
||||
}
|
||||
);
|
||||
|
||||
it.each(rootCases)(
|
||||
'shows an error toast when the $method roots request fails',
|
||||
async ({ method, selectId, errorKey }) => {
|
||||
const manager = createManager();
|
||||
const select = appendRootSelect(selectId);
|
||||
|
||||
global.fetch = vi.fn().mockResolvedValue({
|
||||
ok: false,
|
||||
status: 500,
|
||||
});
|
||||
|
||||
await manager[method]();
|
||||
|
||||
expect(select.options).toHaveLength(1);
|
||||
expect(select.options[0].value).toBe('');
|
||||
expect(select.disabled).toBe(true);
|
||||
expect(showToast).toHaveBeenCalledWith(
|
||||
errorKey,
|
||||
expect.objectContaining({ message: expect.any(String) }),
|
||||
'error',
|
||||
);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
describe('SettingsManager library controls', () => {
|
||||
it('loads libraries and populates the select', async () => {
|
||||
const manager = createManager();
|
||||
|
||||
@@ -1,12 +1,26 @@
|
||||
import { describe, beforeEach, afterEach, expect, it, vi } from 'vitest';
|
||||
import { UpdateService } from '../../../static/js/managers/UpdateService.js';
|
||||
import { state } from '../../../static/js/state/index.js';
|
||||
|
||||
function createFetchResponse(payload) {
|
||||
return {
|
||||
json: vi.fn().mockResolvedValue(payload)
|
||||
json: vi.fn().mockResolvedValue(payload),
|
||||
ok: true,
|
||||
};
|
||||
}
|
||||
|
||||
function stubSettingsUpdateChannel(channel) {
|
||||
state.global = state.global || {};
|
||||
state.global.settings = state.global.settings || {};
|
||||
state.global.settings.update_channel = channel;
|
||||
}
|
||||
|
||||
function clearSettingsUpdateChannel() {
|
||||
if (state.global?.settings) {
|
||||
delete state.global.settings.update_channel;
|
||||
}
|
||||
}
|
||||
|
||||
describe('UpdateService passive checks', () => {
|
||||
let service;
|
||||
let fetchMock;
|
||||
@@ -16,10 +30,13 @@ describe('UpdateService passive checks', () => {
|
||||
success: true,
|
||||
current_version: 'v1.0.0',
|
||||
latest_version: 'v1.0.0',
|
||||
git_info: { short_hash: 'abc123' }
|
||||
git_info: { short_hash: 'abc123' },
|
||||
has_git: true,
|
||||
}));
|
||||
global.fetch = fetchMock;
|
||||
|
||||
stubSettingsUpdateChannel('release');
|
||||
|
||||
service = new UpdateService();
|
||||
service.updateNotificationsEnabled = false;
|
||||
service.lastCheckTime = 0;
|
||||
@@ -28,6 +45,7 @@ describe('UpdateService passive checks', () => {
|
||||
|
||||
afterEach(() => {
|
||||
delete global.fetch;
|
||||
clearSettingsUpdateChannel();
|
||||
});
|
||||
|
||||
it('skips passive update checks when notifications are disabled', async () => {
|
||||
|
||||
Reference in New Issue
Block a user