Skip to content

Commit

Permalink
added count badge
Browse files Browse the repository at this point in the history
  • Loading branch information
Andcool-Systems committed Jul 31, 2024
1 parent eef3552 commit d49d3ba
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 31 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on:
push:
branches:
- main
paths-ignore:
- 'README.md'

jobs:
deploy:
Expand Down
25 changes: 0 additions & 25 deletions src/interfaces/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ interface Profile {
id: string;
name: string;
properties: Properties[];
profileActions: any[];
}

interface DefaultResponse {
Expand Down Expand Up @@ -75,30 +74,6 @@ interface SearchParams {
page: number
}


interface TexturesProfile {
SKIN: TextureProfile;
CAPE?: TextureProfile;
}

interface TextureProfile {
mojang: string | undefined;
eldraxis: string;
}

interface EldraxisCache {
available_in_search: boolean,
last_cached: number
}

interface ProfileResponse {
message: string,
timestamp: number,
uuid: string,
nickname: string,
textures: TexturesProfile,
}

interface SkinAndCape {
skin: {
data: string,
Expand Down
14 changes: 8 additions & 6 deletions src/minecraft/minecraft.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as sharp from 'sharp';
import { PrismaService } from "../prisma/prisma.service";
import { Injectable } from '@nestjs/common';
import { Buffer } from "buffer";
import { Prisma } from "@prisma/client";

@Injectable()
export class MinecraftService {
Expand Down Expand Up @@ -73,7 +74,7 @@ export class MinecraftService {
}


async resolveCollisions(prof: any[]) {
async resolveCollisions(prof: { uuid: string }[]) {
/* resolve nicknames collisions in data base */

for (const record of prof) {
Expand Down Expand Up @@ -110,10 +111,6 @@ export class MinecraftService {
if (!fetched_skin_data) {
return null;
}
const nicks = await this.prisma.minecraft.findMany({ where: { default_nick: fetched_skin_data?.name } });
if (nicks.length > 1) {
await this.resolveCollisions(nicks);
}

if (cache && cache?.default_nick !== fetched_skin_data.name) {
await this.prisma.minecraft.update({
Expand All @@ -124,6 +121,12 @@ export class MinecraftService {
}
})
}

const nicks = await this.prisma.minecraft.findMany({ where: { nickname: fetched_skin_data?.name.toLowerCase() } });
if (nicks.length > 1) {
await this.resolveCollisions(nicks);
}

const textures = atob(fetched_skin_data.properties[0].value);
const json_textures = JSON.parse(textures) as EncodedResponse;
const skin_response = await axios.get(json_textures.textures.SKIN.url, {
Expand Down Expand Up @@ -315,6 +318,5 @@ export class MinecraftService {
message: "Success",
message_ru: "Аккаунт успешно отключен!",
}

}
}
4 changes: 4 additions & 0 deletions src/workshop/bandage.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ export class BandageService {
private notifications: NotificationService
) { }

async getBandagesCount() {
return await this.prisma.bandage.count();
}

async getBandages(sessionId: string,
take: number,
page: number,
Expand Down
11 changes: 11 additions & 0 deletions src/workshop/workshop.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,15 @@ export class WorkshopController {
const user_agent = request.headers['user-agent'] as string;
res.status(200).send(await this.bandageService.getCategories(query.for_edit === "true", request.cookies.sessionId, user_agent));
}

@Get('/workshop/count/badge')
async getCount(@Res() res: Response) {
const count = await this.bandageService.getBandagesCount();
res.status(200).send({
"schemaVersion": 1,
"label": 'Bandages Count',
"message": count,
"color": 'green'
});
}
}

0 comments on commit d49d3ba

Please sign in to comment.