Skip to content

Commit 138c608

Browse files
committed
improve
1 parent 254dc95 commit 138c608

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

src/commands/threat-feed.ts

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
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
26
// @ts-ignore
37
import blessed from 'blessed'
48
// @ts-ignore
@@ -154,18 +158,18 @@ async function fetchThreatFeed(
154158
, width: '100%'
155159
, height: '100%'
156160
, 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*/ })
159163

160-
//allow control the table with the keyboard
164+
// allow control the table with the keyboard
161165
table.focus()
162166

163167
screen.append(table)
164-
168+
165169
const formattedOutput = formatResults(data.results)
166170

167171
table.setData(
168-
{ headers: ['Ecosystem', 'Threat type', 'Name', 'Version', 'Detected at'], data: formattedOutput})
172+
{ headers: ['Ecosystem', 'Name', 'Version', 'Threat type', 'Detected at'], data: formattedOutput})
169173

170174
screen.render()
171175

@@ -177,11 +181,19 @@ const formatResults = (data: ThreatResult[]) => {
177181
const ecosystem = d.purl.split('pkg:')[1].split('/')[0]
178182
const name = d.purl.split('/')[1].split('@')[0]
179183
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]
182192
})
183193
}
184194

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

Comments
 (0)