diff --git a/frontend/package-lock.json b/frontend/package-lock.json index f6ac9a0..7066671 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -18,6 +18,7 @@ "file-saver": "^2.0.5", "html-midi-player": "^1.5.0", "i18next": "^22.4.15", + "lodash-es": "^4.17.21", "mobx": "^6.9.0", "mobx-react-lite": "^3.4.3", "pdfjs-dist": "^4.0.189", @@ -40,6 +41,7 @@ }, "devDependencies": { "@types/file-saver": "^2.0.7", + "@types/lodash-es": "^4.17.12", "@types/react": "^18.2.6", "@types/react-beautiful-dnd": "^13.1.4", "@types/react-dom": "^18.2.4", @@ -2533,6 +2535,21 @@ "hoist-non-react-statics": "^3.3.0" } }, + "node_modules/@types/lodash": { + "version": "4.14.202", + "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.202.tgz", + "integrity": "sha512-OvlIYQK9tNneDlS0VN54LLd5uiPCBOp7gS5Z0f1mjoJYBrtStzgmJBxONW3U6OZqdtNzZPmn9BS/7WI7BFFcFQ==", + "dev": true + }, + "node_modules/@types/lodash-es": { + "version": "4.17.12", + "resolved": "https://registry.npmjs.org/@types/lodash-es/-/lodash-es-4.17.12.tgz", + "integrity": "sha512-0NgftHUcV4v34VhXm8QBSftKVXtbkBG3ViCjs6+eJ5a6y6Mi/jiFGPc1sC7QK+9BFhWrURE3EOggmWaSxL9OzQ==", + "dev": true, + "dependencies": { + "@types/lodash": "*" + } + }, "node_modules/@types/long": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/@types/long/-/long-4.0.2.tgz", @@ -4210,6 +4227,11 @@ "integrity": "sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==", "dev": true }, + "node_modules/lodash-es": { + "version": "4.17.21", + "resolved": "https://registry.npmjs.org/lodash-es/-/lodash-es-4.17.21.tgz", + "integrity": "sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw==" + }, "node_modules/long": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/long/-/long-4.0.0.tgz", diff --git a/frontend/package.json b/frontend/package.json index c0ff6de..b866159 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -19,6 +19,7 @@ "file-saver": "^2.0.5", "html-midi-player": "^1.5.0", "i18next": "^22.4.15", + "lodash-es": "^4.17.21", "mobx": "^6.9.0", "mobx-react-lite": "^3.4.3", "pdfjs-dist": "^4.0.189", @@ -41,6 +42,7 @@ }, "devDependencies": { "@types/file-saver": "^2.0.7", + "@types/lodash-es": "^4.17.12", "@types/react": "^18.2.6", "@types/react-beautiful-dnd": "^13.1.4", "@types/react-dom": "^18.2.4", diff --git a/frontend/src/utils/index.tsx b/frontend/src/utils/index.tsx index 452be72..b55597a 100644 --- a/frontend/src/utils/index.tsx +++ b/frontend/src/utils/index.tsx @@ -27,6 +27,7 @@ import logo from '../assets/images/logo.png'; import { Preset } from '../types/presets'; import { botName, Conversation, MessageType, userName } from '../types/chat'; import { v4 as uuid } from 'uuid'; +import { findLastIndex } from 'lodash-es'; export type Cache = { version: string @@ -145,7 +146,7 @@ function initLastUnfinishedModelDownloads() { export async function refreshRemoteModels(cache: { models: ModelSourceItem[] -}) { +}, filter: boolean = true, initUnfinishedModels: boolean = false) { const manifestUrls = commonStore.modelSourceManifestList.split(/[,,;;\n]/); const requests = manifestUrls.filter(url => url.endsWith('.json')).map( url => fetch(url, { cache: 'no-cache' }).then(r => r.json())); @@ -162,18 +163,16 @@ export async function refreshRemoteModels(cache: { }); cache.models = cache.models.filter((model, index, self) => { return modelSuffix.some((ext => model.name.endsWith(ext))) - && index === self.findIndex( - m => m.name === model.name || (m.SHA256 && m.SHA256 === model.SHA256 && m.size === model.size)); - }); - commonStore.setModelSourceList(cache.models); - await saveCache().catch(() => { + && index === findLastIndex(self, + m => m.name === model.name || (!!m.SHA256 && m.SHA256 === model.SHA256 && m.size === model.size)); }); + await refreshLocalModels(cache, filter, initUnfinishedModels); } export const refreshModels = async (readCache: boolean = false, initUnfinishedModels: boolean = false) => { const cache = await refreshBuiltInModels(readCache); await refreshLocalModels(cache, false, initUnfinishedModels); - await refreshRemoteModels(cache); + await refreshRemoteModels(cache, false, initUnfinishedModels); }; export const getStrategy = (modelConfig: ModelConfig | undefined = undefined) => { diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts index 1c1b93b..040ed0b 100644 --- a/frontend/vite.config.ts +++ b/frontend/vite.config.ts @@ -12,7 +12,7 @@ const vendor = [ 'mobx', 'mobx-react-lite', 'i18next', 'react-i18next', 'usehooks-ts', 'react-toastify', - 'classnames' + 'classnames', 'lodash-es' ]; const embedded = [