File size: 785 Bytes
7fec1da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const fs = require('fs');
const path = require('path');

const usageFile = path.join(__dirname, '../usage.json');

// Initialize with author info if not exists
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 };