67 lines
2.8 KiB
JavaScript
67 lines
2.8 KiB
JavaScript
/**
|
|
* @param {string} key
|
|
* @returns {Array}
|
|
*/
|
|
|
|
app.use("/getAllLogs.lvorex", express.json())
|
|
app.post("/getAllLogs.lvorex", async (req, res) => {
|
|
const postBody = req.body
|
|
const { keyFound, userKey } = await controlKey(req, postBody.key)
|
|
|
|
if (keyFound === false) return res.json({ code: 404, message: "Not authorized." })
|
|
const PermissionCheck = await checkPermission(userKey.rank, "Logs", 0)
|
|
if (!PermissionCheck) return res.json({ code: 401, message: "Your rank is not enough." })
|
|
|
|
let result = await query(`
|
|
select * from \`madmin_logs\`
|
|
`)
|
|
if (result === false) return res.json({ code: 404, message: "SQL Error Appeared." })
|
|
const toInsertLogs = []
|
|
for await (const log of result) {
|
|
let expectedPlayer = null
|
|
if (log.player_uid !== "None") {
|
|
let playerResult = await query(`
|
|
select * from \`${config.Framework.includes("qb") ? 'players' : 'users'}\`
|
|
where \`${config.Framework.includes("qb") ? 'citizenid' : 'identifier'}\` = '${log.player_uid}'
|
|
`)
|
|
if (playerResult === false) return res.json({ code: 404, message: "SQL Error Appeared." })
|
|
if (playerResult.length !== 0) {
|
|
if (config.Framework.includes("qb")) {
|
|
expectedPlayer = playerResult[0]
|
|
} else {
|
|
expectedPlayer = { name: `${playerResult[0].firstname} ${playerResult[0].lastname}` }
|
|
}
|
|
} else {
|
|
expectedPlayer = {name: "Character Deleted."}
|
|
}
|
|
}
|
|
if (log.type === "ban") {
|
|
toInsertLogs.push({
|
|
type: log.type,
|
|
message: `[${log.date}] ${log.author} banned ${expectedPlayer.name}. Reason: ${log.message}`
|
|
})
|
|
} else if (log.type === "adminjail") {
|
|
toInsertLogs.push({
|
|
type: log.type,
|
|
message: `[${log.date}] ${log.author} jailed ${expectedPlayer.name}. Reason: ${log.message}`
|
|
})
|
|
} else if (log.type === "warn") {
|
|
toInsertLogs.push({
|
|
type: log.type,
|
|
message: `[${log.date}] ${log.author} warned ${expectedPlayer.name}. Reason: ${log.message}`
|
|
})
|
|
} else if (log.type === "status" || log.type === "money") {
|
|
toInsertLogs.push({
|
|
type: log.type,
|
|
message: `[${log.date}] ${log.author} ${log.message} Player: ${expectedPlayer.name}`
|
|
})
|
|
} else {
|
|
toInsertLogs.push({
|
|
type: log.type,
|
|
message: `[${log.date}] ${log.author} ${log.message}`
|
|
})
|
|
}
|
|
}
|
|
|
|
res.json({ code: 200, message: toInsertLogs })
|
|
}) |