-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest.ts
48 lines (41 loc) · 1.86 KB
/
test.ts
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
import { Luraph } from ".";
const api = new Luraph(process.env.LPH_API_KEY ?? "");
const main = async () => {
const nodes = await api.getNodes();
let recommendedId = nodes.recommendedId;
//this is **not recommended** in a production environment!
//recommendedId purposely only recommends nodes marked as stable
if(recommendedId === null)
recommendedId = Object.keys(nodes)[0];
console.log("Recommended Node:", recommendedId);
const node = nodes.nodes[recommendedId];
console.log("- CPU Usage:", node.cpuUsage);
console.log("- Options: ");
for(const [optionId, optionInfo] of Object.entries(node.options)){
console.log(" *", optionId, "-", optionInfo.name + ":");
console.log(" |- Description:", optionInfo.description);
console.log(" |- Type:", optionInfo.type);
console.log(" |- Tier:", optionInfo.tier);
console.log(" |- Required:", optionInfo.required);
console.log(" |- Choices:", `[${optionInfo.choices.join(", ")}]`);
if(optionInfo.dependencies){
console.log(" |- Dependencies:");
for(const [dependencyId, dependencyChoices] of Object.entries(optionInfo.dependencies)){
console.log(` * ${dependencyId}:`, `[${dependencyChoices.join(", ")}]`);
}
}
console.log("");
}
const {jobId} = await api.createNewJob(recommendedId, `print'Hello World!'`, "hello-world.txt", {});
console.log("Job ID", jobId);
const {success, error} = await api.getJobStatus(jobId);
console.log("Job finished", success ? "sucessfully" : "unsucessfully");
if(success){
const {fileName, data} = await api.downloadResult(jobId);
console.log("Result Filename", fileName);
console.log("First line of file", data.split("\n")[0]);
}else{
console.log("Error", error);
}
};
main();