69 lines
2.5 KiB
JavaScript
69 lines
2.5 KiB
JavaScript
/**
|
|
* @param {string} key
|
|
* @returns {Array}
|
|
*/
|
|
|
|
app.use("/getAllSharedItems.lvorex", express.json())
|
|
app.post("/getAllSharedItems.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, "Items", 0)
|
|
if (!PermissionCheck) return res.json({ code: 401, message: "Your rank is not enough." })
|
|
|
|
const InspectItemPermissionCheck = await checkPermission(userKey.rank, "Items", 1)
|
|
|
|
const toInsertItems = []
|
|
const SharedItems = await LV.GetAllItems()
|
|
const CraftableItems = []
|
|
|
|
Object.entries(SharedItems).forEach(([key, value]) => {
|
|
const v = SharedItems[key]
|
|
if (v.requiredItems) {
|
|
CraftableItems.push({
|
|
code: v.name,
|
|
requiredItems: v.requiredItems,
|
|
secondsforcraft: v.secondsforcraft
|
|
})
|
|
}
|
|
})
|
|
|
|
SharedItems.forEach(item => {
|
|
let craftable = false
|
|
if (CraftableItems.some(i => i.code === item.name)) {
|
|
const craftableItem = CraftableItems.find(w => w.code === item.name)
|
|
craftable = {
|
|
requiredItems: craftableItem.requiredItems,
|
|
secondsforcraft: craftableItem.secondsforcraft
|
|
}
|
|
}
|
|
if (InspectItemPermissionCheck) {
|
|
toInsertItems.push({
|
|
label: item.label,
|
|
code: item.name,
|
|
desc: item.description ?? item.label,
|
|
icon: item.image,
|
|
useable: item.useable,
|
|
type: item.weapon === true ? 'weapon' : craftable ? 'craftable' : 'item',
|
|
weight: item.weight,
|
|
unique: item.unique,
|
|
craftable: craftable,
|
|
closeafterusage: item.close,
|
|
ammotype: item.weapon === true ? item.ammoname : 'None'
|
|
})
|
|
} else {
|
|
toInsertItems.push({
|
|
label: item.label,
|
|
code: item.name,
|
|
desc: item.description ?? item.label,
|
|
icon: item.image,
|
|
useable: item.useable,
|
|
type: item.weapon === true ? 'weapon' : craftable ? 'craftable' : 'item',
|
|
weight: item.weight,
|
|
unique: item.unique,
|
|
})
|
|
}
|
|
})
|
|
res.json({ code: 200, message: toInsertItems })
|
|
}) |