Skip to content

Commit

Permalink
🧱 Fix Build
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashu11-A committed Apr 21, 2024
1 parent 297c3f2 commit 61325f3
Show file tree
Hide file tree
Showing 15 changed files with 121 additions and 614 deletions.
613 changes: 51 additions & 562 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"pkg": {
"scripts": [
"build/**/*.js",
"build/**/*.json",
"package.json"
],
"assets": [
Expand Down
37 changes: 16 additions & 21 deletions release.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from 'fs'
import os from 'os';
import os from 'os'
import path from 'path'
import { minify } from 'terser'
import { SingleBar, Presets } from 'cli-progress'
Expand Down Expand Up @@ -32,9 +32,7 @@ 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 @@ -50,32 +48,29 @@ async function compress (): Promise<void> {
},
ie8: false,
keep_fnames: false,
mangle: {
properties: true,
toplevel: true
},
mangle: true,
module: true,
toplevel: true,
output: {
ascii_only: true,
beautify: false,
comments: false,
comments: false
},
sourceMap: true
})
.then((result) => {
if (result.code === undefined) return
// const response = obfuscate(result.code, {
// compact: false,
// controlFlowFlattening: true,
// controlFlowFlatteningThreshold: 1,
// numbersToExpressions: true,
// simplify: true,
// stringArrayShuffle: true,
// splitStrings: true,
// stringArrayThreshold: 1
// })
writeFileSync(`${newPath}/${fileName}`, result.code, 'utf8')
if (typeof result.code !== 'string') return
const response = obfuscate(fileContent, {
compact: false,
controlFlowFlattening: true,
controlFlowFlatteningThreshold: 1,
numbersToExpressions: true,
simplify: true,
stringArrayShuffle: true,
splitStrings: true,
stringArrayThreshold: 1
})
writeFileSync(`${newPath}/${fileName}`, response.getObfuscatedCode(), 'utf8')
})
.catch((err) => {
console.log(`Não foi possivel comprimir o arquivo: ${filePath}`)
Expand All @@ -94,7 +89,7 @@ async function compress (): Promise<void> {
const nodeVersion = '20'
const allBuild: string[] = []

args.push("-t")
args.push('-t')

if (os.platform() !== 'win32') {
for (const platform of platforms) {
Expand Down
6 changes: 3 additions & 3 deletions src/classes/PaymentBot.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { core } from '@/app'
import { type BotReturn, type LoginReturn } from '@/interfaces/PaymentBot'
import internalDB from '@/settings/settings.json'
import axios, { AxiosError } from 'axios'
import { writeFileSync } from 'fs'
import path from 'path'
import ck from 'chalk'
import { getInternalSettings } from '@/functions/getSettings'

export class PaymentBot {
private readonly url
Expand All @@ -19,9 +19,9 @@ export class PaymentBot {
const dbPath = path.join(__dirname, '../settings')

writeFileSync(`${dbPath}/settings.json`, JSON.stringify({
...internalDB,
...getInternalSettings(),
...data,
Tokens: this.tokens ?? internalDB.Tokens
Tokens: this.tokens ?? getInternalSettings().Tokens
}, null, 2))
}

Expand Down
5 changes: 2 additions & 3 deletions src/crons/authUpdate.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { core } from '@/app'
import { Crons } from '@/classes/Crons'
import { PaymentBot } from '@/classes/PaymentBot'
import getSettings from '@/functions/getSettings'
import internalDB from '@/settings/settings.json'
import { getSettings, getInternalSettings } from '@/functions/getSettings'

new Crons({
name: 'Auth - Start',
Expand All @@ -27,7 +26,7 @@ new Crons({
async function authUpdate (): Promise<void> {
const { Auth } = getSettings()
if (Auth?.email === undefined || Auth.password === undefined || Auth.uuid === undefined) { core.warn('Sistema de autenticação não configurado'); return }
const PaymentAuth = new PaymentBot({ url: internalDB.API })
const PaymentAuth = new PaymentBot({ url: getInternalSettings().API })

await PaymentAuth.login({ email: Auth.email, password: Auth.password })
await PaymentAuth.validate({ uuid: Auth.uuid })
Expand Down
4 changes: 2 additions & 2 deletions src/discord/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// Isso irá pegar todos os eventos que um botão é precionado e irá destrinjar ele para os seus reais ações
import { core } from '@/app'
import { CustomButtonBuilder, Discord } from '@/functions'
import getSettings from '@/functions/getSettings'
import internalDB from '@/settings/settings.json'
import { getInternalSettings, getSettings } from '@/functions/getSettings'
import { EmbedBuilder } from 'discord.js'
import { Event } from '../base'
import { ButtonController } from './controller'
Expand All @@ -16,6 +15,7 @@ new Event({
const typeAction = interaction.isButton() ? 'Buttom' : interaction.isModalSubmit() ? 'Modal' : 'Select'
const [id, permission, type, action, userId] = CustomButtonBuilder.getInfos(customId)
const { Auth } = getSettings()
const internalDB = getInternalSettings()

if (Auth === undefined) {
await interaction.reply({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { core, db } from '@/app'
import { UpdateCart } from '@/discord/components/payments'
import { type cartData } from '@/interfaces'
import { ctrlPanel } from '@/functions/ctrlPanel'
import settings from '@/functions/getSettings'
import { getSettings } from '@/functions/getSettings'
import { createRow } from '@magicyan/discord'
import axios from 'axios'
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, ComponentType, EmbedBuilder, codeBlock, type ButtonInteraction, type CacheType, TextChannel, Message, type ModalSubmitInteraction } from 'discord.js'
Expand Down Expand Up @@ -96,7 +96,7 @@ export class PaymentFunction {
if (paymentId !== undefined) {
const token = await db.payments.get(`${guildId}.config.mpToken`)

await axios.post(`http://${settings().Express.ip}:${settings().Express.Port}/payment/delete`, {
await axios.post(`http://${getSettings().Express.ip}:${getSettings().Express.Port}/payment/delete`, {
mpToken: token,
paymentId
}).catch(async (err) => {
Expand Down Expand Up @@ -335,7 +335,7 @@ export class PaymentFunction {
const logChannel = guild.channels.cache.get(String(logs)) as TextChannel

if (cartData?.paymentId !== undefined) {
const pagamentoRes = await axios.post(`http://${settings().Express.ip}:${settings().Express.Port}/payment`, {
const pagamentoRes = await axios.post(`http://${getSettings().Express.ip}:${getSettings().Express.Port}/payment`, {
mpToken,
paymentId: cartData.paymentId
})
Expand Down Expand Up @@ -499,7 +499,7 @@ export class PaymentFunction {
name: productsTotal
}

const response = await axios.post(`http://${settings().Express.ip}:${settings().Express.Port}/ctrlpanel/voucher/create`, Post, {
const response = await axios.post(`http://${getSettings().Express.ip}:${getSettings().Express.Port}/ctrlpanel/voucher/create`, Post, {
headers: {
Accept: 'application/json'
}
Expand Down
6 changes: 3 additions & 3 deletions src/discord/components/payments/functions/createPayment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from 'discord.js'
import { UpdateCart } from './updateCart'
import axios from 'axios'
import settings from '@/functions/getSettings'
import { getSettings } from '@/functions/getSettings'
import { PaymentFunction } from '../cart/functions/cartCollectorFunctions'
import { type cartData, type infoPayment } from '@/interfaces'

Expand Down Expand Up @@ -65,7 +65,7 @@ export async function createPayment (options: {
try {
const paymentCreate = await axios
.post(
`http://${settings().Express.ip}:${settings().Express.Port}/payment/create/pix`,
`http://${getSettings().Express.ip}:${getSettings().Express.Port}/payment/create/pix`,
dataPix
)
.catch(async (error) => {
Expand Down Expand Up @@ -159,7 +159,7 @@ export async function createPayment (options: {
ipn
}
const paymentCreate = await axios.post(
`http://${settings().Express.ip}:${settings().Express.Port}/payment/create/card`,
`http://${getSettings().Express.ip}:${getSettings().Express.Port}/payment/create/card`,
dataCart
)

Expand Down
4 changes: 2 additions & 2 deletions src/discord/components/payments/functions/updateCart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from 'discord.js'
import { type PaymentResponse } from 'mercadopago/dist/clients/payment/commonTypes'
import { type ProductCartData, type cartData } from '@/interfaces'
import settings from '@/functions/getSettings'
import { getSettings } from '@/functions/getSettings'

interface UpdateCartType {
interaction: ButtonInteraction<CacheType> | ModalSubmitInteraction<CacheType> | ChatInputCommandInteraction<CacheType>
Expand Down Expand Up @@ -347,7 +347,7 @@ export class UpdateCart {

if (product.pterodactyl !== undefined) {
const { cpu, disk, time, /* port, */ ram } = product.pterodactyl
const { Emojis } = settings()
const { Emojis } = getSettings()

embed.setDescription(`
${cpu !== undefined ? `${Emojis?.cpu ?? '🖥️'} | CPU: ${cpu}` : ''}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
type StringSelectMenuInteraction
} from 'discord.js'
import { type productData } from '@/interfaces'
import settings from '@/functions/getSettings'
import { getSettings } from '@/functions/getSettings'

interface UpdateProductType {
interaction:
Expand Down Expand Up @@ -68,7 +68,7 @@ export class UpdateProduct {

if (productData?.properties?.SetPterodactyl && productData?.pterodactyl !== undefined) {
const { egg, cpu, disk, time, /* port, */ ram } = productData.pterodactyl
const { Emojis } = settings()
const { Emojis } = getSettings()
const strings: string[] = []

if (egg !== undefined) strings.push(`${Emojis?.egg ?? '⚙️'} | Serviço: ${egg.name}`)
Expand Down
6 changes: 3 additions & 3 deletions src/express/server/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { core } from '@/app'
import settings from '@/functions/getSettings'
import { getSettings } from '@/functions/getSettings'
import { App } from './app'
import http from 'http'
import dotenv from 'dotenv'
Expand All @@ -9,7 +9,7 @@ export default function Run (): void {
const app = new App().server
const server = http.createServer(app)

server.listen(settings().Express.Port, settings().Express.ip, () => {
core.info(`✅ Servidor listado em http://localhost:${settings().Express.Port}`.green)
server.listen(getSettings().Express.Port, getSettings().Express.ip, () => {
core.info(`✅ Servidor listado em http://localhost:${getSettings().Express.Port}`.green)
})
}
8 changes: 4 additions & 4 deletions src/express/server/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { core } from '@/app'
import { type Request, type Response, type NextFunction } from 'express'
import settings from '@/functions/getSettings'
import { getSettings } from '@/functions/getSettings'
import cors from 'cors'

export function corsMiddleware (req: Request, res: Response, next: NextFunction): void {
const { active } = settings().Express.cors
let { allow } = settings().Express.cors
const { active } = getSettings().Express.cors
let { allow } = getSettings().Express.cors

if (active) {
cors<Request>({
origin (requestOrigin, callback) {
if (allow === undefined) allow = ['']
allow.push(`${settings().Express.ip}:${settings().Express.Port}`)
allow.push(`${getSettings().Express.ip}:${getSettings().Express.Port}`)

const origin = requestOrigin ?? req.headers.ip ?? req.headers['x-forwarded-for'] ?? req.socket.remoteAddress ?? req.ip

Expand Down
15 changes: 11 additions & 4 deletions src/functions/getSettings.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { type Config } from '@/interfaces/ConfigJson'
import { type Config, type InternalConfig } from '@/interfaces/ConfigJson'
import { readFileSync } from 'fs'
import { join, resolve } from 'path'
import { cwd } from 'process'

export default function getSettings (): Config {
const data = readFileSync('./settings.json', { encoding: 'utf-8' })
return JSON.parse(data) as Config
export function getSettings (): Config {
const data = readFileSync(resolve(cwd(), './settings.json'), { encoding: 'utf-8' })
return JSON.parse(data)
}

export function getInternalSettings (): InternalConfig {
const data = readFileSync(resolve(join(__dirname, '../settings/settings.json')), { encoding: 'utf-8' })
return JSON.parse(data)
}
16 changes: 16 additions & 0 deletions src/interfaces/ConfigJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,19 @@ export interface Config {
Emojis: Emoji
Auth: Auth
}

interface TokenData {
accessToken: string
refreshToken: string
}

export interface InternalConfig {
API: string
Tokens: TokenData
expired: boolean
enabled: boolean
expire_at: string
created_at: string
uuid: string
name: string
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
"skipDefaultLibCheck": true,
"skipLibCheck": true
},
"include": ["./src/**/*"],
"include": ["./src/**/*", "./release.ts"],
"exclude": [""]
}

0 comments on commit 61325f3

Please sign in to comment.