From 8f3cbdd257d92ab1508703c06fa4ef829995a1fd Mon Sep 17 00:00:00 2001 From: Will Miao <13051207myq@gmail.com> Date: Sat, 12 Apr 2025 16:54:27 +0800 Subject: [PATCH] fix: Simplify session item retrieval in loadMoreModels function --- static/js/api/baseModelApi.js | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/static/js/api/baseModelApi.js b/static/js/api/baseModelApi.js index b231b8f2..befc0471 100644 --- a/static/js/api/baseModelApi.js +++ b/static/js/api/baseModelApi.js @@ -2,6 +2,7 @@ import { state, getCurrentPageState } from '../state/index.js'; import { showToast } from '../utils/uiHelpers.js'; import { showDeleteModal, confirmDelete } from '../utils/modalUtils.js'; +import { getSessionItem } from '../utils/storageHelpers.js'; /** * Shared functionality for handling models (loras and checkpoints) @@ -89,8 +90,8 @@ export async function loadMoreModels(options = {}) { // Add model-specific parameters if (modelType === 'lora') { // Check for recipe-based filtering parameters from session storage - const filterLoraHash = getSessionItem ? getSessionItem('recipe_to_lora_filterLoraHash') : null; - const filterLoraHashes = getSessionItem ? getSessionItem('recipe_to_lora_filterLoraHashes') : null; + const filterLoraHash = getSessionItem('recipe_to_lora_filterLoraHash'); + const filterLoraHashes = getSessionItem('recipe_to_lora_filterLoraHashes'); // Add hash filter parameter if present if (filterLoraHash) { @@ -495,17 +496,4 @@ async function performDelete(filePath, modelType = 'lora') { console.error(`Error deleting ${modelType}:`, 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; } \ No newline at end of file