diff --git a/index.js b/index.js index 67c5676..7333f4e 100644 --- a/index.js +++ b/index.js @@ -8,7 +8,7 @@ $$$$$$$$ |$$ \ $$ | __ $$ | $$/ $$ | $$ |$$ | __ $$ | $$ |$$ | $$ | $$ | $$ | $$$$$$ | $$ |/ |$$ | $$ \__$$ |$$ \__/ |$$ \__$$ |$$ | $$ | $$ | $$ | $$ |/ $$/ $$ $$/ $$ | $$ $$/ $$ $$/ $$ $$/ $$ | $$ | $$ | $$/ $$/ $$$$$$$/ $$$$/ $$/ $$$$$$/ $$$$$$/ $$$$$$/ $$/ $$/ $$/ - + Made with <3 by Chris Chrome and the rest of the AstroCom team */ @@ -127,7 +127,7 @@ const dailyAnalytic = (tag) => { // This is a bit more complex, but it's just a }); } -app.use((req,res,next) => { +app.use((req, res, next) => { if (req.path.startsWith("/api/v1")) { addAnalytic("apiCalls"); }; @@ -542,7 +542,7 @@ app.get("/api/v1/directory", (req, res) => { }); // Other public endpoints that need special handling -discordInviteCache = {time: 0, url: ""}; +discordInviteCache = { time: 0, url: "" }; app.get("/discord", (req, res) => { // fetch from process.env.WIDGET_URL, get json body, redirect to body.instant_invite. Cache url for 5 minutes @@ -577,14 +577,14 @@ app.get("/analytics", (req, res) => { return; } // Find the latest date and add "current:true" to it - var latest = {tag_date: "1970-01-01", count: 0}; + var latest = { tag_date: "1970-01-01", count: 0 }; daily.forEach((entry) => { if (entry.tag_date > latest.tag_date) { latest = entry; } }); latest.current = true; - res.json({total, daily}); + res.json({ total, daily }); }); }); }); @@ -622,6 +622,14 @@ app.get("/api/healthcheck", (req, res) => { }); }); +// logCall function (caller, callee) +const logCall = (caller, callee) => { + db.run('INSERT INTO callLogs (caller, callee, timestamp) VALUES (?, ?, ?)', + [caller, callee, Math.floor(Date.now() / 1000)], + (err) => { + if (err) console.error('Error logging call:', err); + }); +} // Query to get a route app.get('/api/v1/route/:apiKey/:ani/:number', (req, res) => { @@ -643,6 +651,7 @@ app.get('/api/v1/route/:apiKey/:ani/:number', (req, res) => { // Check if the ANI is within the block range // If it is, return `local` console.log(`New Call: ${ani} -> ${number}`); + logCall(ani, number); // incriment estCallsMade analytics addAnalytic("estCallsMade"); dailyAnalytic("dailyCallsMade"); @@ -677,6 +686,7 @@ app.get('/api/v1', (req, res) => { // Backwards compatibility with TandmX cause // Check if the ANI is within the block range // If it is, return `local` console.log(`New Call: ${ani} -> ${number}`); + logCall(ani, number); addAnalytic("estCallsMade"); dailyAnalytic("dailyCallsMade"); if (ani >= row.block_start && ani <= row.block_start + row.block_length) { diff --git a/migrations/006_gen_callLogs_table.sql b/migrations/006_gen_callLogs_table.sql new file mode 100644 index 0000000..7855c54 --- /dev/null +++ b/migrations/006_gen_callLogs_table.sql @@ -0,0 +1,6 @@ +CREATE TABLE callLogs ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + timestamp TEXT NOT NULL, + caller TEXT NOT NULL, + callee TEXT NOT NULL +); \ No newline at end of file