Refactor texture handling and update route structure

Moved sessionserver routes to correct directory and removed subdirectory logic from texture file lookup. Updated texture URLs to remove leading slashes and fixed endpoint concatenation. Added default textures for Alex and Steve.
This commit is contained in:
Gilles Lazures 2025-12-28 22:22:54 +01:00
parent a3eb5ee70c
commit e8f58e63cd
10 changed files with 6 additions and 11 deletions

BIN
data/textures/alex.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

BIN
data/textures/steve.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -9,12 +9,7 @@ const TEXTURES_DIR = path.join(process.cwd(), "data", "textures")
router.get("/", async (req, res, next) => {
try {
const hash = req.params.hash
if (!/^[a-f0-9]{64}$/i.test(hash)) {
throw new DefaultError(404, "Texture not found")
}
const subDir = hash.substring(0, 2)
const filePath = path.join(TEXTURES_DIR, subDir, hash)
const filePath = path.join(TEXTURES_DIR, hash)
if (!fs.existsSync(filePath)) {
throw new DefaultError(404, "Texture not found")
}

View File

@ -56,7 +56,7 @@ async function authenticate({ identifier, password, clientToken, requireUser })
delete userResult.user.password
const $clientToken = uuidRegex.test(clientToken) ? clientToken : crypto.randomUUID()
const $clientToken = clientToken || crypto.randomUUID()
const accessToken = jwt.sign({
uuid: userResult.user.uuid,
username: userResult.user.username,
@ -120,7 +120,7 @@ async function refreshToken({ previousAccessToken, clientToken, requireUser }) {
await authRepository.invalidateClientSession(previousAccessToken, clientToken)
const $clientToken = uuidRegex.test(clientToken) ? clientToken : crypto.randomUUID()
const $clientToken = clientToken || crypto.randomUUID()
const newAccessToken = jwt.sign({
uuid: userResult.user.uuid,
username: userResult.user.username,

View File

@ -73,12 +73,12 @@ async function getProfile({ uuid, unsigned = false }) {
const hasValidCape = !!activeCape
const skinNode = hasValidSkin ? {
url: (process.env.TEXTURES_ENDPOINTS || `http://localhost:${process.env.WEB_PORT}/textures/`) + activeSkin.url,
url: (process.env.TEXTURES_ENDPOINTS || `http://localhost:${process.env.WEB_PORT}/textures`) + activeSkin.url,
metadata: activeSkin.variant === "SLIM" ? { model: "slim" } : undefined
} : undefined
const capeNode = hasValidCape ? {
url: (process.env.TEXTURES_ENDPOINTS || `http://localhost:${process.env.WEB_PORT}/textures/`) + activeCape.url
url: (process.env.TEXTURES_ENDPOINTS || `http://localhost:${process.env.WEB_PORT}/textures`) + activeCape.url
} : undefined
const texturesObject = {

View File

@ -459,7 +459,7 @@ async function uploadSkin(uuid, fileObject, variant) {
await fs.writeFile(targetPath, buffer)
const newTextureUuid = crypto.randomUUID()
const textureUrl = `/texture/${hash}`
const textureUrl = `texture/${hash}`
await userRepository.createTexture(newTextureUuid, hash, 'SKIN', textureUrl, null)
}