diff --git a/repositories/userRepository.js b/repositories/userRepository.js index 43378af..7dd50c2 100644 --- a/repositories/userRepository.js +++ b/repositories/userRepository.js @@ -3,6 +3,36 @@ const crypto = require("node:crypto") const database = require("../modules/database") const { DefaultError } = require("../errors/errors") +async function getSkins(uuid) { + try { + const sql = ` + SELECT t.hash, t.url, ps.variant, ps.active + FROM playerSkins ps + JOIN textures t ON ps.skinHash = t.hash + WHERE ps.playerUuid = ? + ` + const rows = await database.query(sql, [uuid]) + return rows + } catch (error) { + return utils.handleDBError(error) + } +} + +async function getCapes(uuid) { + try { + const sql = ` + SELECT t.hash, t.url, t.alias, pc.active + FROM playerCapes pc + JOIN textures t ON pc.capeHash = t.hash + WHERE pc.playerUuid = ? + ` + const rows = await database.query(sql, [uuid]) + return rows + } catch (error) { + return utils.handleDBError(error) + } +} + async function addPropertyToPlayer(key, value, uuid) { try { const sql = ` @@ -704,6 +734,8 @@ async function deleteTexture(hash) { module.exports = { setSkin, banUser, + getSkins, + getCapes, showCape, hideCape, resetSkin, diff --git a/services/userService.js b/services/userService.js index 7b31ca6..97acaf6 100644 --- a/services/userService.js +++ b/services/userService.js @@ -13,6 +13,46 @@ const generateKeyPairAsync = util.promisify(crypto.generateKeyPair) const TEMP_DIR = path.join(process.cwd(), "data", "temp") const TEXTURES_DIR = path.join(process.cwd(), "data", "textures") +async function getSkins(uuid) { + try { + const rawSkins = await userRepository.getSkins(uuid) + + return { + code: 200, + data: { + skins: rawSkins.map(r => ({ + id: r.hash, + state: r.active === 1 ? "ACTIVE" : "INACTIVE", + url: r.url, + variant: r.variant || "CLASSIC" + })) + } + } + } catch (error) { + throw error + } +} + +async function getCapes(uuid) { + try { + const rawCapes = await userRepository.getCapes(uuid) + + return { + code: 200, + data: { + capes: rawCapes.map(r => ({ + id: r.hash, + state: r.active === 1 ? "ACTIVE" : "INACTIVE", + url: r.url, + alias: r.alias || "LentiaCustomCape" + })) + } + } + } catch (error) { + throw error + } +} + async function getPlayerProperties(uuid) { try { const result = await userRepository.getPlayerProperties(uuid) @@ -529,8 +569,10 @@ async function removeCape(uuid, hash) { module.exports = { banUser, + getCapes, showCape, hideCape, + getSkins, unbanUser, resetSkin, isBlocked,