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.
This commit is contained in:
Gilles Lazures 2026-01-23 22:52:00 +01:00
parent 3f64c2c897
commit 48ea9f708b
2 changed files with 19 additions and 11 deletions

View File

@ -4,20 +4,29 @@ module.exports = {
POST: { POST: {
headers: z.object({ headers: z.object({
"content-type": z.string() "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." }) "authorization": z.string().min(1, { message: "Authorization header is required." })
}), }),
body: z.object({ body: z.union([
variant: z.enum(["classic", "slim"], { z.object({
errorMap: () => ({ message: "Variant must be 'classic' or 'slim'." }) 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() z.object({
.url({ message: "Invalid URL format." }) variant: z.enum(["classic", "slim"], {
.max(2048, { message: "URL is too long." }) errorMap: () => ({ message: "Variant must be 'classic' or 'slim'." })
}), }),
})
]),
error: { error: {
code: 400, code: 400,
message: "Invalid skin URL or variant.", message: "Invalid skin data, URL or variant.",
error: "IllegalArgumentException" error: "IllegalArgumentException"
} }
} }

View File

@ -492,8 +492,7 @@ async function uploadSkin(uuid, fileObject, variant) {
const existingTexture = await userRepository.getTextureByHash(hash) const existingTexture = await userRepository.getTextureByHash(hash)
if (!existingTexture) { if (!existingTexture) {
const subDir = hash.substring(0, 2) const targetDir = path.join(TEXTURES_DIR)
const targetDir = path.join(TEXTURES_DIR, subDir)
const targetPath = path.join(targetDir, hash) const targetPath = path.join(targetDir, hash)
await fs.mkdir(targetDir, { recursive: true }) await fs.mkdir(targetDir, { recursive: true })