Skip to content

Commit

Permalink
fix: endpoints not working
Browse files Browse the repository at this point in the history
  • Loading branch information
Deivu committed Aug 21, 2024
1 parent a75e18e commit 626f553
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 29 deletions.
8 changes: 5 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const Formidable = require('./src/Formidable.js');

new Formidable()
.load()
.listen();
(async function main() {
const client = new Formidable();
await client.load();
await client.listen();
})();
19 changes: 9 additions & 10 deletions src/Formidable.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class Formidable {
}

async handle(command, endpoint, request, reply) {
console.log(endpoint);
try {
let body = request.query;
if (!Config.auth && command.locked) {
Expand Down Expand Up @@ -116,7 +115,15 @@ class Formidable {
reply.send(this.endpoints);
}

load() {
async load() {
// Check for updates
this.logger.info('[Server] Checking for latest updates...');
try {
await this.update();
this.logger.info('[Server] Update done');
} catch (error) {
this.logger.error(error);
}
// Load global ratelimit
const global = new Limiter(this).global();
this.logger.info(`[Ratelimits] Global: ${global.options.points} reqs / ${global.options.duration}s`);
Expand Down Expand Up @@ -197,14 +204,6 @@ class Formidable {
if (!Config.port) this.logger.warn('[Server] User didn\'t set a port, will use a random open port');
if (!Config.auth) this.logger.warn('[Server] User didn\'t set an auth, locked endpoints will execute without authorization');

this.logger.info('[Server] Checking for latest updates...');
try {
await this.update();
this.logger.info('[Server] Update done');
} catch (error) {
this.logger.error(error);
}

setInterval(() => {
try {
this.update();
Expand Down
22 changes: 9 additions & 13 deletions src/struct/Cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Cache {
this.fuse = {};
this.listening = false;
for (const [ key, file ] of Object.entries(FILES)) this.update(key, `${DIRECTORY}/${file}`);

this.monitor();
}

Expand All @@ -20,19 +21,14 @@ class Cache {
}

update(key, directory) {
Create()
.then(() => {
// read data
const data = readJSONSync(directory);
// do not update internal data if local files is empty
if (!Object.keys(data || {}).length) return;
this.data[key.toLowerCase()] = data;
const keys = SEARCH[key];
if (!keys) return;
const dist = Config.distance;
this.fuse[key.toLowerCase()] = new Fuse(this.data[key.toLowerCase()], { keys, distance: dist });
})
.catch(() => null);
const data = readJSONSync(directory);
// do not update internal data if local files is empty
if (!Object.keys(data || {}).length) return;
this.data[key.toLowerCase()] = data;
const keys = SEARCH[key];
if (!keys) return;
const dist = Config.distance;
this.fuse[key.toLowerCase()] = new Fuse(this.data[key.toLowerCase()], { keys, distance: dist });
}

monitor() {
Expand Down
5 changes: 2 additions & 3 deletions src/struct/Updater.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@ const Check = async () => {
const shouldForceUpdate = await ForceUpdate();
if (shouldForceUpdate) return Object.keys(FILES);

/** @type string */
const raw = await fetch(URLS.VERSION);
const remote = JSON.parse(raw);
const response = await Axios.get(URLS.VERSION);
const remote = response.data;
const local = await readJSON(`${DIRECTORY}/${FILES.VERSION}`);

const outdated = [];
Expand Down

0 comments on commit 626f553

Please sign in to comment.