Skip to content

Commit

Permalink
🐛 fix: Pterodactyl Login
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashu11-A committed Mar 4, 2024
1 parent 3444817 commit d49b301
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 42 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 9 additions & 2 deletions release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -31,7 +32,9 @@ async function carregarDados (options: {
async function compress (): Promise<void> {
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')
Expand All @@ -47,13 +50,16 @@ async function compress (): Promise<void> {
},
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
})
Expand All @@ -69,6 +75,7 @@ async function compress (): Promise<void> {
writeFileSync(`${newPath}/${fileName}`, fileContent, 'utf8')
}
}

progressBar.stop()

const args = ['.', '--no-bytecode', '--compress', 'Brotli', '--public-packages', '"*"', '--public']
Expand Down
9 changes: 4 additions & 5 deletions rollup.config.ts
Original file line number Diff line number Diff line change
@@ -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'],
Expand Down Expand Up @@ -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,
Expand Down
52 changes: 27 additions & 25 deletions src/classes/Pterodactyl.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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' })
Expand All @@ -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(
Expand Down Expand Up @@ -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
Expand All @@ -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,

Check failure on line 302 in src/classes/Pterodactyl.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Object literal may only specify known properties, and 'name' does not exist in type 'UserPtero'.

Check failure on line 302 in src/classes/Pterodactyl.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Object literal may only specify known properties, and 'name' does not exist in type 'UserPtero'.
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

Expand All @@ -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) {
Expand Down Expand Up @@ -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

Expand All @@ -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`)
}
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/crons/SystemStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/discord/components/account/functions/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ButtonBuilder>()
Expand Down
8 changes: 4 additions & 4 deletions src/discord/components/payments/functions/updateCart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}` : ''}
}
Expand Down
17 changes: 15 additions & 2 deletions src/interfaces/Payments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d49b301

Please sign in to comment.