mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-28 20:42:37 +00:00
246d62b578
[access-token-encryptor] nicer log message for zero access token found GitOrigin-RevId: 2a28fdc71a1e063f091f55bc247d9dd26bbd0ee3
27 lines
774 B
JavaScript
27 lines
774 B
JavaScript
function formatTokenUsageStats(STATS) {
|
|
const prettyStats = []
|
|
const sortedStats = Object.entries(STATS).sort((a, b) =>
|
|
a[0] > b[0] ? 1 : -1
|
|
)
|
|
const totalByName = {}
|
|
for (const [key, n] of sortedStats) {
|
|
const [name, version, collectionName, path, label] = key.split(':')
|
|
totalByName[name] = (totalByName[name] || 0) + n
|
|
prettyStats.push({ name, version, collectionName, path, label, n })
|
|
}
|
|
for (const row of prettyStats) {
|
|
row.percentage = ((100 * row.n) / totalByName[row.name])
|
|
.toFixed(2)
|
|
.padStart(6)
|
|
}
|
|
|
|
if (prettyStats.length === 0) {
|
|
console.warn('---')
|
|
console.warn('Found 0 access tokens.')
|
|
console.warn('---')
|
|
} else {
|
|
console.table(prettyStats)
|
|
}
|
|
}
|
|
|
|
module.exports = { formatTokenUsageStats }
|