Skip to content

Commit

Permalink
chore: small changes + version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
tabarra committed Jun 11, 2024
1 parent 66d202d commit 3fbe33a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 24 deletions.
47 changes: 25 additions & 22 deletions core/extras/banner.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import boxen from 'boxen';
import chalk from 'chalk';
import open from 'open';
import { shuffle } from 'd3-array';
import { z } from 'zod';

import got from '@core/extras/got.js';
import getOsDistro from '@core/extras/getOsDistro.js';
Expand All @@ -10,25 +12,26 @@ import { addLocalIpAddress } from './isIpAddressLocal';
const console = consoleFactory();


const getIPs = async () => {
const getPublicIp = async () => {
const zIpValidator = z.string().ip();
const reqOptions = {
timeout: { request: 2500 },
timeout: { request: 2000 },
};
const allOps = await Promise.allSettled([
// op.value.ip
// got('https://ip.seeip.org/json', reqOptions).json(), //expired cert?
got('https://api.ipify.org/?format=json', reqOptions).json(),
got('https://api.myip.com', reqOptions).json(),

// op.value.query
// got(`http://ip-api.com/json/`, reqOptions).json(),
// got(`https://extreme-ip-lookup.com/json/`, reqOptions).json(), //requires API key
const httpGetter = async (url, jsonPath) => {
const res = await got(url, reqOptions).json();
return zIpValidator.parse(res[jsonPath]);
};

const allApis = shuffle([
['http://ip-api.com/json/', 'query'],
['https://api.ipify.org?format=json', 'ip'],
['https://api.myip.com', 'ip'],
['https://ip.seeip.org/json', 'ip'],
]);
for (let i = 0; i < allOps.length; i++) {
const op = allOps[i];
if (op.status == 'fulfilled' && op.value.ip) {
return op.value.ip;
}
for await (const [url, jsonPath] of allApis) {
try {
return await httpGetter(url, jsonPath);
} catch (error) { }
}
return false;
};
Expand Down Expand Up @@ -111,8 +114,8 @@ const awaitDatabase = new Promise((resolve, reject) => {


export const printBanner = async () => {
const [ipRes, msgRes, adminPinRes] = await Promise.allSettled([
getIPs(),
const [publicIpResp, msgRes, adminPinRes] = await Promise.allSettled([
getPublicIp(),
getOSMessage(),
awaitMasterPin,
awaitHttp,
Expand All @@ -125,9 +128,9 @@ export const printBanner = async () => {
addrs = [
(txEnv.isWindows) ? 'localhost' : 'your-public-ip',
];
if (ipRes.value) {
addrs.push(ipRes.value);
addLocalIpAddress(ipRes.value);
if (publicIpResp.value) {
addrs.push(publicIpResp.value);
addLocalIpAddress(publicIpResp.value);
}
} else {
addrs = [convars.forceInterface];
Expand Down Expand Up @@ -162,7 +165,7 @@ export const printBanner = async () => {

//Opening page
if (txEnv.isWindows && adminPinRes.value) {
open(`http://localhost:${convars.txAdminPort}/addMaster/pin#${adminPinRes.value}`).catch((e) => {});
open(`http://localhost:${convars.txAdminPort}/addMaster/pin#${adminPinRes.value}`).catch((e) => { });
}

//Starting server
Expand Down
2 changes: 1 addition & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
author 'Tabarra'
description 'The official FiveM/RedM server web/in-game management platform.'
repository 'https://github.com/tabarra/txAdmin'
version '7.2.0-tbd'
version '7.2.0'
ui_label 'txAdmin'

rdr3_warning 'I acknowledge that this is a prerelease build of RedM, and I am aware my resources *will* become incompatible once RedM ships.'
Expand Down
2 changes: 1 addition & 1 deletion locale/sv.json
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@
"ids": {
"current_ids": "Nuvarande identifikationer",
"previous_ids": "Tidigare använda identifikationer",
"all_hwids": "All Hardware IDs"
"all_hwids": "Alla hårdvaru identifikationer"
}
}
}
Expand Down

0 comments on commit 3fbe33a

Please sign in to comment.