Initial commit: Tapalka monorepo (bot, front, strapi)

This commit is contained in:
2026-05-21 11:54:44 +07:00
commit 9ec9485940
208 changed files with 58314 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
import { IPlayer } from '@/interfaces/player.type';
export function CalculateReferralsCount(player: IPlayer | null): number {
if (!player) {
return 0;
}
let total = player.attributes.my_referrals.data?.length || 0;
player.attributes.my_referrals?.data?.forEach(referral => {
total += referral.attributes?.my_referrals.data?.length || 0;
});
return total;
}

View File

@@ -0,0 +1,14 @@
export function FormatNumber(num: number): string {
return Array.from(String(num))
.reverse()
.map((a, i) => {
if (i % 3 == 0 && i > 0) return a + '.';
return a;
})
.reverse()
.join('');
}
export const toFixed = (value: string | number | undefined, decimals: number = 4) => {
return Number(Number(value).toFixed(decimals));
};

View File

@@ -0,0 +1,16 @@
export const FormatTime = (time: number | null) => {
if (!time) {
return null;
} else {
const hours = Math.floor(time / (1000 * 60 * 60))
.toString()
.padStart(2, '0');
const minutes = Math.floor((time % (1000 * 60 * 60)) / (1000 * 60))
.toString()
.padStart(2, '0');
const seconds = Math.floor((time % (1000 * 60)) / 1000)
.toString()
.padStart(2, '0');
return `${hours}:${minutes}:${seconds}`;
}
};

View File

@@ -0,0 +1,38 @@
import axios, { AxiosInstance } from 'axios';
const backend_url = process.env.NEXT_PUBLIC_STRAPI_URL;
export class HttpInstanceFactory {
private static baseInstance: AxiosInstance | null = null;
private static authorizedInstance: AxiosInstance | null = null;
public static getBaseInstance(): AxiosInstance {
if (this.baseInstance) return this.baseInstance;
this.baseInstance = axios.create({
baseURL: backend_url,
headers: {
'Content-Type': 'application/json',
'ngrok-skip-browser-warning': 'true',
},
});
return this.baseInstance;
}
public static getAuthorizedInstance(jwt?: string): AxiosInstance {
if (this.authorizedInstance) return this.authorizedInstance;
if (jwt) return this.updateAuthorizedInstance(jwt);
return this.getBaseInstance();
}
public static updateAuthorizedInstance(jwt: string) {
this.authorizedInstance = axios.create({
baseURL: backend_url,
headers: {
'Content-Type': 'application/json',
'ngrok-skip-browser-warning': 'true',
Authorization: `Bearer ${jwt}`,
},
});
return this.authorizedInstance;
}
}

View File

@@ -0,0 +1,17 @@
function declension(num: number, words: string[]): string {
const cases = [2, 0, 1, 1, 1, 2];
return words[num % 100 > 4 && num % 100 < 20 ? 2 : cases[num % 10 < 5 ? num % 10 : 5]];
}
export function updateFriendAndReferralCounts(
referralsLength: number,
referralsCount: number,
): { friendsWord: string; referralWord: string } {
const friendWord = declension(referralsLength, ['Друг', 'Друга', 'Друзей']);
const referralWord = declension(referralsCount, ['Реферал', 'Реферала', 'Рефералов']);
return {
friendsWord: `${referralsLength} ${friendWord}`,
referralWord: `${referralsCount} ${referralWord}`,
};
}