fix: Simplify session item retrieval in loadMoreModels function

This commit is contained in:
Will Miao
2025-04-12 16:54:27 +08:00
parent 2fc06ae64e
commit 8f3cbdd257

View File

@@ -2,6 +2,7 @@
import { state, getCurrentPageState } from '../state/index.js'; import { state, getCurrentPageState } from '../state/index.js';
import { showToast } from '../utils/uiHelpers.js'; import { showToast } from '../utils/uiHelpers.js';
import { showDeleteModal, confirmDelete } from '../utils/modalUtils.js'; import { showDeleteModal, confirmDelete } from '../utils/modalUtils.js';
import { getSessionItem } from '../utils/storageHelpers.js';
/** /**
* Shared functionality for handling models (loras and checkpoints) * Shared functionality for handling models (loras and checkpoints)
@@ -89,8 +90,8 @@ export async function loadMoreModels(options = {}) {
// Add model-specific parameters // Add model-specific parameters
if (modelType === 'lora') { if (modelType === 'lora') {
// Check for recipe-based filtering parameters from session storage // Check for recipe-based filtering parameters from session storage
const filterLoraHash = getSessionItem ? getSessionItem('recipe_to_lora_filterLoraHash') : null; const filterLoraHash = getSessionItem('recipe_to_lora_filterLoraHash');
const filterLoraHashes = getSessionItem ? getSessionItem('recipe_to_lora_filterLoraHashes') : null; const filterLoraHashes = getSessionItem('recipe_to_lora_filterLoraHashes');
// Add hash filter parameter if present // Add hash filter parameter if present
if (filterLoraHash) { if (filterLoraHash) {
@@ -496,16 +497,3 @@ async function performDelete(filePath, modelType = 'lora') {
showToast(`Failed to delete ${modelType}: ${error.message}`, 'error'); showToast(`Failed to delete ${modelType}: ${error.message}`, 'error');
} }
} }
// Helper function to get session item - import if available, otherwise provide fallback
function getSessionItem(key) {
if (typeof window !== 'undefined' && window.sessionStorage) {
const item = window.sessionStorage.getItem(key);
try {
return item ? JSON.parse(item) : null;
} catch (e) {
return item;
}
}
return null;
}