@@ -127,12 +127,20 @@ export class ServerConsole {
127127 }
128128
129129 async execute ( command : string ) : Promise < string > {
130- const child = Command . create ( "ssh" , [ "-tt" , "-o" , "StrictHostKeyChecking=accept-new" , "-i" , await this . server . config ( ) . getKey ( ) . getPath ( ) , `root@${ this . server . config ( ) . getIP ( ) } ` , command ] ) ;
131-
130+ const child = Command . create ( "ssh" , [
131+ "-tt" ,
132+ "-o" ,
133+ "StrictHostKeyChecking=accept-new" ,
134+ "-i" ,
135+ await this . server . config ( ) . getKey ( ) . getPath ( ) ,
136+ `root@${ this . server . config ( ) . getIP ( ) } ` ,
137+ command ,
138+ ] ) ;
139+
132140 return new Promise ( ( resolve , reject ) => {
133141 let stdout = "" ;
134142 let stderr = "" ;
135-
143+
136144 child . on ( "close" , ( data ) => {
137145 if ( data . code === 0 ) {
138146 resolve ( stdout ) ;
@@ -144,25 +152,31 @@ export class ServerConsole {
144152 } else if ( stderr . includes ( "Permission denied" ) ) {
145153 reject ( new Error ( "Cannot connect to server: Permission denied" ) ) ;
146154 } else if ( stderr . includes ( "Host key verification failed" ) ) {
147- reject ( new Error ( "Cannot connect to server: Host key verification failed" ) ) ;
155+ reject (
156+ new Error (
157+ "Cannot connect to server: Host key verification failed" ,
158+ ) ,
159+ ) ;
148160 } else {
149- reject ( new Error ( `Command failed with code ${ data . code } : ${ stderr } ` ) ) ;
161+ reject (
162+ new Error ( `Command failed with code ${ data . code } : ${ stderr } ` ) ,
163+ ) ;
150164 }
151165 }
152166 } ) ;
153-
167+
154168 child . on ( "error" , ( error ) => {
155169 reject ( new Error ( `Error executing command: ${ error } ` ) ) ;
156170 } ) ;
157-
171+
158172 child . stdout . on ( "data" , ( data ) => {
159173 stdout += data ;
160174 } ) ;
161-
175+
162176 child . stderr . on ( "data" , ( data ) => {
163177 stderr += data ;
164178 } ) ;
165-
179+
166180 child . spawn ( ) ;
167181 } ) ;
168182 }
@@ -174,11 +188,11 @@ class Docker {
174188 constructor ( server : Server ) {
175189 this . server = server ;
176190 }
177-
191+
178192 async getVersion ( ) : Promise < string > {
179193 try {
180194 const output = await this . server . console . execute ( "docker version" ) ;
181- const lines = output . split ( '\n' ) ;
195+ const lines = output . split ( "\n" ) ;
182196 let foundCommunity = false ;
183197 let version = null ;
184198
@@ -224,47 +238,47 @@ class Docker {
224238 } > {
225239 try {
226240 const command = `echo "===CONTAINERS===" && docker ps -a --format "{{.Status}}" && echo "===IMAGES===" && docker images --format "{{.Repository}}" && echo "===DANGLING===" && docker images -f dangling=true --format "{{.Repository}}" && echo "===SIZE===" && docker system df` ;
227-
241+
228242 const output = await this . server . console . execute ( command ) ;
229243 console . log ( "Docker command output:" , output ) ; // Debug log
230-
231- const lines = output . split ( '\n' ) ;
232- let currentSection = '' ;
244+
245+ const lines = output . split ( "\n" ) ;
246+ let currentSection = "" ;
233247 const containers : string [ ] = [ ] ;
234248 const images : string [ ] = [ ] ;
235249 const dangling : string [ ] = [ ] ;
236250 let size = "0B" ;
237-
251+
238252 for ( const line of lines ) {
239253 const trimmedLine = line . trim ( ) ;
240-
241- if ( trimmedLine === ' ===CONTAINERS===' ) {
242- currentSection = ' containers' ;
254+
255+ if ( trimmedLine === " ===CONTAINERS===" ) {
256+ currentSection = " containers" ;
243257 continue ;
244- } else if ( trimmedLine === ' ===IMAGES===' ) {
245- currentSection = ' images' ;
258+ } else if ( trimmedLine === " ===IMAGES===" ) {
259+ currentSection = " images" ;
246260 continue ;
247- } else if ( trimmedLine === ' ===DANGLING===' ) {
248- currentSection = ' dangling' ;
261+ } else if ( trimmedLine === " ===DANGLING===" ) {
262+ currentSection = " dangling" ;
249263 continue ;
250- } else if ( trimmedLine === ' ===SIZE===' ) {
251- currentSection = ' size' ;
264+ } else if ( trimmedLine === " ===SIZE===" ) {
265+ currentSection = " size" ;
252266 continue ;
253267 }
254-
255- if ( trimmedLine && ! trimmedLine . includes ( ' REPOSITORY' ) ) {
268+
269+ if ( trimmedLine && ! trimmedLine . includes ( " REPOSITORY" ) ) {
256270 switch ( currentSection ) {
257- case ' containers' :
271+ case " containers" :
258272 containers . push ( trimmedLine ) ;
259273 break ;
260- case ' images' :
274+ case " images" :
261275 images . push ( trimmedLine ) ;
262276 break ;
263- case ' dangling' :
277+ case " dangling" :
264278 dangling . push ( trimmedLine ) ;
265279 break ;
266- case ' size' :
267- if ( trimmedLine . includes ( ' Images' ) ) {
280+ case " size" :
281+ if ( trimmedLine . includes ( " Images" ) ) {
268282 const sizeMatch = trimmedLine . match ( / ( \d + \. ? \d * [ G M K ] ? B ) / ) ;
269283 if ( sizeMatch ) {
270284 size = sizeMatch [ 1 ] ;
@@ -274,11 +288,11 @@ class Docker {
274288 }
275289 }
276290 }
277-
291+
278292 let running = 0 ;
279293 let stopped = 0 ;
280294 for ( const container of containers ) {
281- if ( container . includes ( 'Up' ) ) {
295+ if ( container . includes ( "Up" ) ) {
282296 running ++ ;
283297 } else {
284298 stopped ++ ;
@@ -289,22 +303,20 @@ class Docker {
289303 containers : {
290304 running,
291305 stopped,
292- total : running + stopped
306+ total : running + stopped ,
293307 } ,
294308 images : {
295309 local : images . length ,
296310 size,
297- dangling : dangling . length
298- }
311+ dangling : dangling . length ,
312+ } ,
299313 } ;
300314 } catch ( error ) {
301315 console . error ( "Error retrieving Docker data:" , error ) ;
302316 return {
303317 containers : { running : 0 , stopped : 0 , total : 0 } ,
304- images : { local : 0 , size : "0B" , dangling : 0 }
318+ images : { local : 0 , size : "0B" , dangling : 0 } ,
305319 } ;
306320 }
307321 }
308322}
309-
310- export type { ConfigServer , Docker } ;
0 commit comments