Skip to content

Commit

Permalink
added default skin to cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Andcool-Systems committed Jan 1, 2025
1 parent fcf0a23 commit ad96ed3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 36 deletions.
44 changes: 15 additions & 29 deletions src/interfaces/interfaces.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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,
Expand Down
20 changes: 13 additions & 7 deletions src/minecraft/minecraft.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 = '';
Expand All @@ -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(),
Expand All @@ -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;
Expand Down
Binary file added src/minecraft/steve.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ad96ed3

Please sign in to comment.