-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.js
More file actions
38 lines (34 loc) · 845 Bytes
/
function.js
File metadata and controls
38 lines (34 loc) · 845 Bytes
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
29
30
31
32
33
34
35
36
37
38
const { writeFileSync, readFileSync } = require('fs')
/**
* @param {string} file
* @returns {object}
*/
function getLogs(file) {
const data = readFileSync(`./logs/${file}`, "utf8")
return JSON.parse(data)
}
/**
* @param {object} data
* @param {string} data.username
* @param {string} data.sessionid
* @param {string} data.origin
* @returns {boolean}
*/
function sendLogsLogin(data) {
const file = "registre_login.json"
const filePath = `./logs/${file}`
const timestamp = Date.now()
const dataFiles = getLogs(file)
dataFiles[data.username] = { ...data, timestamp }
const jsonData = JSON.stringify(dataFiles, null, 2)
try {
writeFileSync(filePath, jsonData, "utf8")
return true
} catch (error) {
return false
}
}
module.exports = {
sendLogsLogin,
getLogs
}