Skip to content

Commit bd4254a

Browse files
committed
Correções
1 parent f0db907 commit bd4254a

File tree

2 files changed

+30
-22
lines changed

2 files changed

+30
-22
lines changed

index.js

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,38 @@
1-
// Import all of the files and dependencies needed.
2-
import fs from 'fs'
3-
//import express from 'express'
4-
//import ws from './server/server.js'
5-
import db from './functions/database.js'
6-
import setup from './functions/setup.js'
1+
import fs from 'fs';
2+
import db from './functions/database.js';
3+
import setup from './functions/setup.js';
74

8-
setup(db)
5+
setup(db);
96

107
setTimeout(function main() {
11-
console.log("Arquivo Criado")
12-
fs.writeFileSync("status.json", (`{
13-
"panel": "${db.get('panel')}",
14-
"wings": "${db.get('wings')}",
15-
"server": {
16-
"syncing": ${db.get('ready')},
17-
"lastSynced": "${db.get('lastSynced')}"
18-
}
19-
}`)
20-
)}, 13000)
21-
8+
console.log("Criando arquivo...");
9+
const data = {
10+
panel: db.get('panel'),
11+
wings: db.get('wings'),
12+
server: {
13+
syncing: db.get('ready'),
14+
lastSynced: db.get('lastSynced')
15+
}
16+
};
17+
// Validar e escapar os valores antes de inseri-los no JSON
18+
const json = JSON.stringify(data, null, 2);
19+
// Usar o método "fs.writeFile()" para não bloquear o processo principal
20+
fs.writeFile("status.json", json, (err) => {
21+
if (err) {
22+
console.error(err.message);
23+
} else {
24+
console.log("Arquivo criado com sucesso");
25+
}
26+
});
27+
}, 15000); // Tempo de 15 segundos
28+
29+
// Fechar o banco de dados após 17 segundos
2230
setTimeout(function main() {
23-
db.close((err) => {
31+
db.close((err) => {
2432
if (err) {
2533
console.error(err.message);
2634
} else {
2735
console.log('Banco de dados parado com sucesso');
2836
}
29-
})}, 15000
30-
)
37+
});
38+
}, 17000);

status.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
"wings": "1.11.4",
44
"server": {
55
"syncing": true,
6-
"lastSynced": "1:17:26 PM"
6+
"lastSynced": "10:50:08"
77
}
88
}

0 commit comments

Comments
 (0)