exaroton 1.9.0 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -1
- package/index.js +3 -2
- package/package.json +1 -1
- package/src/Request/Server/Files/Config/GetConfigFileOptionsRequest.js +7 -0
- package/src/Request/Server/Files/Config/UpdateConfigFileOptionsRequest.js +21 -0
- package/src/Server/Config/Config.js +115 -0
- package/src/Server/Config/ConfigOption.js +103 -0
- package/src/Server/Config/ConfigOptionType.js +13 -0
- package/src/Server/File.js +38 -5
package/README.md
CHANGED
|
@@ -291,6 +291,40 @@ try {
|
|
|
291
291
|
}
|
|
292
292
|
```
|
|
293
293
|
|
|
294
|
+
#### Config files
|
|
295
|
+
Config files are files that contain server configuration and are shown as forms rather than plain text files in the exaroton panel.
|
|
296
|
+
You can get a config file object by using the `getConfig()` method on a file object.
|
|
297
|
+
Whether a file is a config file can be checked using the `isConfigFile` property.
|
|
298
|
+
|
|
299
|
+
```js
|
|
300
|
+
let file = server.getFile("server.properties");
|
|
301
|
+
let config = file.getConfig();
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
#### Get config file options
|
|
305
|
+
```js
|
|
306
|
+
let options = await config.getOptions();
|
|
307
|
+
for(let [key, option] of options) {
|
|
308
|
+
console.log(key, option.getValue());
|
|
309
|
+
}
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
#### Update config file options
|
|
313
|
+
```js
|
|
314
|
+
let options = await config.getOptions();
|
|
315
|
+
|
|
316
|
+
options.get("max-players").setValue(26);
|
|
317
|
+
options.get("pvp").setValue(false);
|
|
318
|
+
|
|
319
|
+
await config.save();
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
Options of type `select` or `multiselect` have a list of possible values.
|
|
323
|
+
```js
|
|
324
|
+
let options = await config.getOptions();
|
|
325
|
+
console.log(options.get("difficulty").getOptions());
|
|
326
|
+
```
|
|
327
|
+
|
|
294
328
|
### Websocket API
|
|
295
329
|
The websocket API allows a constant connection to our websocket service to receive
|
|
296
330
|
events in real time without polling (e.g. trying to get the server status every few seconds).
|
|
@@ -372,4 +406,4 @@ You can unsubscribe from one, multiple or all streams using the `server.unsubscr
|
|
|
372
406
|
server.unsubscribe("console");
|
|
373
407
|
server.unsubscribe(["tick", "heap"]);
|
|
374
408
|
server.unsubscribe(); // this disconnects the websocket connection
|
|
375
|
-
```
|
|
409
|
+
```
|
package/index.js
CHANGED
|
@@ -4,5 +4,6 @@ module.exports = {
|
|
|
4
4
|
Software: require('./src/Server/Software'),
|
|
5
5
|
ServerStatus: require('./src/Server/ServerStatus'),
|
|
6
6
|
Request: require('./src/Request/Request'),
|
|
7
|
-
Response: require('./src/Response/Response')
|
|
8
|
-
|
|
7
|
+
Response: require('./src/Response/Response'),
|
|
8
|
+
ConfigOptionType: require('./src/Server/Config/ConfigOptionType')
|
|
9
|
+
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const FileRequest = require("../FileRequest");
|
|
2
|
+
|
|
3
|
+
class UpdateConfigFileOptionsRequest extends FileRequest {
|
|
4
|
+
endpoint = "servers/{id}/files/config/{path}";
|
|
5
|
+
method = "POST";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* UpdateConfigFileOptionsRequest constructor
|
|
9
|
+
*
|
|
10
|
+
* @param {string} id
|
|
11
|
+
* @param {string} path
|
|
12
|
+
* @param {Object.<string, string|number|boolean|string[]>} options
|
|
13
|
+
*/
|
|
14
|
+
constructor(id, path, options) {
|
|
15
|
+
super(id, path);
|
|
16
|
+
|
|
17
|
+
this.data = options;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
module.exports = UpdateConfigFileOptionsRequest;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
const GetConfigFileOptionsRequest = require("../../Request/Server/Files/Config/GetConfigFileOptionsRequest");
|
|
2
|
+
const UpdateConfigFileOptionsRequest = require("../../Request/Server/Files/Config/UpdateConfigFileOptionsRequest");
|
|
3
|
+
const ConfigOption = require("./ConfigOption");
|
|
4
|
+
|
|
5
|
+
class Config {
|
|
6
|
+
/**
|
|
7
|
+
* @type {File}
|
|
8
|
+
*/
|
|
9
|
+
#file;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @type {null|Map<string, ConfigOption>}
|
|
13
|
+
*/
|
|
14
|
+
#options = null;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @type {null|Map<string, ConfigOptionValue>}
|
|
18
|
+
*/
|
|
19
|
+
#originalValues = null;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @param {File} file
|
|
23
|
+
*/
|
|
24
|
+
constructor(file) {
|
|
25
|
+
this.#file = file;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @param {Object} object
|
|
30
|
+
* @return {this}
|
|
31
|
+
*/
|
|
32
|
+
applyData(object) {
|
|
33
|
+
this.#options = new Map();
|
|
34
|
+
this.#originalValues = new Map();
|
|
35
|
+
|
|
36
|
+
if (!Array.isArray(object)) {
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
for (const option of object) {
|
|
41
|
+
if (typeof option !== "object") {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
let {key, label, type, value, options} = option;
|
|
46
|
+
if (typeof key !== "string" || typeof label !== "string" || typeof type !== "string" || options && !Array.isArray(options)) {
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
this.#options.set(key, new ConfigOption(key, label, type, value, options));
|
|
51
|
+
this.#originalValues.set(key, value);
|
|
52
|
+
}
|
|
53
|
+
return this;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @return {Promise<this>}
|
|
58
|
+
*/
|
|
59
|
+
async #loadOptions() {
|
|
60
|
+
const response = await this.#file.getClient().request(new GetConfigFileOptionsRequest(this.#file.getServer().id, this.#file.path));
|
|
61
|
+
this.applyData(response.getData());
|
|
62
|
+
return this;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* @param {boolean} update
|
|
67
|
+
* @return {Promise<Map<string, ConfigOption>>}
|
|
68
|
+
*/
|
|
69
|
+
async getOptions(update = false) {
|
|
70
|
+
if (update || this.#options === null) {
|
|
71
|
+
await this.#loadOptions();
|
|
72
|
+
}
|
|
73
|
+
return this.#options;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* @param {string} key
|
|
78
|
+
* @return {Promise<ConfigOption|null>}
|
|
79
|
+
*/
|
|
80
|
+
async getOption(key) {
|
|
81
|
+
const options = await this.getOptions();
|
|
82
|
+
return options.get(key) ?? null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Save all changes made to this config file
|
|
87
|
+
*
|
|
88
|
+
* @return {Promise<Response|null>} null if no changes were made
|
|
89
|
+
*/
|
|
90
|
+
async save() {
|
|
91
|
+
let updated = false;
|
|
92
|
+
let changed = {};
|
|
93
|
+
for (let [key, option] of this.#options) {
|
|
94
|
+
if (option.getValue() !== this.#originalValues.get(key)) {
|
|
95
|
+
updated = true;
|
|
96
|
+
changed[key] = option.getValue();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (!updated) {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
let response = await this.#file.getClient().request(
|
|
105
|
+
new UpdateConfigFileOptionsRequest(this.#file.getServer().id, this.#file.path, changed));
|
|
106
|
+
|
|
107
|
+
for (let [key, value] of Object.entries(changed)) {
|
|
108
|
+
this.#originalValues.set(key, value);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return response;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
module.exports = Config;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {string|number|boolean|string[]} ConfigOptionValue
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
class ConfigOption {
|
|
6
|
+
/**
|
|
7
|
+
* Key of this config option
|
|
8
|
+
*
|
|
9
|
+
* @type {string}
|
|
10
|
+
*/
|
|
11
|
+
#key;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Label of this config option
|
|
15
|
+
*
|
|
16
|
+
* @type {string}
|
|
17
|
+
*/
|
|
18
|
+
#label;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Option type
|
|
22
|
+
*
|
|
23
|
+
* @type {string}
|
|
24
|
+
*/
|
|
25
|
+
#type;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Current option value
|
|
29
|
+
*
|
|
30
|
+
* @type {ConfigOptionValue}
|
|
31
|
+
*/
|
|
32
|
+
#value;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Available options for select/multiselect
|
|
36
|
+
*
|
|
37
|
+
* @type {string[]|null}
|
|
38
|
+
*/
|
|
39
|
+
#options;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* ConfigOption constructor
|
|
43
|
+
*
|
|
44
|
+
* @param {string} key
|
|
45
|
+
* @param {string} label
|
|
46
|
+
* @param {string} type
|
|
47
|
+
* @param {ConfigOptionValue} value
|
|
48
|
+
* @param {string[]|null} options
|
|
49
|
+
*/
|
|
50
|
+
constructor(key, label, type, value, options = null) {
|
|
51
|
+
this.#key = key;
|
|
52
|
+
this.#label = label;
|
|
53
|
+
this.#type = type;
|
|
54
|
+
this.#value = value;
|
|
55
|
+
this.#options = options;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @return {string}
|
|
60
|
+
*/
|
|
61
|
+
getKey() {
|
|
62
|
+
return this.#key;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* @return {string}
|
|
67
|
+
*/
|
|
68
|
+
getLabel() {
|
|
69
|
+
return this.#label;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @return {string}
|
|
74
|
+
*/
|
|
75
|
+
getType() {
|
|
76
|
+
return this.#type;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @return {ConfigOptionValue}
|
|
81
|
+
*/
|
|
82
|
+
getValue() {
|
|
83
|
+
return this.#value;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* @param {ConfigOptionValue} value
|
|
88
|
+
* @return {ConfigOption}
|
|
89
|
+
*/
|
|
90
|
+
setValue(value) {
|
|
91
|
+
this.#value = value;
|
|
92
|
+
return this;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* @return {string[]|null}
|
|
97
|
+
*/
|
|
98
|
+
getOptions() {
|
|
99
|
+
return this.#options;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
module.exports = ConfigOption;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @enum {string}
|
|
3
|
+
*/
|
|
4
|
+
class ConfigOptionType {
|
|
5
|
+
static STRING = "string";
|
|
6
|
+
static INTEGER = "number";
|
|
7
|
+
static FLOAT = "float";
|
|
8
|
+
static BOOLEAN = "boolean";
|
|
9
|
+
static MULTI_SELECT = "multiselect";
|
|
10
|
+
static SELECT = "select";
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
module.exports = ConfigOptionType;
|
package/src/Server/File.js
CHANGED
|
@@ -3,6 +3,7 @@ const GetFileDataRequest = require("../Request/Server/Files/GetFileDataRequest")
|
|
|
3
3
|
const PutFileDataRequest = require("../Request/Server/Files/PutFileDataRequest");
|
|
4
4
|
const DeleteFileDataRequest = require("../Request/Server/Files/DeleteFileDataRequest");
|
|
5
5
|
const CreateDirectoryRequest = require("../Request/Server/Files/CreateDirectoryRequest");
|
|
6
|
+
const Config = require("./Config/Config");
|
|
6
7
|
|
|
7
8
|
class File {
|
|
8
9
|
/**
|
|
@@ -60,15 +61,20 @@ class File {
|
|
|
60
61
|
children = null;
|
|
61
62
|
|
|
62
63
|
/**
|
|
63
|
-
* @type {
|
|
64
|
+
* @type {Server}
|
|
64
65
|
*/
|
|
65
66
|
#server;
|
|
66
67
|
|
|
67
68
|
/**
|
|
68
|
-
* @type {
|
|
69
|
+
* @type {Client}
|
|
69
70
|
*/
|
|
70
71
|
#client;
|
|
71
72
|
|
|
73
|
+
/**
|
|
74
|
+
* @type {Config|null}
|
|
75
|
+
*/
|
|
76
|
+
#config = null;
|
|
77
|
+
|
|
72
78
|
/**
|
|
73
79
|
* @param {string|null} path
|
|
74
80
|
*/
|
|
@@ -113,7 +119,7 @@ class File {
|
|
|
113
119
|
/**
|
|
114
120
|
* Set the server
|
|
115
121
|
*
|
|
116
|
-
* @param server
|
|
122
|
+
* @param {Server} server
|
|
117
123
|
* @returns {this}
|
|
118
124
|
*/
|
|
119
125
|
setServer(server) {
|
|
@@ -129,7 +135,7 @@ class File {
|
|
|
129
135
|
/**
|
|
130
136
|
* Set the API client
|
|
131
137
|
*
|
|
132
|
-
* @param client
|
|
138
|
+
* @param {Client} client
|
|
133
139
|
* @returns {this}
|
|
134
140
|
*/
|
|
135
141
|
setClient(client) {
|
|
@@ -142,6 +148,20 @@ class File {
|
|
|
142
148
|
return this;
|
|
143
149
|
}
|
|
144
150
|
|
|
151
|
+
/**
|
|
152
|
+
* @return {Client}
|
|
153
|
+
*/
|
|
154
|
+
getClient() {
|
|
155
|
+
return this.#client;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* @return {Server}
|
|
160
|
+
*/
|
|
161
|
+
getServer() {
|
|
162
|
+
return this.#server;
|
|
163
|
+
}
|
|
164
|
+
|
|
145
165
|
/**
|
|
146
166
|
* Get file information from the API
|
|
147
167
|
*
|
|
@@ -251,6 +271,19 @@ class File {
|
|
|
251
271
|
|
|
252
272
|
return this.children;
|
|
253
273
|
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Get Config object for this file
|
|
277
|
+
* Only available if the file is a config file
|
|
278
|
+
*
|
|
279
|
+
* @return {Config}
|
|
280
|
+
*/
|
|
281
|
+
getConfig() {
|
|
282
|
+
if (this.#config === null) {
|
|
283
|
+
this.#config = new Config(this);
|
|
284
|
+
}
|
|
285
|
+
return this.#config;
|
|
286
|
+
}
|
|
254
287
|
}
|
|
255
288
|
|
|
256
|
-
module.exports = File;
|
|
289
|
+
module.exports = File;
|