|
|
const fs = require('fs'); |
|
|
const path = require('path'); |
|
|
|
|
|
const usageFile = path.join(__dirname, '../usage.json'); |
|
|
|
|
|
|
|
|
if (!fs.existsSync(usageFile)) { |
|
|
fs.writeFileSync(usageFile, JSON.stringify({ |
|
|
initialized: new Date().toISOString(), |
|
|
endpoints: { |
|
|
'/download': 0, |
|
|
'/usage': 0, |
|
|
'/': 0 |
|
|
} |
|
|
}, null, 2)); |
|
|
} |
|
|
|
|
|
function trackUsage(endpoint) { |
|
|
const usageData = JSON.parse(fs.readFileSync(usageFile)); |
|
|
usageData.endpoints[endpoint] = (usageData.endpoints[endpoint] || 0) + 1; |
|
|
fs.writeFileSync(usageFile, JSON.stringify(usageData, null, 2)); |
|
|
} |
|
|
|
|
|
function getUsageStats() { |
|
|
return JSON.parse(fs.readFileSync(usageFile)); |
|
|
} |
|
|
|
|
|
module.exports = { trackUsage, getUsageStats }; |