From d49b3011710296699169cbe6d6902a8996a51ff6 Mon Sep 17 00:00:00 2001 From: Ashu11-A Date: Mon, 4 Mar 2024 17:16:06 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20Pterodactyl=20Login?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 4 +- release.ts | 11 +++- rollup.config.ts | 9 ++-- src/classes/Pterodactyl.ts | 52 ++++++++++--------- src/crons/SystemStatus.ts | 2 +- .../components/account/functions/generate.ts | 2 +- .../payments/functions/updateCart.ts | 8 +-- src/interfaces/Payments.ts | 17 +++++- 8 files changed, 63 insertions(+), 42 deletions(-) diff --git a/package.json b/package.json index 9569814e..1bc90803 100644 --- a/package.json +++ b/package.json @@ -26,8 +26,8 @@ "build": "tsc && tscpaths -p tsconfig.json -s ./src -o ./dist", "build:test": "tsc --project ./tsconfig.json --declaration true -declarationDir dist/types && tsc-alias", "build:release": "npm run build && ts-node release.ts", - "lint": "eslint --ext .tsx,.ts --fix ./src -c .eslintrc.json", - "rollup": "npm run build:test && rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript --bundleConfigAsCjs" + "build:rollup": "npm run build:test && rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript --bundleConfigAsCjs", + "lint": "eslint --ext .tsx,.ts --fix ./src -c .eslintrc.json" }, "keywords": [ "Bot", diff --git a/release.ts b/release.ts index a886e6dc..fd41dad8 100644 --- a/release.ts +++ b/release.ts @@ -4,6 +4,7 @@ import path from 'path' import { minify } from 'terser' import { SingleBar, Presets } from 'cli-progress' import { exec } from '@yao-pkg/pkg' +import { } from 'rollup' async function carregarDados (options: { diretorio: string @@ -31,7 +32,9 @@ async function carregarDados (options: { async function compress (): Promise { const progressBar = new SingleBar({}, Presets.rect) const files = await carregarDados({ diretorio: 'dist' }) + progressBar.start(Object.entries(files).length, 0) + for (const [filePath, fileContent] of Object.entries(files)) { progressBar.increment(1) const newPath = path.dirname(filePath).replace('dist', 'build') @@ -47,13 +50,16 @@ async function compress (): Promise { }, ie8: false, keep_fnames: false, - mangle: true, + mangle: { + properties: true, + toplevel: true + }, module: true, toplevel: true, output: { ascii_only: true, beautify: false, - comments: false + comments: false, }, sourceMap: true }) @@ -69,6 +75,7 @@ async function compress (): Promise { writeFileSync(`${newPath}/${fileName}`, fileContent, 'utf8') } } + progressBar.stop() const args = ['.', '--no-bytecode', '--compress', 'Brotli', '--public-packages', '"*"', '--public'] diff --git a/rollup.config.ts b/rollup.config.ts index 919fdac9..a1caf33a 100644 --- a/rollup.config.ts +++ b/rollup.config.ts @@ -1,11 +1,10 @@ // import { type OutputOptions } from 'rollup' +import commonjs from '@rollup/plugin-commonjs' import json from '@rollup/plugin-json' -import terser from '@rollup/plugin-terser' -import nodePolyfills from 'rollup-plugin-polyfill-node' import multi from '@rollup/plugin-multi-entry' -import tsConfigPaths from 'rollup-plugin-tsconfig-paths' import nodeResolve from '@rollup/plugin-node-resolve' -import commonjs from '@rollup/plugin-commonjs' +import nodePolyfills from 'rollup-plugin-polyfill-node' +import tsConfigPaths from 'rollup-plugin-tsconfig-paths' export default { input: ['dist/**/*.js', 'dist/**/*.json'], @@ -42,7 +41,7 @@ export default { plugins: [ tsConfigPaths({ tsConfigPath: './tsconfig.build.json' }), nodeResolve({ preferBuiltins: false, extensions: ['.mjs', '.js', '.json', '.node'], browser: false, allowExportsFolderMapping: false }), - multi({ include: 'dist/lib', preserveModules: true }), + multi({ include: 'dist/lib', preserveModules: true, exclude: ['node_modules/**/*.node'] }), commonjs({ exclude: ['node_modules/**/*.node'] }), // terser({ // maxWorkers: 4, diff --git a/src/classes/Pterodactyl.ts b/src/classes/Pterodactyl.ts index 18edf7b6..c8ac0366 100644 --- a/src/classes/Pterodactyl.ts +++ b/src/classes/Pterodactyl.ts @@ -1,6 +1,6 @@ import { core, db } from '@/app' import { numerosParaLetras, updateProgressAndEstimation } from '@/functions' -import { type PaymentServerPtero, type PaymentUserPtero, type EggObject, type NestObject, type NodeConfigObject, type NodeObject, type Server, type UserObject } from '@/interfaces' +import { type PaymentServerPtero, type PaymentUserPtero, type EggObject, type NestObject, type NodeConfigObject, type NodeObject, type Server, type UserObject, PaymentMetadataPtero, UserPtero } from '@/interfaces' import axios, { type AxiosError, type AxiosInstance } from 'axios' export class Pterodactyl { @@ -223,7 +223,7 @@ export class Pterodactyl { }): Promise<{ status: boolean, userData: any[] | undefined }> { const { email, guildId } = options - let metadata = await db.ctrlPanel.table(`${numerosParaLetras(guildId)}_users`).get('metadata') + let metadata = await db.pterodactyl.table(`${numerosParaLetras(guildId)}_users`).get('metadata') if (metadata?.lastPage === undefined) { metadata = await this.updateDatabase({ guildId, type: 'users' }) @@ -238,7 +238,7 @@ export class Pterodactyl { }> { let status: { status: boolean, userData: any[] | undefined } = { status: false, userData: undefined } for (let page = 1; page <= metadata.lastPage; page++) { - const dataDB = await db.ctrlPanel.table(`${numerosParaLetras(guildId)}_users`).get(String(page)) + const dataDB = await db.pterodactyl.table(`${numerosParaLetras(guildId)}_users`).get(String(page)) if (Array.isArray(dataDB)) { foundUsers = dataDB.filter( @@ -276,7 +276,7 @@ export class Pterodactyl { undefined> { const { guildId, type } = options const { url, token } = this - const usersData: PaymentUserPtero[] = [] + const usersData: UserPtero[] = [] const serversData: PaymentServerPtero[] = [] const startTime = Date.now() let clientCount = 0 @@ -293,24 +293,26 @@ export class Pterodactyl { const data = response.data const users = data.data as PaymentUserPtero[] + const metadata = data.meta.pagination as PaymentMetadataPtero for (const user of users) { - const { id, name, email, root_admin } = user + const { id, username, email, root_admin } = user.attributes usersData.push({ id, - name, + name: username, email, root_admin }) - if (user.root_admin) { + if (root_admin) { teamCount++ } else { clientCount++ } } - if (data.current_page <= data.last_page) { - const dataBD = await db.ctrlPanel.table(`${numerosParaLetras(guildId)}_users`).get(String(data.current_page)) + if (metadata.current_page <= metadata.total_pages) { + const dataBD = await db.pterodactyl.table(`${numerosParaLetras(guildId)}_users`).get(String(metadata.current_page)) + console.log(usersData) if (dataBD?.length <= 50 || usersData?.length > 0) { let isDataChanged = false @@ -327,36 +329,36 @@ export class Pterodactyl { } } if (isDataChanged) { - core.info(`Tabela: ${data.current_page}/${data.last_page} | Mesclando`) - await db.ctrlPanel.table(`${numerosParaLetras(guildId)}_users`).set(`${data.current_page}`, usersData) + core.info(`Tabela: ${metadata.current_page}/${metadata.total_pages} | Mesclando`) + await db.pterodactyl.table(`${numerosParaLetras(guildId)}_users`).set(`${metadata.current_page}`, usersData) } else { - core.info(`Tabela: ${data.current_page}/${data.last_page} | Sincronizado`) + core.info(`Tabela: ${metadata.current_page}/${metadata.total_pages} | Sincronizado`) } - if (data.current_page % 2 === 0) { + if (metadata.current_page % 2 === 0) { const { progress, estimatedTimeRemaining } = updateProgressAndEstimation({ - totalTables: data.last_page, - currentTable: data.current_page, + totalTables: metadata.total_pages, + currentTable: metadata.current_page, startTime }) - core.log(`Tabelas: ${data.current_page}/${data.last_page}`, `Users: ${data.from} - ${data.to} / ${data.total}`, `${progress.toFixed(2)}% | Tempo Restante: ${estimatedTimeRemaining.toFixed(2)}s`) + core.log(`Tabelas: ${metadata.current_page}/${metadata.total_pages}`, `Users: ${metadata.total} - ${metadata.per_page * metadata.current_page} / ${metadata.total}`, `${progress.toFixed(2)}% | Tempo Restante: ${estimatedTimeRemaining.toFixed(2)}s`) } } - if (data.current_page === data.last_page) { - const { last_page: lastPage, per_page: perPage, total } = data - const metadata = { + if (metadata.current_page === metadata.total_pages) { + const { total_pages: lastPage, per_page: perPage, total } = metadata + const metadataData = { lastPage, perPage, total, clientCount, teamCount } - await db.ctrlPanel.table(`${numerosParaLetras(guildId)}_users`).set('metadata', metadata) - return metadata + await db.ctrlPanel.table(`${numerosParaLetras(guildId)}_users`).set('metadata', metadataData) + return metadataData } else if (data.next_page_url !== null) { usersData.length = 0 - return await fetchUsers(data.next_page_url) + return await fetchUsers(`${url}/api/application/users?page=${metadata.current_page + 1}`) } } } catch (err) { @@ -389,7 +391,7 @@ export class Pterodactyl { } if (data.current_page <= data.last_page) { - const dataBD = await db.ctrlPanel.table(`${numerosParaLetras(guildId)}_servers`).get(String(data.current_page)) + const dataBD = await db.pterodactyl.table(`${numerosParaLetras(guildId)}_servers`).get(String(data.current_page)) if (dataBD?.length <= 50 || serversData?.length > 0) { let isDataChanged = false @@ -406,7 +408,7 @@ export class Pterodactyl { } if (isDataChanged) { core.info(`Tabela: ${data.current_page}/${data.last_page} | Mesclando`) - await db.ctrlPanel.table(`${numerosParaLetras(guildId)}_servers`).set(`${data.current_page}`, serversData) + await db.pterodactyl.table(`${numerosParaLetras(guildId)}_servers`).set(`${data.current_page}`, serversData) } else { core.info(`Tabela: ${data.current_page}/${data.last_page} | Sincronizado`) } @@ -421,7 +423,7 @@ export class Pterodactyl { sincDate: Number(new Date()) } console.log(metadata) - await db.ctrlPanel.table(`${numerosParaLetras(guildId)}_servers`).set('metadata', metadata) + await db.pterodactyl.table(`${numerosParaLetras(guildId)}_servers`).set('metadata', metadata) return metadata } else if (data.next_page_url !== null) { serversData.length = 0 diff --git a/src/crons/SystemStatus.ts b/src/crons/SystemStatus.ts index fb564c31..b99dd82c 100644 --- a/src/crons/SystemStatus.ts +++ b/src/crons/SystemStatus.ts @@ -165,7 +165,7 @@ new Crons({ for (const [, guild] of guilds.entries()) { const enabled = await db.system.get(`${guild.id}.status.PteroStatus`) - if (enabled === false) return + if (enabled !== undefined && enabled === false) return try { const embeds: EmbedBuilder[] = [] const now = new Date() diff --git a/src/discord/components/account/functions/generate.ts b/src/discord/components/account/functions/generate.ts index ab328132..6151ded3 100644 --- a/src/discord/components/account/functions/generate.ts +++ b/src/discord/components/account/functions/generate.ts @@ -139,7 +139,7 @@ export class GenAccount { const embed = new EmbedBuilder({ title: `👋 Bem vindo ${interaction.user.username}.`, description: - 'Abaixo se encontra os metodos atuais para realizar o Login em nossas plataformas' + 'Abaixo se encontra os metodos atuais para realizar o Login em nossas plataformas' }).setColor('Blurple') const row = new ActionRowBuilder() diff --git a/src/discord/components/payments/functions/updateCart.ts b/src/discord/components/payments/functions/updateCart.ts index d948a75a..5bbbb6fa 100644 --- a/src/discord/components/payments/functions/updateCart.ts +++ b/src/discord/components/payments/functions/updateCart.ts @@ -347,10 +347,10 @@ export class UpdateCart { const { Emojis } = settings() embed.setDescription(` - ${cpu !== undefined ? `${Emojis?.cpu} | CPU: ${cpu}` : ''} - ${ram !== undefined ? `${Emojis?.ram} | Ram: ${ram}` : ''} - ${time !== undefined ? `${Emojis?.time} | Duração do plano: ${time}` : ''} - ${disk !== undefined ? `${Emojis?.disk} | Disco: ${disk}` : ''} + ${cpu !== undefined ? `${Emojis?.cpu ?? '🖥️'} | CPU: ${cpu}` : ''} + ${ram !== undefined ? `${Emojis?.ram ?? '🎟'} | Ram: ${ram}` : ''} + ${time !== undefined ? `${Emojis?.time ?? '⏳'} | Duração do plano: ${time}` : ''} + ${disk !== undefined ? `${Emojis?.disk ?? '💿'} | Disco: ${disk}` : ''} `) // ${port !== undefined ? `${Emojis?.port} | Portas: ${port}` : ''} } diff --git a/src/interfaces/Payments.ts b/src/interfaces/Payments.ts index b8fdf70d..43a917f0 100644 --- a/src/interfaces/Payments.ts +++ b/src/interfaces/Payments.ts @@ -85,12 +85,25 @@ export interface PaymentUserCTRL { role: string } -export interface PaymentUserPtero { +export interface UserPtero { id: number - name: string + username: string email: string root_admin: boolean } +export interface PaymentUserPtero { + object: 'user' + attributes: UserPtero +} + +export interface PaymentMetadataPtero { + total: number + count: number + per_page: number + current_page: number + total_pages: number + links: object +} export interface PaymentServerPtero { id: number