{
- item.isLocal &&
+ item.isComplete &&
} onClick={() => {
OpenFileFolder(`${commonStore.settings.customModelsPath}/${item.name}`, true);
}} />
}
- {item.downloadUrl && !item.isLocal &&
+ {item.downloadUrl && !item.isComplete &&
} onClick={() => {
toastWithButton(`${t('Downloading')} ${item.name}`, t('Check'), () => {
navigate({ pathname: '/downloads' });
@@ -203,7 +205,7 @@ export const Models: FC = observer(() => {
>
{({ item, rowId }) => (
- (!item.hide || item.isLocal) &&
+ (!item.hide || item.isComplete) &&
key={rowId}>
{({ renderCell }) => (
{renderCell(item)}
diff --git a/frontend/src/startup.ts b/frontend/src/startup.ts
index 12657d3..dadca46 100644
--- a/frontend/src/startup.ts
+++ b/frontend/src/startup.ts
@@ -16,7 +16,7 @@ export async function startup() {
await GetPlatform().then(p => commonStore.setPlatform(p as Platform));
await initConfig();
- initCache().then(initRemoteText); // depends on config customModelsPath
+ initCache(true).then(initRemoteText); // depends on config customModelsPath
if (commonStore.settings.autoUpdatesCheck) // depends on config settings
checkUpdate();
@@ -58,11 +58,11 @@ async function initConfig() {
});
}
-async function initCache() {
+async function initCache(initUnfinishedModels: boolean) {
await ReadJson('cache.json').then((cacheData: Cache) => {
if (cacheData.depComplete)
commonStore.setDepComplete(cacheData.depComplete);
}).catch(() => {
});
- await refreshModels(false);
+ await refreshModels(false, initUnfinishedModels);
}
\ No newline at end of file
diff --git a/frontend/src/stores/commonStore.ts b/frontend/src/stores/commonStore.ts
index f093ac5..398f7ea 100644
--- a/frontend/src/stores/commonStore.ts
+++ b/frontend/src/stores/commonStore.ts
@@ -55,6 +55,7 @@ class CommonStore {
modelSourceList: ModelSourceItem[] = [];
// downloads
downloadList: DownloadStatus[] = [];
+ lastUnfinishedModelDownloads: DownloadStatus[] = [];
// settings
advancedCollapsed: boolean = true;
settings: SettingsType = {
@@ -197,6 +198,10 @@ class CommonStore {
setAdvancedCollapsed(value: boolean) {
this.advancedCollapsed = value;
}
+
+ setLastUnfinishedModelDownloads(value: DownloadStatus[]) {
+ this.lastUnfinishedModelDownloads = value;
+ }
}
export default new CommonStore();
\ No newline at end of file
diff --git a/frontend/src/utils/index.tsx b/frontend/src/utils/index.tsx
index 1b9e2ad..2ac09af 100644
--- a/frontend/src/utils/index.tsx
+++ b/frontend/src/utils/index.tsx
@@ -16,6 +16,7 @@ import { Button } from '@fluentui/react-components';
import { Language, Languages, SettingsType } from '../pages/Settings';
import { ModelSourceItem } from '../pages/Models';
import { ModelConfig, ModelParameters } from '../pages/Configs';
+import { DownloadStatus } from '../pages/Downloads';
export type Cache = {
models: ModelSourceItem[]
@@ -47,9 +48,11 @@ export async function refreshBuiltInModels(readCache: boolean = false) {
return cache;
}
-export async function refreshLocalModels(cache: { models: ModelSourceItem[] }, filter: boolean = true) {
+export async function refreshLocalModels(cache: {
+ models: ModelSourceItem[]
+}, filter: boolean = true, initUnfinishedModels: boolean = false) {
if (filter)
- cache.models = cache.models.filter(m => !m.isLocal); //TODO BUG cause local but in manifest files to be removed, so currently cache is disabled
+ cache.models = cache.models.filter(m => !m.isComplete); //TODO BUG cause local but in manifest files to be removed, so currently cache is disabled
await ListDirFiles(commonStore.settings.customModelsPath).then((data) => {
cache.models.push(...data.flatMap(d => {
@@ -58,8 +61,9 @@ export async function refreshLocalModels(cache: { models: ModelSourceItem[] }, f
name: d.name,
size: d.size,
lastUpdated: d.modTime,
+ isComplete: true,
isLocal: true
- }];
+ }] as ModelSourceItem[];
return [];
}));
}).catch(() => {
@@ -80,17 +84,43 @@ export async function refreshLocalModels(cache: { models: ModelSourceItem[] }, f
} else {
cache.models[i] = Object.assign({}, cache.models[j], cache.models[i]);
}
- } // else is bad local file
+ } // else is not complete local file
+ cache.models[i].isLocal = true;
+ cache.models[i].localSize = cache.models[j].size;
cache.models.splice(j, 1);
j--;
}
}
}
commonStore.setModelSourceList(cache.models);
+ if (initUnfinishedModels)
+ initLastUnfinishedModelDownloads();
await saveCache().catch(() => {
});
}
+function initLastUnfinishedModelDownloads() {
+ const list: DownloadStatus[] = [];
+ commonStore.modelSourceList.forEach((item) => {
+ if (item.isLocal && !item.isComplete) {
+ list.push(
+ {
+ name: item.name,
+ path: `${commonStore.settings.customModelsPath}/${item.name}`,
+ url: item.downloadUrl!,
+ transferred: item.localSize!,
+ size: item.size,
+ speed: 0,
+ progress: item.localSize! / item.size * 100,
+ downloading: false,
+ done: false
+ }
+ );
+ }
+ });
+ commonStore.setLastUnfinishedModelDownloads(list);
+}
+
export async function refreshRemoteModels(cache: { models: ModelSourceItem[] }) {
const manifestUrls = commonStore.modelSourceManifestList.split(/[,,;;\n]/);
const requests = manifestUrls.filter(url => url.endsWith('.json')).map(
@@ -116,9 +146,9 @@ export async function refreshRemoteModels(cache: { models: ModelSourceItem[] })
});
}
-export const refreshModels = async (readCache: boolean = false) => {
+export const refreshModels = async (readCache: boolean = false, initUnfinishedModels: boolean = false) => {
const cache = await refreshBuiltInModels(readCache);
- await refreshLocalModels(cache);
+ await refreshLocalModels(cache, false, initUnfinishedModels);
await refreshRemoteModels(cache);
};