@@ -8,7 +8,6 @@ import { CLIUtils } from '../utils/cli.utils';
88import { ConfigService } from '../services/config.service' ;
99import path from 'node:path' ;
1010import { DriveFileService } from '../services/drive/drive-file.service' ;
11- import { UploadService } from '../services/network/upload.service' ;
1211import { CryptoService } from '../services/crypto.service' ;
1312import { DownloadService } from '../services/network/download.service' ;
1413import { ErrorUtils } from '../utils/errors.utils' ;
@@ -19,6 +18,7 @@ import { ThumbnailService } from '../services/thumbnail.service';
1918import { BufferStream } from '../utils/stream.utils' ;
2019import { isFileThumbnailable } from '../utils/thumbnail.utils' ;
2120import { Readable } from 'node:stream' ;
21+ import { Environment } from '@internxt/inxt-js' ;
2222
2323export default class UploadFile extends Command {
2424 static readonly args = { } ;
@@ -72,9 +72,15 @@ export default class UploadFile extends Command {
7272 user : user . bridgeUser ,
7373 pass : user . userId ,
7474 } ) ;
75+ const environment = new Environment ( {
76+ bridgeUser : user . bridgeUser ,
77+ bridgePass : user . userId ,
78+ bridgeUrl : ConfigService . instance . get ( 'NETWORK_URL' ) ,
79+ encryptionKey : user . mnemonic ,
80+ } ) ;
7581 const networkFacade = new NetworkFacade (
7682 networkModule ,
77- UploadService . instance ,
83+ environment ,
7884 DownloadService . instance ,
7985 CryptoService . instance ,
8086 ) ;
@@ -99,32 +105,35 @@ export default class UploadFile extends Command {
99105 }
100106
101107 const progressCallback = ( progress : number ) => {
102- progressBar . update ( progress * 0.99 ) ;
108+ progressBar . update ( progress * 100 * 0.99 ) ;
103109 } ;
104110
105- const [ uploadPromise , abortable ] = await UploadService . instance . uploadFileStream (
106- fileStream ,
107- user . bucket ,
108- user . mnemonic ,
109- stats . size ,
110- networkFacade ,
111- progressCallback ,
112- ) ;
113-
114- process . on ( 'SIGINT' , ( ) => {
115- abortable . abort ( 'SIGINT received' ) ;
116- process . exit ( 1 ) ;
111+ const fileId = await new Promise ( ( resolve : ( fileId : string ) => void , reject ) => {
112+ const state = networkFacade . uploadFile (
113+ fileStream ,
114+ stats . size ,
115+ user . bucket ,
116+ ( err : Error | null , res : string | null ) => {
117+ if ( err ) {
118+ return reject ( err ) ;
119+ }
120+ resolve ( res as string ) ;
121+ } ,
122+ progressCallback ,
123+ ) ;
124+ process . on ( 'SIGINT' , ( ) => {
125+ state . stop ( ) ;
126+ process . exit ( 1 ) ;
127+ } ) ;
117128 } ) ;
118129
119- const uploadResult = await uploadPromise ;
120-
121130 // 3. Create the file in Drive
122131 const createdDriveFile = await DriveFileService . instance . createFile ( {
123132 plain_name : fileInfo . name ,
124133 type : fileType ,
125134 size : stats . size ,
126135 folder_id : destinationFolderUuid ,
127- id : uploadResult . fileId ,
136+ id : fileId ,
128137 bucket : user . bucket ,
129138 encrypt_version : EncryptionVersion . Aes03 ,
130139 name : '' ,
@@ -139,7 +148,6 @@ export default class UploadFile extends Command {
139148 thumbnailBuffer ,
140149 fileType ,
141150 user . bucket ,
142- user . mnemonic ,
143151 createdDriveFile . id ,
144152 networkFacade ,
145153 ) ;
0 commit comments