Skip to content

Commit

Permalink
chore: updated mysql2 and got
Browse files Browse the repository at this point in the history
plus esbuild, but that didn't take any test
  • Loading branch information
tabarra committed Jun 25, 2023
1 parent 6f4789d commit 2ed6a3b
Show file tree
Hide file tree
Showing 10 changed files with 424 additions and 525 deletions.
8 changes: 6 additions & 2 deletions core/components/HealthMonitor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,13 @@ export default class HealthMonitor {
let dynamicResp;
const requestOptions = {
url: `http://${globals.fxRunner.fxServerHost}/dynamic.json`,
timeout: this.hardConfigs.timeout,
maxRedirects: 0,
retry: { limit: 0 },
timeout: {
request: this.hardConfigs.timeout
},
retry: {
limit: 0
},
};
try {
const data = await got.get(requestOptions).json();
Expand Down
4 changes: 3 additions & 1 deletion core/extras/banner.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ const console = consoleFactory();


const getIPs = async () => {
const reqOptions = { timeout: 2500 };
const reqOptions = {
timeout: { request: 2500 }
};
const allOps = await Promise.allSettled([
// op.value.ip
got('https://ip.seeip.org/json', reqOptions).json(),
Expand Down
4 changes: 3 additions & 1 deletion core/extras/got.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { convars, txEnv } from '@core/globalData';
import got from 'got';

export default got.extend({
timeout: 5000,
timeout: {
request: 5000
},
headers: {
'User-Agent': `txAdmin ${txEnv.txAdminVersion}`,
},
Expand Down
7 changes: 6 additions & 1 deletion core/extras/recipeEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,12 @@ const taskDownloadGithub = async (options, basePath, deployerCtx) => {
if (options.ref) {
reference = options.ref;
} else {
const data = await got.get(`https://api.github.com/repos/${repoOwner}/${repoName}`, { timeout: 15e3 }).json();
const data = await got.get(
`https://api.github.com/repos/${repoOwner}/${repoName}`,
{
timeout: { request: 15e3 }
}
).json();
if (typeof data !== 'object' || !data.default_branch) {
throw new Error('reference not set, and wasn ot able to detect using github\'s api');
}
Expand Down
12 changes: 7 additions & 5 deletions core/webroutes/adminManager/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ const discordIDRegex = /^\d{17,20}$/;
const nameRegex = citizenfxIDRegex;
const nameRegexDesc = 'up to 18 characters containing only letters, numbers and the characters \`_.-\`';
const dangerousPerms = ['all_permissions', 'manage.admins', 'console.write', 'settings.write'];

const cfxHttpReqOptions = {
timeout: { request: 6000 }
}

/**
* Returns the output page containing the admins.
Expand Down Expand Up @@ -87,7 +89,7 @@ async function handleAdd(ctx) {
try {
if (consts.validIdentifiers.fivem.test(citizenfxID)) {
const id = citizenfxID.split(':')[1];
const res = await got(`https://policy-live.fivem.net/api/getUserInfo/${id}`, {timeout: 6000}).json();
const res = await got(`https://policy-live.fivem.net/api/getUserInfo/${id}`, cfxHttpReqOptions).json();
if (!res.username || !res.username.length) {
return ctx.send({type: 'danger', message: 'Invalid CitizenFX ID1'});
}
Expand All @@ -96,7 +98,7 @@ async function handleAdd(ctx) {
identifier: citizenfxID,
};
} else if (citizenfxIDRegex.test(citizenfxID)) {
const res = await got(`https://forum.cfx.re/u/${citizenfxID}.json`, {timeout: 6000}).json();
const res = await got(`https://forum.cfx.re/u/${citizenfxID}.json`, cfxHttpReqOptions).json();
if (!res.user || typeof res.user.id !== 'number') {
return ctx.send({type: 'danger', message: 'Invalid CitizenFX ID2'});
}
Expand Down Expand Up @@ -182,7 +184,7 @@ async function handleEdit(ctx) {
try {
if (consts.validIdentifiers.fivem.test(citizenfxID)) {
const id = citizenfxID.split(':')[1];
const res = await got(`https://policy-live.fivem.net/api/getUserInfo/${id}`, {timeout: 6000}).json();
const res = await got(`https://policy-live.fivem.net/api/getUserInfo/${id}`, cfxHttpReqOptions).json();
if (!res.username || !res.username.length) {
return ctx.send({type: 'danger', message: '(ERR1) Invalid CitizenFX ID'});
}
Expand All @@ -191,7 +193,7 @@ async function handleEdit(ctx) {
identifier: citizenfxID,
};
} else if (citizenfxIDRegex.test(citizenfxID)) {
const res = await got(`https://forum.cfx.re/u/${citizenfxID}.json`, {timeout: 6000}).json();
const res = await got(`https://forum.cfx.re/u/${citizenfxID}.json`, cfxHttpReqOptions).json();
if (!res.user || typeof res.user.id !== 'number') {
return ctx.send({type: 'danger', message: '(ERR2) Invalid CitizenFX ID'});
}
Expand Down
4 changes: 3 additions & 1 deletion core/webroutes/diagnostics/diagnosticsFuncs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ export const getFXServerData = async () => {
const requestOptions = {
url: `http://${fxRunner.fxServerHost}/info.json`,
maxRedirects: 0,
timeout: healthMonitor.hardConfigs.timeout,
timeout: {
request: healthMonitor.hardConfigs.timeout
},
retry: { limit: 0 },
};

Expand Down
4 changes: 2 additions & 2 deletions core/webroutes/setup/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ async function handleValidateRecipeURL(ctx) {
try {
const recipeText = await got.get({
url: recipeURL,
timeout: 4500,
timeout: { request: 4500 }
}).text();
if (typeof recipeText !== 'string') throw new Error('This URL did not return a string.');
const recipe = parseValidateRecipe(recipeText);
Expand Down Expand Up @@ -330,7 +330,7 @@ async function handleSaveDeployerImport(ctx) {
try {
recipeText = await got.get({
url: recipeURL,
timeout: 4500,
timeout: { request: 4500 }
}).text();
if (typeof recipeText !== 'string') throw new Error('This URL did not return a string.');
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion docs/dev_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
- [x] improve timeout handling of discord bot save
- [x] fix handling of disallowed intents
- [x] improve the bot with dangerous permissions and missing access messages
- [ ] attempt to update mysql2 and got
- [x] attempt to update mysql2 and got
- [ ] merge PRs
- [ ] disable whitelist page when server is not on license whitelist mode

Expand Down
Loading

0 comments on commit 2ed6a3b

Please sign in to comment.