2026-04-14 17:41:39 +02:00

42 lines
1.6 KiB
JavaScript

/**
* @param {string} key
* @param {Array} sentConsoleEntries
* @returns {string}
*/
app.use("/downloadConsoleLogs.lvorex", express.json())
app.post("/downloadConsoleLogs.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, "LiveConsole", 0)
if (!PermissionCheck) return res.json({ code: 401, message: "Your rank is not enough." })
const sentConsoleEntries = postBody.sentConsoleEntries
const consoleText = sentConsoleEntries.join("\n")
const DateNow = Date.now()
await fs.appendFile(path.join(rootDir, `Web/Panel/LiveConsole/logs/${DateNow}.txt`), `${consoleText}`, "utf8")
res.json({ code: 200, message: `${DateNow}` })
})
/**
* @param {string} key
* @param {string} logId
* @returns {string}
*/
app.use("/unlinkConsoleLog.lvorex", express.json())
app.post("/unlinkConsoleLog.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, "LiveConsole", 0)
if (!PermissionCheck) return res.json({ code: 401, message: "Your rank is not enough." })
const logId = postBody.logId
await fs.unlink(path.join(rootDir, `Web/Panel/LiveConsole/logs/${logId}.txt`))
res.json({ code: 200, message: "Unlinked." })
})