1+ import ora from 'ora' ;
12import { CreateModelDto } from '@/infrastructure/dtos/models/create-model.dto' ;
23import { UpdateModelDto } from '@/infrastructure/dtos/models/update-model.dto' ;
34import { BadRequestException , Injectable } from '@nestjs/common' ;
45import { Model , ModelSettingParams } from '@/domain/models/model.interface' ;
56import { ModelNotFoundException } from '@/infrastructure/exception/model-not-found.exception' ;
67import { basename , join } from 'path' ;
7- import { promises , existsSync , mkdirSync , rmdirSync , readFileSync } from 'fs' ;
8+ import { promises , existsSync , mkdirSync , readFileSync , rmSync } from 'fs' ;
89import { StartModelSuccessDto } from '@/infrastructure/dtos/models/start-model-success.dto' ;
910import { ExtensionRepository } from '@/domain/repositories/extension.interface' ;
1011import { EngineExtension } from '@/domain/abstracts/engine.abstract' ;
@@ -123,8 +124,7 @@ export class ModelsUsecases {
123124 . remove ( id )
124125 . then (
125126 ( ) =>
126- existsSync ( modelFolder ) &&
127- rmdirSync ( modelFolder , { recursive : true } ) ,
127+ existsSync ( modelFolder ) && rmSync ( modelFolder , { recursive : true } ) ,
128128 )
129129 . then ( ( ) => {
130130 const modelEvent : ModelEvent = {
@@ -163,7 +163,7 @@ export class ModelsUsecases {
163163 modelId,
164164 } ;
165165 }
166- console . log ( 'Loading model...' ) ;
166+ const loadingModelSpinner = ora ( 'Loading model...' ) . start ( ) ;
167167 // update states and emitting event
168168 this . activeModelStatuses [ modelId ] = {
169169 model : modelId ,
@@ -210,10 +210,13 @@ export class ModelsUsecases {
210210 } ;
211211 this . eventEmitter . emit ( 'model.event' , modelEvent ) ;
212212 } )
213- . then ( ( ) => ( {
214- message : 'Model loaded successfully' ,
215- modelId,
216- } ) )
213+ . then ( ( ) => {
214+ loadingModelSpinner . succeed ( 'Model loaded' ) ;
215+ return {
216+ message : 'Model loaded successfully' ,
217+ modelId,
218+ } ;
219+ } )
217220 . catch ( async ( e ) => {
218221 // remove the model from this.activeModelStatus.
219222 delete this . activeModelStatuses [ modelId ] ;
@@ -229,6 +232,7 @@ export class ModelsUsecases {
229232 modelId,
230233 } ;
231234 }
235+ loadingModelSpinner . fail ( 'Model loading failed' ) ;
232236 await this . telemetryUseCases . createCrashReport (
233237 e ,
234238 TelemetrySource . CORTEX_CPP ,
@@ -359,7 +363,9 @@ export class ModelsUsecases {
359363 toDownloads ,
360364 // Post processing
361365 async ( ) => {
362- console . log ( 'Update model metadata...' ) ;
366+ const uploadModelMetadataSpiner = ora (
367+ 'Updating model metadata...' ,
368+ ) . start ( ) ;
363369 // Post processing after download
364370 if ( existsSync ( join ( modelFolder , 'model.yml' ) ) ) {
365371 const model : CreateModelDto = load (
@@ -409,6 +415,7 @@ export class ModelsUsecases {
409415 } ) ;
410416 }
411417 }
418+ uploadModelMetadataSpiner . succeed ( 'Model metadata updated' ) ;
412419 const modelEvent : ModelEvent = {
413420 model : modelId ,
414421 event : 'model-downloaded' ,
0 commit comments