58 lines
2.0 KiB
JavaScript
58 lines
2.0 KiB
JavaScript
/**
|
|
* @param {string} key
|
|
* @returns {Array}
|
|
*/
|
|
|
|
app.use("/getAllResources.lvorex", express.json())
|
|
app.post("/getAllResources.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, "Resources", 0)
|
|
if (!PermissionCheck) return res.json({ code: 401, message: "Your rank is not enough." })
|
|
|
|
const toInsertResources = []
|
|
for (let i = 0; i < GetNumResources(); i++) {
|
|
const resource = GetResourceByFindIndex(i)
|
|
toInsertResources.push({
|
|
name: resource,
|
|
status: GetResourceState(resource) === 'started' ? 'start' : 'stop'
|
|
})
|
|
}
|
|
|
|
res.json({ code: 200, message: toInsertResources })
|
|
})
|
|
|
|
/**
|
|
* @param {string} key
|
|
* @param {string} action
|
|
* @param {string} resource
|
|
* @returns {string}
|
|
*/
|
|
|
|
app.use("/toggleResourceState.lvorex", express.json())
|
|
app.post("/toggleResourceState.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, "Resources", 1)
|
|
if (!PermissionCheck) return res.json({ code: 401, message: "Your rank is not enough." })
|
|
let result = undefined
|
|
|
|
if (postBody.action === "start") {
|
|
result = StartResource(postBody.resource)
|
|
} else if (postBody.action === "stop") {
|
|
result = StopResource(postBody.resource)
|
|
} else if (postBody.action === "restart") {
|
|
result = StopResource(postBody.resource)
|
|
result = StartResource(postBody.resource)
|
|
}
|
|
|
|
if (result) {
|
|
res.json({ code: 200, message: "Completed." })
|
|
} else {
|
|
res.json({ code: 404, message: "Script cant touch anything in resources. Please read documents." })
|
|
}
|
|
}) |