From 48ea9f708ba74268ed00343806d9e9ffe439963e Mon Sep 17 00:00:00 2001 From: azures04 Date: Fri, 23 Jan 2026 22:52:00 +0100 Subject: [PATCH] Expand skin upload schema and simplify texture storage Updated the skin upload schema to accept both JSON and multipart/form-data content types, and to allow requests without a URL. Simplified the texture storage path in userService.js by removing subdirectory partitioning based on hash. --- .../minecraft/profile/skins.js | 27 ++++++++++++------- services/userService.js | 3 +-- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/schemas/minecraftservices/minecraft/profile/skins.js b/schemas/minecraftservices/minecraft/profile/skins.js index 9ed9d94..5554810 100644 --- a/schemas/minecraftservices/minecraft/profile/skins.js +++ b/schemas/minecraftservices/minecraft/profile/skins.js @@ -4,20 +4,29 @@ module.exports = { POST: { headers: z.object({ "content-type": z.string() - .regex(/application\/json/i, { message: "Content-Type must be application/json" }), + .regex(/application\/json|multipart\/form-data/i, { + message: "Content-Type must be application/json or multipart/form-data" + }), "authorization": z.string().min(1, { message: "Authorization header is required." }) }), - body: z.object({ - variant: z.enum(["classic", "slim"], { - errorMap: () => ({ message: "Variant must be 'classic' or 'slim'." }) + body: z.union([ + z.object({ + variant: z.enum(["classic", "slim"], { + errorMap: () => ({ message: "Variant must be 'classic' or 'slim'." }) + }), + url: z.string() + .url({ message: "Invalid URL format." }) + .max(2048, { message: "URL is too long." }) }), - url: z.string() - .url({ message: "Invalid URL format." }) - .max(2048, { message: "URL is too long." }) - }), + z.object({ + variant: z.enum(["classic", "slim"], { + errorMap: () => ({ message: "Variant must be 'classic' or 'slim'." }) + }), + }) + ]), error: { code: 400, - message: "Invalid skin URL or variant.", + message: "Invalid skin data, URL or variant.", error: "IllegalArgumentException" } } diff --git a/services/userService.js b/services/userService.js index ec66a82..24727bf 100644 --- a/services/userService.js +++ b/services/userService.js @@ -492,8 +492,7 @@ async function uploadSkin(uuid, fileObject, variant) { const existingTexture = await userRepository.getTextureByHash(hash) if (!existingTexture) { - const subDir = hash.substring(0, 2) - const targetDir = path.join(TEXTURES_DIR, subDir) + const targetDir = path.join(TEXTURES_DIR) const targetPath = path.join(targetDir, hash) await fs.mkdir(targetDir, { recursive: true })