diff --git a/src/interfaces/interfaces.ts b/src/interfaces/interfaces.ts index 70398a3..8c8c7b0 100644 --- a/src/interfaces/interfaces.ts +++ b/src/interfaces/interfaces.ts @@ -1,31 +1,28 @@ -interface Textures { - SKIN: { - url: string; - metadata?: { - model: string; - } - }; - CAPE?: { - url: string; - }; -} - interface EncodedResponse { timestamp: number, profileId: string, profileName: string, - textures: Textures + textures: { + SKIN?: { + url: string; + metadata?: { + model: string; + } + }; + CAPE?: { + url: string; + }; + } } -interface Properties { - name: string; - value: string; -} interface Profile { id: string; name: string; - properties: Properties[]; + properties: { + name: string; + value: string; + }[]; } interface SearchUnit { @@ -40,17 +37,6 @@ interface SearchParams { page: number } -interface SkinAndCape { - skin: { - data: string, - slim: boolean - }, - cape: string -} - -interface CapeResponse { - data: SkinAndCape -} interface Notifications { id?: number, diff --git a/src/minecraft/minecraft.service.ts b/src/minecraft/minecraft.service.ts index 524ee8b..29bd198 100644 --- a/src/minecraft/minecraft.service.ts +++ b/src/minecraft/minecraft.service.ts @@ -6,7 +6,6 @@ import { Buffer } from "buffer"; import { Session } from "src/auth/auth.service"; import { LocaleException } from "src/interceptors/localization.interceptor"; import responses from "src/localization/minecraft.localization"; -import { Cron } from "@nestjs/schedule"; @Injectable() export class MinecraftService { @@ -133,12 +132,19 @@ export class MinecraftService { const textures = Buffer.from(fetched_skin_data.properties[0].value, 'base64').toString(); const json_textures = JSON.parse(textures) as EncodedResponse; - const skin_response = await axios.get(json_textures.textures.SKIN.url, { responseType: 'arraybuffer', validateStatus: () => true }); - if (skin_response.status !== 200) { - throw new LocaleException(responses.PROFILE_NOT_FOUND, 404); + let skin_buff: Buffer | null = null; + if (json_textures.textures.SKIN) { + const skin_response = await axios.get(json_textures.textures.SKIN.url, { responseType: 'arraybuffer', validateStatus: () => true }); + + if (skin_response.status !== 200) { + throw new LocaleException(responses.PROFILE_NOT_FOUND, 404); + } + skin_buff = Buffer.from(skin_response.data, 'binary'); + } else { + skin_buff = await sharp('./src/minecraft/steve.png').toBuffer(); } - const skin_buff = Buffer.from(skin_response.data, 'binary'); + const head = await this.generateHead(skin_buff); let cape_b64 = ''; @@ -158,7 +164,7 @@ export class MinecraftService { data: skin_buff.toString('base64'), data_cape: cape_b64, data_head: head.toString('base64'), - slim: json_textures.textures.SKIN.metadata?.model === 'slim' + slim: json_textures.textures.SKIN?.metadata?.model === 'slim' }, update: { nickname: fetched_skin_data.name.toLowerCase(), @@ -167,7 +173,7 @@ export class MinecraftService { data: skin_buff.toString('base64'), data_cape: cape_b64, data_head: head.toString('base64'), - slim: json_textures.textures.SKIN.metadata?.model === 'slim' + slim: json_textures.textures.SKIN?.metadata?.model === 'slim' } }); return updated_data; diff --git a/src/minecraft/steve.png b/src/minecraft/steve.png new file mode 100644 index 0000000..31770d6 Binary files /dev/null and b/src/minecraft/steve.png differ