1
- //@ts -nocheck
1
+ /* Not a fan of adding this, mainly doing it because
2
+ the types associated with the blessed packages
3
+ create some type errors
4
+ */
5
+ // @ts -nocheck
2
6
// @ts -ignore
3
7
import blessed from 'blessed'
4
8
// @ts -ignore
@@ -154,18 +158,18 @@ async function fetchThreatFeed(
154
158
, width : '100%'
155
159
, height : '100%'
156
160
, border : { type : "line" , fg : "cyan" }
157
- , columnSpacing : 10 //in chars
158
- , columnWidth : [ 20 , 20 , 20 , 20 , 20 ] /*in chars*/ } )
161
+ , columnSpacing : 5 //in chars
162
+ , columnWidth : [ 10 , 25 , 10 , 20 , 20 ] /*in chars*/ } )
159
163
160
- //allow control the table with the keyboard
164
+ // allow control the table with the keyboard
161
165
table . focus ( )
162
166
163
167
screen . append ( table )
164
-
168
+
165
169
const formattedOutput = formatResults ( data . results )
166
170
167
171
table . setData (
168
- { headers : [ 'Ecosystem' , 'Threat type ' , 'Name ' , 'Version ' , 'Detected at' ] , data : formattedOutput } )
172
+ { headers : [ 'Ecosystem' , 'Name ' , 'Version ' , 'Threat type ' , 'Detected at' ] , data : formattedOutput } )
169
173
170
174
screen . render ( )
171
175
@@ -177,11 +181,19 @@ const formatResults = (data: ThreatResult[]) => {
177
181
const ecosystem = d . purl . split ( 'pkg:' ) [ 1 ] . split ( '/' ) [ 0 ]
178
182
const name = d . purl . split ( '/' ) [ 1 ] . split ( '@' ) [ 0 ]
179
183
const version = d . purl . split ( '@' ) [ 1 ]
180
-
181
- return [ ecosystem , d . threatType , name , version , d . createdAt ]
184
+
185
+ const timeStart = new Date ( d . createdAt ) ;
186
+ const timeEnd = new Date ( )
187
+
188
+ const diff = getHourDiff ( timeStart , timeEnd )
189
+ const hourDiff = diff > 0 ? `${ diff } hours ago` : `${ getMinDiff ( timeStart , timeEnd ) } minutes ago`
190
+
191
+ return [ ecosystem , decodeURIComponent ( name ) , version , d . threatType , hourDiff ]
182
192
} )
183
193
}
184
194
185
- const formatQueryParams = ( params : any ) => {
186
- return Object . entries ( params ) . map ( entry => `${ entry [ 0 ] } =${ entry [ 1 ] } ` )
187
- }
195
+ const formatQueryParams = ( params : any ) => Object . entries ( params ) . map ( entry => `${ entry [ 0 ] } =${ entry [ 1 ] } ` )
196
+
197
+ const getHourDiff = ( start , end ) => Math . floor ( ( end - start ) / 3600000 )
198
+
199
+ const getMinDiff = ( start , end ) => Math . floor ( ( end - start ) / 60000 )
0 commit comments