-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
52 lines (46 loc) · 1.48 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const fs = require('fs').promises;
const Client = require('node-rest-client').Client;
const { exists, chmodSync } = require('fs');
const repl = require('repl');
const srv = 'https://api.spacetraders.io/v2/';
let token; // Declare token at the global level
function makeRequest(opt) {
const endpoint = `${srv}${opt}`;
const args = {
headers: {'Content-Type': 'application/json', 'Authorization': `Bearer ${token}`}
};
const client = new Client();
client.get(`${endpoint}`, args, (data, response) => {
// Handle the response here
if (response.statusCode === 200) {
console.log('Response data:', data);
} else {
console.error('Error:', response.statusCode, data);
}
});
}
// Read the token asynchronously and set it when available
fs.readFile('secrets/token.txt', 'utf8')
.then((data) => {
token = data; // Store the token at the global level
})
.catch((err) => {
console.error(err);
});
function myEval(cmd, context, filename) {
var cmds = ('test','test2');
if(cmds.includes(cmd)); {
console.log("You just tested");
}
}
const myRepl = repl.start({
prompt: '> ',
eval: (input, context, filename, callback) => { // TODO: implement my eval https://nodejs.dev/en/api/v20/repl/#custom-evaluation-functions
try {
const userIn = eval(input);
callback(null, userIn);
} catch (err) {
callback(err);
}
}
});