diff --git a/packages/backend/src/managers/modelsManager.spec.ts b/packages/backend/src/managers/modelsManager.spec.ts index b5c2679b7..b7a7ade90 100644 --- a/packages/backend/src/managers/modelsManager.spec.ts +++ b/packages/backend/src/managers/modelsManager.spec.ts @@ -520,7 +520,9 @@ describe('downloadModel', () => { mocks.onEventDownloadMock.mockImplementation(listener => { listener({ + id: 'id', status: 'completed', + duration: 1000, }); }); diff --git a/packages/backend/src/managers/modelsManager.ts b/packages/backend/src/managers/modelsManager.ts index 361b1375c..5d8e7cb20 100644 --- a/packages/backend/src/managers/modelsManager.ts +++ b/packages/backend/src/managers/modelsManager.ts @@ -27,9 +27,9 @@ import * as podmanDesktopApi from '@podman-desktop/api'; import { Downloader } from '../utils/downloader'; import type { TaskRegistry } from '../registries/TaskRegistry'; import type { Task } from '@shared/src/models/ITask'; -import type { ProgressiveEvent } from '../utils/progressiveEvent'; -import { isCompletionProgressiveEvent, isProgressProgressiveEvent } from '../utils/progressiveEvent'; -import { Uploader } from '../models/uploader'; +import type { ProgressiveEvent } from '../models/progressiveEvent'; +import { isCompletionProgressiveEvent, isExecutingProgressiveEvent } from '../models/progressiveEvent'; +import { Uploader } from '../utils/uploader'; export class ModelsManager implements Disposable { #modelsDir: string; @@ -228,7 +228,7 @@ export class ModelsManager implements Disposable { } tasks.forEach(task => { - if (isProgressProgressiveEvent(event)) { + if (isExecutingProgressiveEvent(event)) { task.state = 'loading'; task.progress = event.value; } else if (isCompletionProgressiveEvent(event)) { @@ -316,7 +316,7 @@ export class ModelsManager implements Disposable { const uploader = new Uploader(localModelPath); uploader.onEvent((event: ProgressiveEvent) => { - if (isProgressProgressiveEvent(event)) { + if (isExecutingProgressiveEvent(event)) { task.state = 'loading'; task.progress = event.value; } else if (isCompletionProgressiveEvent(event)) { diff --git a/packages/backend/src/utils/progressiveEvent.ts b/packages/backend/src/models/progressiveEvent.ts similarity index 90% rename from packages/backend/src/utils/progressiveEvent.ts rename to packages/backend/src/models/progressiveEvent.ts index 5aa5771cd..71fb87f54 100644 --- a/packages/backend/src/utils/progressiveEvent.ts +++ b/packages/backend/src/models/progressiveEvent.ts @@ -27,7 +27,7 @@ export interface CompletionProgressiveEvent extends ProgressiveEvent { duration: number; } -export interface ProgressProgressiveEvent extends ProgressiveEvent { +export interface ExecutingProgressiveEvent extends ProgressiveEvent { status: 'progress'; value: number; } @@ -43,7 +43,7 @@ export const isCompletionProgressiveEvent = (value: unknown): value is Completio ); }; -export const isProgressProgressiveEvent = (value: unknown): value is ProgressProgressiveEvent => { +export const isExecutingProgressiveEvent = (value: unknown): value is ExecutingProgressiveEvent => { return ( !!value && typeof value === 'object' && 'status' in value && value['status'] === 'progress' && 'value' in value ); diff --git a/packages/backend/src/models/WSLUploader.spec.ts b/packages/backend/src/utils/WSLUploader.spec.ts similarity index 98% rename from packages/backend/src/models/WSLUploader.spec.ts rename to packages/backend/src/utils/WSLUploader.spec.ts index 04c6ff385..d0b2cfac9 100644 --- a/packages/backend/src/models/WSLUploader.spec.ts +++ b/packages/backend/src/utils/WSLUploader.spec.ts @@ -19,7 +19,7 @@ import { expect, test, describe, vi } from 'vitest'; import { WSLUploader } from './WSLUploader'; import * as podmanDesktopApi from '@podman-desktop/api'; -import * as utils from '../utils/podman'; +import * as utils from './podman'; import { beforeEach } from 'node:test'; const mocks = vi.hoisted(() => { diff --git a/packages/backend/src/models/WSLUploader.ts b/packages/backend/src/utils/WSLUploader.ts similarity index 96% rename from packages/backend/src/models/WSLUploader.ts rename to packages/backend/src/utils/WSLUploader.ts index e70ec3124..5799d7188 100644 --- a/packages/backend/src/models/WSLUploader.ts +++ b/packages/backend/src/utils/WSLUploader.ts @@ -18,7 +18,7 @@ import path from 'node:path'; import * as podmanDesktopApi from '@podman-desktop/api'; -import { getFirstRunningMachine, getPodmanCli } from '../utils/podman'; +import { getFirstRunningMachine, getPodmanCli } from './podman'; import type { UploadWorker } from './uploader'; export class WSLUploader implements UploadWorker { diff --git a/packages/backend/src/utils/downloader.ts b/packages/backend/src/utils/downloader.ts index 736f673fc..81bbe41e7 100644 --- a/packages/backend/src/utils/downloader.ts +++ b/packages/backend/src/utils/downloader.ts @@ -20,7 +20,11 @@ import { getDurationSecondsSince } from './utils'; import { createWriteStream, promises } from 'node:fs'; import https from 'node:https'; import { EventEmitter, type Event } from '@podman-desktop/api'; -import type { CompletionProgressiveEvent, ProgressProgressiveEvent, ProgressiveEvent } from './progressiveEvent'; +import type { + CompletionProgressiveEvent, + ExecutingProgressiveEvent, + ProgressiveEvent, +} from '../models/progressiveEvent'; export class Downloader { private readonly _onEvent = new EventEmitter(); @@ -129,7 +133,7 @@ export class Downloader { id: this.requestedIdentifier, status: 'progress', value: progressValue, - } as ProgressProgressiveEvent); + } as ExecutingProgressiveEvent); } }); resp.pipe(stream); diff --git a/packages/backend/src/models/uploader.spec.ts b/packages/backend/src/utils/uploader.spec.ts similarity index 95% rename from packages/backend/src/models/uploader.spec.ts rename to packages/backend/src/utils/uploader.spec.ts index 657b7c79f..fe0c5517e 100644 --- a/packages/backend/src/models/uploader.spec.ts +++ b/packages/backend/src/utils/uploader.spec.ts @@ -52,13 +52,13 @@ beforeEach(() => { describe('perform', () => { test('should return localModelPath if no workers for current system', async () => { vi.mocked(podmanDesktopApi.env).isWindows = false; - const result = await uploader.perform(); + const result = await uploader.perform('id'); expect(result).toBe('localpath'); }); test('should return remote path if there is a worker for current system', async () => { vi.spyOn(WSLUploader.prototype, 'upload').mockResolvedValue('remote'); vi.mocked(podmanDesktopApi.env).isWindows = true; - const result = await uploader.perform(); + const result = await uploader.perform('id'); expect(result).toBe('remote'); }); }); diff --git a/packages/backend/src/models/uploader.ts b/packages/backend/src/utils/uploader.ts similarity index 96% rename from packages/backend/src/models/uploader.ts rename to packages/backend/src/utils/uploader.ts index a4404c39a..aff45e2f9 100644 --- a/packages/backend/src/models/uploader.ts +++ b/packages/backend/src/utils/uploader.ts @@ -18,8 +18,8 @@ import { EventEmitter, type Event } from '@podman-desktop/api'; import { WSLUploader } from './WSLUploader'; -import { getDurationSecondsSince } from '../utils/utils'; -import type { CompletionProgressiveEvent, ProgressiveEvent } from '../utils/progressiveEvent'; +import { getDurationSecondsSince } from './utils'; +import type { CompletionProgressiveEvent, ProgressiveEvent } from '../models/progressiveEvent'; export interface UploadWorker { canUpload: () => boolean;