@meowpanel/api 0.2.0 → 0.4.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/esm/mod.d.ts +39 -18
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +26 -8
- package/esm/src/client.d.ts +48 -11
- package/esm/src/client.d.ts.map +1 -1
- package/esm/src/client.js +53 -12
- package/esm/src/errors.d.ts +8 -0
- package/esm/src/errors.d.ts.map +1 -1
- package/esm/src/errors.js +10 -0
- package/esm/src/http.d.ts +2 -2
- package/esm/src/http.d.ts.map +1 -1
- package/esm/src/http.js +5 -2
- package/esm/src/namespace.d.ts +1 -1
- package/esm/src/namespace.js +1 -1
- package/esm/src/resources/account.d.ts +104 -19
- package/esm/src/resources/account.d.ts.map +1 -1
- package/esm/src/resources/account.js +112 -13
- package/esm/src/resources/api-keys.d.ts +16 -24
- package/esm/src/resources/api-keys.d.ts.map +1 -1
- package/esm/src/resources/api-keys.js +16 -20
- package/esm/src/resources/auth.d.ts +70 -4
- package/esm/src/resources/auth.d.ts.map +1 -1
- package/esm/src/resources/auth.js +47 -4
- package/esm/src/resources/eggs.d.ts +261 -22
- package/esm/src/resources/eggs.d.ts.map +1 -1
- package/esm/src/resources/eggs.js +261 -25
- package/esm/src/resources/features.d.ts +35 -0
- package/esm/src/resources/features.d.ts.map +1 -0
- package/esm/src/resources/features.js +21 -0
- package/esm/src/resources/hosts.d.ts +143 -18
- package/esm/src/resources/hosts.d.ts.map +1 -1
- package/esm/src/resources/hosts.js +145 -10
- package/esm/src/resources/logs.d.ts +39 -0
- package/esm/src/resources/logs.d.ts.map +1 -0
- package/esm/src/resources/logs.js +38 -0
- package/esm/src/resources/nodes.d.ts +106 -41
- package/esm/src/resources/nodes.d.ts.map +1 -1
- package/esm/src/resources/nodes.js +121 -28
- package/esm/src/resources/permissions.d.ts +45 -0
- package/esm/src/resources/permissions.d.ts.map +1 -0
- package/esm/src/resources/permissions.js +26 -0
- package/esm/src/resources/request-logs.d.ts +91 -0
- package/esm/src/resources/request-logs.d.ts.map +1 -0
- package/esm/src/resources/request-logs.js +70 -0
- package/esm/src/resources/roles.d.ts +128 -0
- package/esm/src/resources/roles.d.ts.map +1 -0
- package/esm/src/resources/roles.js +142 -0
- package/esm/src/resources/server-groups.d.ts +141 -7
- package/esm/src/resources/server-groups.d.ts.map +1 -1
- package/esm/src/resources/server-groups.js +157 -8
- package/esm/src/resources/servers/activity.d.ts +50 -8
- package/esm/src/resources/servers/activity.d.ts.map +1 -1
- package/esm/src/resources/servers/activity.js +54 -13
- package/esm/src/resources/servers/allocations.d.ts +3 -3
- package/esm/src/resources/servers/allocations.d.ts.map +1 -1
- package/esm/src/resources/servers/allocations.js +7 -7
- package/esm/src/resources/servers/backups.d.ts +46 -0
- package/esm/src/resources/servers/backups.d.ts.map +1 -0
- package/esm/src/resources/servers/backups.js +43 -0
- package/esm/src/resources/servers/connection.d.ts +27 -7
- package/esm/src/resources/servers/connection.d.ts.map +1 -1
- package/esm/src/resources/servers/connection.js +28 -7
- package/esm/src/resources/servers/features.d.ts +81 -0
- package/esm/src/resources/servers/features.d.ts.map +1 -0
- package/esm/src/resources/servers/features.js +60 -0
- package/esm/src/resources/servers/files.d.ts +41 -53
- package/esm/src/resources/servers/files.d.ts.map +1 -1
- package/esm/src/resources/servers/files.js +74 -116
- package/esm/src/resources/servers/index.d.ts +46 -27
- package/esm/src/resources/servers/index.d.ts.map +1 -1
- package/esm/src/resources/servers/index.js +26 -12
- package/esm/src/resources/servers/jobs.d.ts +88 -0
- package/esm/src/resources/servers/jobs.d.ts.map +1 -0
- package/esm/src/resources/servers/jobs.js +115 -0
- package/esm/src/resources/servers/node-client.d.ts +33 -0
- package/esm/src/resources/servers/node-client.d.ts.map +1 -0
- package/esm/src/resources/servers/node-client.js +61 -0
- package/esm/src/resources/servers/profiles.d.ts +45 -1
- package/esm/src/resources/servers/profiles.d.ts.map +1 -1
- package/esm/src/resources/servers/profiles.js +55 -2
- package/esm/src/resources/servers/server.d.ts +10 -25
- package/esm/src/resources/servers/server.d.ts.map +1 -1
- package/esm/src/resources/servers/server.js +18 -34
- package/esm/src/resources/servers/sftp.d.ts +21 -19
- package/esm/src/resources/servers/sftp.d.ts.map +1 -1
- package/esm/src/resources/servers/sftp.js +22 -14
- package/esm/src/resources/servers/sub-users.d.ts +99 -0
- package/esm/src/resources/servers/sub-users.d.ts.map +1 -0
- package/esm/src/resources/servers/sub-users.js +94 -0
- package/esm/src/resources/servers/types.d.ts +27 -25
- package/esm/src/resources/servers/types.d.ts.map +1 -1
- package/esm/src/resources/systems.d.ts +124 -0
- package/esm/src/resources/systems.d.ts.map +1 -0
- package/esm/src/resources/systems.js +139 -0
- package/esm/src/resources/users.d.ts +330 -0
- package/esm/src/resources/users.d.ts.map +1 -0
- package/esm/src/resources/users.js +280 -0
- package/esm/src/types.d.ts +18 -1
- package/esm/src/types.d.ts.map +1 -1
- package/esm/src/types.js +11 -0
- package/package.json +1 -1
- package/script/mod.d.ts +39 -18
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +52 -5
- package/script/src/client.d.ts +48 -11
- package/script/src/client.d.ts.map +1 -1
- package/script/src/client.js +53 -12
- package/script/src/errors.d.ts +8 -0
- package/script/src/errors.d.ts.map +1 -1
- package/script/src/errors.js +10 -0
- package/script/src/http.d.ts +2 -2
- package/script/src/http.d.ts.map +1 -1
- package/script/src/http.js +5 -2
- package/script/src/namespace.d.ts +1 -1
- package/script/src/namespace.js +1 -1
- package/script/src/resources/account.d.ts +104 -19
- package/script/src/resources/account.d.ts.map +1 -1
- package/script/src/resources/account.js +114 -13
- package/script/src/resources/api-keys.d.ts +16 -24
- package/script/src/resources/api-keys.d.ts.map +1 -1
- package/script/src/resources/api-keys.js +15 -19
- package/script/src/resources/auth.d.ts +70 -4
- package/script/src/resources/auth.d.ts.map +1 -1
- package/script/src/resources/auth.js +47 -4
- package/script/src/resources/eggs.d.ts +261 -22
- package/script/src/resources/eggs.d.ts.map +1 -1
- package/script/src/resources/eggs.js +267 -26
- package/script/src/resources/features.d.ts +35 -0
- package/script/src/resources/features.d.ts.map +1 -0
- package/script/src/resources/features.js +25 -0
- package/script/src/resources/hosts.d.ts +143 -18
- package/script/src/resources/hosts.d.ts.map +1 -1
- package/script/src/resources/hosts.js +146 -10
- package/script/src/resources/logs.d.ts +39 -0
- package/script/src/resources/logs.d.ts.map +1 -0
- package/script/src/resources/logs.js +42 -0
- package/script/src/resources/nodes.d.ts +106 -41
- package/script/src/resources/nodes.d.ts.map +1 -1
- package/script/src/resources/nodes.js +122 -28
- package/script/src/resources/permissions.d.ts +45 -0
- package/script/src/resources/permissions.d.ts.map +1 -0
- package/script/src/resources/permissions.js +31 -0
- package/script/src/resources/request-logs.d.ts +91 -0
- package/script/src/resources/request-logs.d.ts.map +1 -0
- package/script/src/resources/request-logs.js +75 -0
- package/script/src/resources/roles.d.ts +128 -0
- package/script/src/resources/roles.d.ts.map +1 -0
- package/script/src/resources/roles.js +148 -0
- package/script/src/resources/server-groups.d.ts +141 -7
- package/script/src/resources/server-groups.d.ts.map +1 -1
- package/script/src/resources/server-groups.js +158 -8
- package/script/src/resources/servers/activity.d.ts +50 -8
- package/script/src/resources/servers/activity.d.ts.map +1 -1
- package/script/src/resources/servers/activity.js +54 -12
- package/script/src/resources/servers/allocations.d.ts +3 -3
- package/script/src/resources/servers/allocations.d.ts.map +1 -1
- package/script/src/resources/servers/allocations.js +7 -7
- package/script/src/resources/servers/backups.d.ts +46 -0
- package/script/src/resources/servers/backups.d.ts.map +1 -0
- package/script/src/resources/servers/backups.js +47 -0
- package/script/src/resources/servers/connection.d.ts +27 -7
- package/script/src/resources/servers/connection.d.ts.map +1 -1
- package/script/src/resources/servers/connection.js +28 -7
- package/script/src/resources/servers/features.d.ts +81 -0
- package/script/src/resources/servers/features.d.ts.map +1 -0
- package/script/src/resources/servers/features.js +64 -0
- package/script/src/resources/servers/files.d.ts +41 -53
- package/script/src/resources/servers/files.d.ts.map +1 -1
- package/script/src/resources/servers/files.js +74 -116
- package/script/src/resources/servers/index.d.ts +46 -27
- package/script/src/resources/servers/index.d.ts.map +1 -1
- package/script/src/resources/servers/index.js +26 -12
- package/script/src/resources/servers/jobs.d.ts +88 -0
- package/script/src/resources/servers/jobs.d.ts.map +1 -0
- package/script/src/resources/servers/jobs.js +120 -0
- package/script/src/resources/servers/node-client.d.ts +33 -0
- package/script/src/resources/servers/node-client.d.ts.map +1 -0
- package/script/src/resources/servers/node-client.js +65 -0
- package/script/src/resources/servers/profiles.d.ts +45 -1
- package/script/src/resources/servers/profiles.d.ts.map +1 -1
- package/script/src/resources/servers/profiles.js +55 -2
- package/script/src/resources/servers/server.d.ts +10 -25
- package/script/src/resources/servers/server.d.ts.map +1 -1
- package/script/src/resources/servers/server.js +18 -34
- package/script/src/resources/servers/sftp.d.ts +21 -19
- package/script/src/resources/servers/sftp.d.ts.map +1 -1
- package/script/src/resources/servers/sftp.js +22 -14
- package/script/src/resources/servers/sub-users.d.ts +99 -0
- package/script/src/resources/servers/sub-users.d.ts.map +1 -0
- package/script/src/resources/servers/sub-users.js +99 -0
- package/script/src/resources/servers/types.d.ts +27 -25
- package/script/src/resources/servers/types.d.ts.map +1 -1
- package/script/src/resources/systems.d.ts +124 -0
- package/script/src/resources/systems.d.ts.map +1 -0
- package/script/src/resources/systems.js +145 -0
- package/script/src/resources/users.d.ts +330 -0
- package/script/src/resources/users.d.ts.map +1 -0
- package/script/src/resources/users.js +287 -0
- package/script/src/types.d.ts +18 -1
- package/script/src/types.d.ts.map +1 -1
- package/script/src/types.js +12 -0
- package/esm/src/resources/members.d.ts +0 -138
- package/esm/src/resources/members.d.ts.map +0 -1
- package/esm/src/resources/members.js +0 -122
- package/script/src/resources/members.d.ts +0 -138
- package/script/src/resources/members.d.ts.map +0 -1
- package/script/src/resources/members.js +0 -127
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { HttpClient } from '../../http.js';
|
|
2
|
+
import type { NanoID } from '../../types.js';
|
|
3
|
+
/** Where a feature's availability comes from, resolved most-specific-wins. */
|
|
4
|
+
export type FeatureSource = 'server' | 'egg' | 'node';
|
|
5
|
+
/** Where an effective setting value comes from. `server` is a client override, `feature` is the default. */
|
|
6
|
+
export type FeatureSettingSource = 'server' | 'feature';
|
|
7
|
+
/** One resolved setting of an effective feature. */
|
|
8
|
+
export interface FeatureSetting {
|
|
9
|
+
/** The effective resolved value. */
|
|
10
|
+
value: unknown;
|
|
11
|
+
/** Whether the value is a client override (`server`) or the feature default (`feature`). */
|
|
12
|
+
source: FeatureSettingSource;
|
|
13
|
+
/** The feature's code-defined default for this setting. */
|
|
14
|
+
default: unknown;
|
|
15
|
+
}
|
|
16
|
+
/** A feature as it applies to a specific server, with its resolved settings. */
|
|
17
|
+
export interface EffectiveFeature {
|
|
18
|
+
/** The feature key, e.g. `"minecraft.players"`. */
|
|
19
|
+
name: string;
|
|
20
|
+
/** Whether the feature is enabled for this server. */
|
|
21
|
+
enabled: boolean;
|
|
22
|
+
/** When `true`, the enabled state is fixed and cannot be toggled. */
|
|
23
|
+
locked: boolean;
|
|
24
|
+
/** Where the feature's availability is granted from. */
|
|
25
|
+
source: FeatureSource;
|
|
26
|
+
/** The selected variant, or `null` when the feature has none. */
|
|
27
|
+
variant: string | null;
|
|
28
|
+
/** Resolved settings, keyed by setting name. */
|
|
29
|
+
settings: Record<string, FeatureSetting>;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Manages the feature configuration of a specific server.
|
|
33
|
+
*
|
|
34
|
+
* Access via `server.features`.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts ignore
|
|
38
|
+
* const features = await server.features.list();
|
|
39
|
+
* await server.features.setEnabled('minecraft.players', true);
|
|
40
|
+
* await server.features.update('minecraft.players', { settings: { show_players_online: false } });
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare class ServerFeaturesManager {
|
|
44
|
+
private readonly serverId;
|
|
45
|
+
private readonly http;
|
|
46
|
+
/** @internal */
|
|
47
|
+
constructor(serverId: NanoID, http: HttpClient);
|
|
48
|
+
/** List the features available to this server, with their resolved state. */
|
|
49
|
+
list(): Promise<EffectiveFeature[]>;
|
|
50
|
+
/**
|
|
51
|
+
* Fetch a single feature's resolved state.
|
|
52
|
+
*
|
|
53
|
+
* @throws {@link ApiError} with `isNotFound === true` if the feature is not available to the server.
|
|
54
|
+
*/
|
|
55
|
+
get(feature: string): Promise<EffectiveFeature>;
|
|
56
|
+
/**
|
|
57
|
+
* Update a feature's settings or variant.
|
|
58
|
+
*
|
|
59
|
+
* A `null` setting value, or a `null` variant, resets it to the feature default.
|
|
60
|
+
*
|
|
61
|
+
* @param feature The feature key.
|
|
62
|
+
* @param payload The settings and/or variant to change.
|
|
63
|
+
*/
|
|
64
|
+
update(feature: string, payload: {
|
|
65
|
+
settings?: Record<string, unknown>;
|
|
66
|
+
variant?: string | null;
|
|
67
|
+
}): Promise<EffectiveFeature>;
|
|
68
|
+
/**
|
|
69
|
+
* Enable or disable a feature.
|
|
70
|
+
*
|
|
71
|
+
* @throws {@link ApiError} with `isForbidden === true` if the feature is locked.
|
|
72
|
+
*/
|
|
73
|
+
setEnabled(feature: string, enabled: boolean): Promise<EffectiveFeature>;
|
|
74
|
+
/**
|
|
75
|
+
* Enable or disable several features at once.
|
|
76
|
+
*
|
|
77
|
+
* @param features A map of feature key to desired enabled state.
|
|
78
|
+
*/
|
|
79
|
+
setEnabledBulk(features: Record<string, boolean>): Promise<EffectiveFeature[]>;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=features.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features.d.ts","sourceRoot":"","sources":["../../../../src/src/resources/servers/features.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAE7C,8EAA8E;AAC9E,MAAM,MAAM,aAAa,GAAG,QAAQ,GAAG,KAAK,GAAG,MAAM,CAAC;AAEtD,4GAA4G;AAC5G,MAAM,MAAM,oBAAoB,GAAG,QAAQ,GAAG,SAAS,CAAC;AAExD,oDAAoD;AACpD,MAAM,WAAW,cAAc;IAC9B,oCAAoC;IACpC,KAAK,EAAE,OAAO,CAAC;IACf,4FAA4F;IAC5F,MAAM,EAAE,oBAAoB,CAAC;IAC7B,2DAA2D;IAC3D,OAAO,EAAE,OAAO,CAAC;CACjB;AAED,gFAAgF;AAChF,MAAM,WAAW,gBAAgB;IAChC,mDAAmD;IACnD,IAAI,EAAE,MAAM,CAAC;IACb,sDAAsD;IACtD,OAAO,EAAE,OAAO,CAAC;IACjB,qEAAqE;IACrE,MAAM,EAAE,OAAO,CAAC;IAChB,wDAAwD;IACxD,MAAM,EAAE,aAAa,CAAC;IACtB,iEAAiE;IACjE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,gDAAgD;IAChD,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;CACzC;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,qBAAqB;IAGhC,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,IAAI;IAHtB,gBAAgB;gBAEE,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,UAAU;IAGlC,6EAA6E;IACtE,IAAI,IAAI,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAI1C;;;;OAIG;IACI,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAItD;;;;;;;OAOG;IACI,MAAM,CACZ,OAAO,EAAE,MAAM,EACf,OAAO,EAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,GACtE,OAAO,CAAC,gBAAgB,CAAC;IAO5B;;;;OAIG;IACI,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAO/E;;;;OAIG;IACI,cAAc,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC;CAGrF"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ServerFeaturesManager = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Manages the feature configuration of a specific server.
|
|
6
|
+
*
|
|
7
|
+
* Access via `server.features`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts ignore
|
|
11
|
+
* const features = await server.features.list();
|
|
12
|
+
* await server.features.setEnabled('minecraft.players', true);
|
|
13
|
+
* await server.features.update('minecraft.players', { settings: { show_players_online: false } });
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
class ServerFeaturesManager {
|
|
17
|
+
serverId;
|
|
18
|
+
http;
|
|
19
|
+
/** @internal */
|
|
20
|
+
constructor(serverId, http) {
|
|
21
|
+
this.serverId = serverId;
|
|
22
|
+
this.http = http;
|
|
23
|
+
}
|
|
24
|
+
/** List the features available to this server, with their resolved state. */
|
|
25
|
+
list() {
|
|
26
|
+
return this.http.get(`/servers/${this.serverId}/features`);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Fetch a single feature's resolved state.
|
|
30
|
+
*
|
|
31
|
+
* @throws {@link ApiError} with `isNotFound === true` if the feature is not available to the server.
|
|
32
|
+
*/
|
|
33
|
+
get(feature) {
|
|
34
|
+
return this.http.get(`/servers/${this.serverId}/features/${encodeURIComponent(feature)}`);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Update a feature's settings or variant.
|
|
38
|
+
*
|
|
39
|
+
* A `null` setting value, or a `null` variant, resets it to the feature default.
|
|
40
|
+
*
|
|
41
|
+
* @param feature The feature key.
|
|
42
|
+
* @param payload The settings and/or variant to change.
|
|
43
|
+
*/
|
|
44
|
+
update(feature, payload) {
|
|
45
|
+
return this.http.patch(`/servers/${this.serverId}/features/${encodeURIComponent(feature)}`, payload);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Enable or disable a feature.
|
|
49
|
+
*
|
|
50
|
+
* @throws {@link ApiError} with `isForbidden === true` if the feature is locked.
|
|
51
|
+
*/
|
|
52
|
+
setEnabled(feature, enabled) {
|
|
53
|
+
return this.http.post(`/servers/${this.serverId}/features/${encodeURIComponent(feature)}`, { enabled });
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Enable or disable several features at once.
|
|
57
|
+
*
|
|
58
|
+
* @param features A map of feature key to desired enabled state.
|
|
59
|
+
*/
|
|
60
|
+
setEnabledBulk(features) {
|
|
61
|
+
return this.http.post(`/servers/${this.serverId}/features`, { features });
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.ServerFeaturesManager = ServerFeaturesManager;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ServerJob } from './jobs.js';
|
|
2
|
+
import type { NodeClient } from './node-client.js';
|
|
2
3
|
import type { FileEntryData } from './types.js';
|
|
3
4
|
/**
|
|
4
5
|
* A single file or directory entry in a server's file system.
|
|
@@ -26,58 +27,42 @@ export declare class FileEntry {
|
|
|
26
27
|
constructor(data: FileEntryData);
|
|
27
28
|
}
|
|
28
29
|
/**
|
|
29
|
-
* Manages file system operations for a specific server via the Whisker node daemon
|
|
30
|
+
* Manages file system operations for a specific server via the Whisker node daemon.
|
|
30
31
|
*
|
|
31
|
-
* File operations communicate directly with the node daemon.
|
|
32
|
-
*
|
|
32
|
+
* File operations communicate directly with the node daemon. Archive operations
|
|
33
|
+
* (`compress`/`decompress`) may run as a background {@link ServerJob} when they exceed
|
|
34
|
+
* the daemon's fast-path window.
|
|
33
35
|
*
|
|
34
36
|
* @example
|
|
35
37
|
* ```ts ignore
|
|
36
38
|
* const entries = await server.files.list('/');
|
|
37
|
-
*
|
|
38
|
-
* await server.files.
|
|
39
|
-
*
|
|
40
|
-
* await server.files.delete(['/backup.zip']);
|
|
39
|
+
* await server.files.write('/motd.txt', 'Hello World');
|
|
40
|
+
* const result = await server.files.compress(['/world'], '/');
|
|
41
|
+
* if (result instanceof ServerJob) await result.wait();
|
|
41
42
|
* ```
|
|
42
43
|
*/
|
|
43
44
|
export declare class ServerFilesManager {
|
|
44
|
-
private readonly
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
* @param serverId The server's NanoID.
|
|
50
|
-
* @param token Bearer token for node authentication.
|
|
51
|
-
* @param resolveNodeUrl Async function that returns the daemon base URL for this server's node.
|
|
52
|
-
*/
|
|
53
|
-
constructor(serverId: NanoID, token: string, resolveNodeUrl: () => Promise<string>);
|
|
54
|
-
/** Lazily resolve and cache the node daemon URL. */
|
|
55
|
-
private getNodeUrl;
|
|
56
|
-
/** Build a full node API URL for a file path endpoint. */
|
|
57
|
-
private buildFileUrl;
|
|
58
|
-
/** Shared auth headers for node requests. */
|
|
59
|
-
private get authHeaders();
|
|
60
|
-
/** Perform a raw fetch to the node and throw on non-2xx. */
|
|
61
|
-
private nodeFetch;
|
|
45
|
+
private readonly node;
|
|
46
|
+
/** @internal */
|
|
47
|
+
constructor(node: NodeClient);
|
|
48
|
+
/** Normalize a path to an absolute `/files` endpoint. */
|
|
49
|
+
private endpoint;
|
|
62
50
|
/**
|
|
63
51
|
* List the contents of a directory.
|
|
64
52
|
*
|
|
65
53
|
* @param path Absolute path to the directory, e.g. `"/"` or `"/plugins"`.
|
|
66
|
-
* @returns An array of {@link FileEntry} objects.
|
|
67
54
|
*/
|
|
68
55
|
list(path: string): Promise<FileEntry[]>;
|
|
69
56
|
/**
|
|
70
57
|
* Read the text content of a file.
|
|
71
58
|
*
|
|
72
59
|
* @param path Absolute path to the file, e.g. `"/server.properties"`.
|
|
73
|
-
* @returns The file content as a UTF-8 string.
|
|
74
60
|
*/
|
|
75
61
|
read(path: string): Promise<string>;
|
|
76
62
|
/**
|
|
77
63
|
* Read the raw binary content of a file.
|
|
78
64
|
*
|
|
79
65
|
* @param path Absolute path to the file.
|
|
80
|
-
* @returns The file content as an `ArrayBuffer`.
|
|
81
66
|
*/
|
|
82
67
|
readBinary(path: string): Promise<ArrayBuffer>;
|
|
83
68
|
/**
|
|
@@ -106,56 +91,59 @@ export declare class ServerFilesManager {
|
|
|
106
91
|
*
|
|
107
92
|
* @param from Absolute source path.
|
|
108
93
|
* @param to Absolute destination path.
|
|
94
|
+
* @param root Root directory for resolving relative paths. Defaults to `"/"`.
|
|
109
95
|
*/
|
|
110
|
-
move(from: string, to: string): Promise<void>;
|
|
96
|
+
move(from: string, to: string, root?: string): Promise<void>;
|
|
111
97
|
/**
|
|
112
|
-
* Copy a file or directory to a new
|
|
98
|
+
* Copy a file or directory to a new path.
|
|
113
99
|
*
|
|
114
|
-
* @param
|
|
115
|
-
* @param
|
|
100
|
+
* @param from Absolute source path.
|
|
101
|
+
* @param to Absolute destination path.
|
|
102
|
+
* @param root Root directory for resolving relative paths. Defaults to `"/"`.
|
|
116
103
|
*/
|
|
117
|
-
copy(
|
|
104
|
+
copy(from: string, to: string, root?: string): Promise<void>;
|
|
118
105
|
/**
|
|
119
106
|
* Create an empty file or directory.
|
|
120
107
|
*
|
|
121
108
|
* @param path Absolute path of the new file or directory.
|
|
122
109
|
* @param directory When `true`, creates a directory instead of a file.
|
|
110
|
+
* @param root Root directory for resolving relative paths. Defaults to `"/"`.
|
|
123
111
|
*/
|
|
124
|
-
create(path: string, directory?: boolean): Promise<void>;
|
|
112
|
+
create(path: string, directory?: boolean, root?: string): Promise<void>;
|
|
125
113
|
/**
|
|
126
|
-
* Compress one or more
|
|
114
|
+
* Compress one or more paths into a server-named archive.
|
|
115
|
+
*
|
|
116
|
+
* Resolves to a {@link FileEntry} for the created archive when the daemon finishes
|
|
117
|
+
* within its fast-path window, or a {@link ServerJob} to track when it runs longer.
|
|
127
118
|
*
|
|
128
|
-
* @param
|
|
129
|
-
* @param
|
|
130
|
-
* @param rootPath Root directory for resolving relative paths. Defaults to `"/"`.
|
|
119
|
+
* @param paths Absolute paths to include in the archive.
|
|
120
|
+
* @param root Root directory for resolving the paths. Defaults to `"/"`.
|
|
131
121
|
*/
|
|
132
|
-
compress(
|
|
122
|
+
compress(paths: string[], root?: string): Promise<FileEntry | ServerJob>;
|
|
133
123
|
/**
|
|
134
124
|
* Decompress (extract) an archive file.
|
|
135
125
|
*
|
|
136
|
-
*
|
|
137
|
-
* @
|
|
126
|
+
* Resolves to `null` when the daemon finishes within its fast-path window, or a
|
|
127
|
+
* {@link ServerJob} to track when it runs longer.
|
|
128
|
+
*
|
|
129
|
+
* @param path Absolute path to the archive to extract.
|
|
130
|
+
* @param root Directory to extract the archive into. Defaults to `"/"`.
|
|
138
131
|
*/
|
|
139
|
-
decompress(
|
|
132
|
+
decompress(path: string, root?: string): Promise<ServerJob | null>;
|
|
140
133
|
/**
|
|
141
134
|
* Change the permissions (chmod) of one or more files.
|
|
142
135
|
*
|
|
143
|
-
* @param entries
|
|
144
|
-
* @param
|
|
145
|
-
*
|
|
146
|
-
* @example
|
|
147
|
-
* ```ts ignore
|
|
148
|
-
* await server.files.chmod([{ file: 'start.sh', mode: '755' }]);
|
|
149
|
-
* ```
|
|
136
|
+
* @param entries Array of `{ file, mode }` objects, e.g. `[{ file: 'start.sh', mode: '755' }]`.
|
|
137
|
+
* @param root Root directory for resolving paths. Defaults to `"/"`.
|
|
150
138
|
*/
|
|
151
139
|
chmod(entries: {
|
|
152
140
|
file: string;
|
|
153
141
|
mode: string;
|
|
154
|
-
}[],
|
|
142
|
+
}[], root?: string): Promise<void>;
|
|
155
143
|
/**
|
|
156
|
-
* Upload a file
|
|
144
|
+
* Upload a file using multipart form data.
|
|
157
145
|
*
|
|
158
|
-
* @param path Absolute directory path to upload
|
|
146
|
+
* @param path Absolute directory path to upload into.
|
|
159
147
|
* @param filename The name for the uploaded file.
|
|
160
148
|
* @param content The file content as a `Blob`, `File`, or `ArrayBuffer`.
|
|
161
149
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../../../../src/src/resources/servers/files.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../../../../src/src/resources/servers/files.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ServerFilesManager = exports.FileEntry = void 0;
|
|
4
|
-
const
|
|
4
|
+
const jobs_js_1 = require("./jobs.js");
|
|
5
5
|
/**
|
|
6
6
|
* A single file or directory entry in a server's file system.
|
|
7
7
|
*/
|
|
@@ -39,77 +39,37 @@ class FileEntry {
|
|
|
39
39
|
}
|
|
40
40
|
exports.FileEntry = FileEntry;
|
|
41
41
|
/**
|
|
42
|
-
* Manages file system operations for a specific server via the Whisker node daemon
|
|
42
|
+
* Manages file system operations for a specific server via the Whisker node daemon.
|
|
43
43
|
*
|
|
44
|
-
* File operations communicate directly with the node daemon.
|
|
45
|
-
*
|
|
44
|
+
* File operations communicate directly with the node daemon. Archive operations
|
|
45
|
+
* (`compress`/`decompress`) may run as a background {@link ServerJob} when they exceed
|
|
46
|
+
* the daemon's fast-path window.
|
|
46
47
|
*
|
|
47
48
|
* @example
|
|
48
49
|
* ```ts ignore
|
|
49
50
|
* const entries = await server.files.list('/');
|
|
50
|
-
*
|
|
51
|
-
* await server.files.
|
|
52
|
-
*
|
|
53
|
-
* await server.files.delete(['/backup.zip']);
|
|
51
|
+
* await server.files.write('/motd.txt', 'Hello World');
|
|
52
|
+
* const result = await server.files.compress(['/world'], '/');
|
|
53
|
+
* if (result instanceof ServerJob) await result.wait();
|
|
54
54
|
* ```
|
|
55
55
|
*/
|
|
56
56
|
class ServerFilesManager {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* @param serverId The server's NanoID.
|
|
63
|
-
* @param token Bearer token for node authentication.
|
|
64
|
-
* @param resolveNodeUrl Async function that returns the daemon base URL for this server's node.
|
|
65
|
-
*/
|
|
66
|
-
constructor(serverId, token, resolveNodeUrl) {
|
|
67
|
-
this.serverId = serverId;
|
|
68
|
-
this.token = token;
|
|
69
|
-
this.resolveNodeUrl = resolveNodeUrl;
|
|
70
|
-
}
|
|
71
|
-
/** Lazily resolve and cache the node daemon URL. */
|
|
72
|
-
async getNodeUrl() {
|
|
73
|
-
if (!this.nodeUrl)
|
|
74
|
-
this.nodeUrl = await this.resolveNodeUrl();
|
|
75
|
-
return this.nodeUrl;
|
|
76
|
-
}
|
|
77
|
-
/** Build a full node API URL for a file path endpoint. */
|
|
78
|
-
async buildFileUrl(endpoint) {
|
|
79
|
-
const base = await this.getNodeUrl();
|
|
80
|
-
return `${base}/api/servers/${this.serverId}/files${endpoint}`;
|
|
81
|
-
}
|
|
82
|
-
/** Shared auth headers for node requests. */
|
|
83
|
-
get authHeaders() {
|
|
84
|
-
return { 'Authorization': `Bearer ${this.token}` };
|
|
57
|
+
node;
|
|
58
|
+
/** @internal */
|
|
59
|
+
constructor(node) {
|
|
60
|
+
this.node = node;
|
|
85
61
|
}
|
|
86
|
-
/**
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
...init,
|
|
90
|
-
headers: { ...this.authHeaders, ...init.headers },
|
|
91
|
-
});
|
|
92
|
-
if (!res.ok) {
|
|
93
|
-
let message = `HTTP ${res.status}`;
|
|
94
|
-
try {
|
|
95
|
-
const body = await res.json();
|
|
96
|
-
if (typeof body.error === 'string')
|
|
97
|
-
message = body.error;
|
|
98
|
-
}
|
|
99
|
-
catch { /* ignore */ }
|
|
100
|
-
throw new errors_js_1.ApiError({ message, status: res.status });
|
|
101
|
-
}
|
|
102
|
-
return res;
|
|
62
|
+
/** Normalize a path to an absolute `/files` endpoint. */
|
|
63
|
+
endpoint(path) {
|
|
64
|
+
return '/files' + (path.startsWith('/') ? path : `/${path}`);
|
|
103
65
|
}
|
|
104
66
|
/**
|
|
105
67
|
* List the contents of a directory.
|
|
106
68
|
*
|
|
107
69
|
* @param path Absolute path to the directory, e.g. `"/"` or `"/plugins"`.
|
|
108
|
-
* @returns An array of {@link FileEntry} objects.
|
|
109
70
|
*/
|
|
110
71
|
async list(path) {
|
|
111
|
-
const
|
|
112
|
-
const res = await this.nodeFetch(url);
|
|
72
|
+
const res = await this.node.fetch(this.endpoint(path));
|
|
113
73
|
const data = await res.json();
|
|
114
74
|
return data.map((e) => new FileEntry(e));
|
|
115
75
|
}
|
|
@@ -117,22 +77,18 @@ class ServerFilesManager {
|
|
|
117
77
|
* Read the text content of a file.
|
|
118
78
|
*
|
|
119
79
|
* @param path Absolute path to the file, e.g. `"/server.properties"`.
|
|
120
|
-
* @returns The file content as a UTF-8 string.
|
|
121
80
|
*/
|
|
122
81
|
async read(path) {
|
|
123
|
-
const
|
|
124
|
-
const res = await this.nodeFetch(url);
|
|
82
|
+
const res = await this.node.fetch(this.endpoint(path));
|
|
125
83
|
return res.text();
|
|
126
84
|
}
|
|
127
85
|
/**
|
|
128
86
|
* Read the raw binary content of a file.
|
|
129
87
|
*
|
|
130
88
|
* @param path Absolute path to the file.
|
|
131
|
-
* @returns The file content as an `ArrayBuffer`.
|
|
132
89
|
*/
|
|
133
90
|
async readBinary(path) {
|
|
134
|
-
const
|
|
135
|
-
const res = await this.nodeFetch(url);
|
|
91
|
+
const res = await this.node.fetch(this.endpoint(path));
|
|
136
92
|
return res.arrayBuffer();
|
|
137
93
|
}
|
|
138
94
|
/**
|
|
@@ -142,8 +98,7 @@ class ServerFilesManager {
|
|
|
142
98
|
* @param content The UTF-8 text content to write.
|
|
143
99
|
*/
|
|
144
100
|
async write(path, content) {
|
|
145
|
-
|
|
146
|
-
await this.nodeFetch(url, {
|
|
101
|
+
await this.node.fetch(this.endpoint(path), {
|
|
147
102
|
method: 'PUT',
|
|
148
103
|
body: content,
|
|
149
104
|
headers: { 'Content-Type': 'text/plain' },
|
|
@@ -157,9 +112,8 @@ class ServerFilesManager {
|
|
|
157
112
|
* @param contentType MIME type of the content.
|
|
158
113
|
*/
|
|
159
114
|
async writeBinary(path, content, contentType) {
|
|
160
|
-
const url = await this.buildFileUrl(path.startsWith('/') ? path : `/${path}`);
|
|
161
115
|
const body = content instanceof ArrayBuffer ? new Uint8Array(content) : content;
|
|
162
|
-
await this.
|
|
116
|
+
await this.node.fetch(this.endpoint(path), {
|
|
163
117
|
method: 'PUT',
|
|
164
118
|
body: body,
|
|
165
119
|
headers: { 'Content-Type': contentType },
|
|
@@ -171,38 +125,33 @@ class ServerFilesManager {
|
|
|
171
125
|
* @param paths An array of absolute paths to delete.
|
|
172
126
|
*/
|
|
173
127
|
async delete(paths) {
|
|
174
|
-
|
|
175
|
-
await this.nodeFetch(url, {
|
|
176
|
-
method: 'DELETE',
|
|
177
|
-
body: JSON.stringify({ root: '/', files: paths }),
|
|
178
|
-
headers: { 'Content-Type': 'application/json' },
|
|
179
|
-
});
|
|
128
|
+
await Promise.all(paths.map((p) => this.node.fetch(this.endpoint(p), { method: 'DELETE' })));
|
|
180
129
|
}
|
|
181
130
|
/**
|
|
182
131
|
* Move (rename) a file or directory.
|
|
183
132
|
*
|
|
184
133
|
* @param from Absolute source path.
|
|
185
134
|
* @param to Absolute destination path.
|
|
135
|
+
* @param root Root directory for resolving relative paths. Defaults to `"/"`.
|
|
186
136
|
*/
|
|
187
|
-
async move(from, to) {
|
|
188
|
-
|
|
189
|
-
await this.nodeFetch(url, {
|
|
137
|
+
async move(from, to, root = '/') {
|
|
138
|
+
await this.node.fetch('/files/move', {
|
|
190
139
|
method: 'POST',
|
|
191
|
-
body: JSON.stringify({
|
|
140
|
+
body: JSON.stringify({ root, Paths: { [from]: to } }),
|
|
192
141
|
headers: { 'Content-Type': 'application/json' },
|
|
193
142
|
});
|
|
194
143
|
}
|
|
195
144
|
/**
|
|
196
|
-
* Copy a file or directory to a new
|
|
145
|
+
* Copy a file or directory to a new path.
|
|
197
146
|
*
|
|
198
|
-
* @param
|
|
199
|
-
* @param
|
|
147
|
+
* @param from Absolute source path.
|
|
148
|
+
* @param to Absolute destination path.
|
|
149
|
+
* @param root Root directory for resolving relative paths. Defaults to `"/"`.
|
|
200
150
|
*/
|
|
201
|
-
async copy(
|
|
202
|
-
|
|
203
|
-
await this.nodeFetch(url, {
|
|
151
|
+
async copy(from, to, root = '/') {
|
|
152
|
+
await this.node.fetch('/files/copy', {
|
|
204
153
|
method: 'POST',
|
|
205
|
-
body: JSON.stringify({
|
|
154
|
+
body: JSON.stringify({ root, Paths: { [from]: to } }),
|
|
206
155
|
headers: { 'Content-Type': 'application/json' },
|
|
207
156
|
});
|
|
208
157
|
}
|
|
@@ -211,76 +160,85 @@ class ServerFilesManager {
|
|
|
211
160
|
*
|
|
212
161
|
* @param path Absolute path of the new file or directory.
|
|
213
162
|
* @param directory When `true`, creates a directory instead of a file.
|
|
163
|
+
* @param root Root directory for resolving relative paths. Defaults to `"/"`.
|
|
214
164
|
*/
|
|
215
|
-
async create(path, directory = false) {
|
|
216
|
-
|
|
217
|
-
await this.nodeFetch(url, {
|
|
165
|
+
async create(path, directory = false, root = '/') {
|
|
166
|
+
await this.node.fetch('/files/create', {
|
|
218
167
|
method: 'POST',
|
|
219
|
-
body: JSON.stringify({
|
|
168
|
+
body: JSON.stringify({ root, Paths: { [path]: { type: directory ? 'directory' : 'file' } } }),
|
|
220
169
|
headers: { 'Content-Type': 'application/json' },
|
|
221
170
|
});
|
|
222
171
|
}
|
|
223
172
|
/**
|
|
224
|
-
* Compress one or more
|
|
173
|
+
* Compress one or more paths into a server-named archive.
|
|
174
|
+
*
|
|
175
|
+
* Resolves to a {@link FileEntry} for the created archive when the daemon finishes
|
|
176
|
+
* within its fast-path window, or a {@link ServerJob} to track when it runs longer.
|
|
225
177
|
*
|
|
226
|
-
* @param
|
|
227
|
-
* @param
|
|
228
|
-
* @param rootPath Root directory for resolving relative paths. Defaults to `"/"`.
|
|
178
|
+
* @param paths Absolute paths to include in the archive.
|
|
179
|
+
* @param root Root directory for resolving the paths. Defaults to `"/"`.
|
|
229
180
|
*/
|
|
230
|
-
async compress(
|
|
231
|
-
const
|
|
232
|
-
await this.nodeFetch(url, {
|
|
181
|
+
async compress(paths, root = '/') {
|
|
182
|
+
const res = await this.node.fetch('/files/compress', {
|
|
233
183
|
method: 'POST',
|
|
234
|
-
body: JSON.stringify({
|
|
184
|
+
body: JSON.stringify({ root, paths }),
|
|
235
185
|
headers: { 'Content-Type': 'application/json' },
|
|
236
186
|
});
|
|
187
|
+
if (res.status === 202) {
|
|
188
|
+
const { job_id } = await res.json();
|
|
189
|
+
return new jobs_js_1.ServerJob({ id: job_id }, this.node);
|
|
190
|
+
}
|
|
191
|
+
return new FileEntry(await res.json());
|
|
237
192
|
}
|
|
238
193
|
/**
|
|
239
194
|
* Decompress (extract) an archive file.
|
|
240
195
|
*
|
|
241
|
-
*
|
|
242
|
-
* @
|
|
196
|
+
* Resolves to `null` when the daemon finishes within its fast-path window, or a
|
|
197
|
+
* {@link ServerJob} to track when it runs longer.
|
|
198
|
+
*
|
|
199
|
+
* @param path Absolute path to the archive to extract.
|
|
200
|
+
* @param root Directory to extract the archive into. Defaults to `"/"`.
|
|
243
201
|
*/
|
|
244
|
-
async decompress(
|
|
245
|
-
const
|
|
246
|
-
await this.nodeFetch(url, {
|
|
202
|
+
async decompress(path, root = '/') {
|
|
203
|
+
const res = await this.node.fetch('/files/decompress', {
|
|
247
204
|
method: 'POST',
|
|
248
|
-
body: JSON.stringify({
|
|
205
|
+
body: JSON.stringify({ root, path }),
|
|
249
206
|
headers: { 'Content-Type': 'application/json' },
|
|
250
207
|
});
|
|
208
|
+
if (res.status === 202) {
|
|
209
|
+
const { job_id } = await res.json();
|
|
210
|
+
return new jobs_js_1.ServerJob({ id: job_id }, this.node);
|
|
211
|
+
}
|
|
212
|
+
return null;
|
|
251
213
|
}
|
|
252
214
|
/**
|
|
253
215
|
* Change the permissions (chmod) of one or more files.
|
|
254
216
|
*
|
|
255
|
-
* @param entries
|
|
256
|
-
* @param
|
|
257
|
-
*
|
|
258
|
-
* @example
|
|
259
|
-
* ```ts ignore
|
|
260
|
-
* await server.files.chmod([{ file: 'start.sh', mode: '755' }]);
|
|
261
|
-
* ```
|
|
217
|
+
* @param entries Array of `{ file, mode }` objects, e.g. `[{ file: 'start.sh', mode: '755' }]`.
|
|
218
|
+
* @param root Root directory for resolving paths. Defaults to `"/"`.
|
|
262
219
|
*/
|
|
263
|
-
async chmod(entries,
|
|
264
|
-
const
|
|
265
|
-
|
|
220
|
+
async chmod(entries, root = '/') {
|
|
221
|
+
const paths = {};
|
|
222
|
+
for (const entry of entries)
|
|
223
|
+
paths[entry.file] = { mode: entry.mode };
|
|
224
|
+
await this.node.fetch('/files/chmod', {
|
|
266
225
|
method: 'POST',
|
|
267
|
-
body: JSON.stringify({
|
|
226
|
+
body: JSON.stringify({ root, paths }),
|
|
268
227
|
headers: { 'Content-Type': 'application/json' },
|
|
269
228
|
});
|
|
270
229
|
}
|
|
271
230
|
/**
|
|
272
|
-
* Upload a file
|
|
231
|
+
* Upload a file using multipart form data.
|
|
273
232
|
*
|
|
274
|
-
* @param path Absolute directory path to upload
|
|
233
|
+
* @param path Absolute directory path to upload into.
|
|
275
234
|
* @param filename The name for the uploaded file.
|
|
276
235
|
* @param content The file content as a `Blob`, `File`, or `ArrayBuffer`.
|
|
277
236
|
*/
|
|
278
237
|
async upload(path, filename, content) {
|
|
279
|
-
const url = await this.buildFileUrl(`/upload?directory=${encodeURIComponent(path)}`);
|
|
280
238
|
const form = new FormData();
|
|
281
239
|
const blob = content instanceof ArrayBuffer ? new Blob([content]) : content;
|
|
282
240
|
form.append('files', blob, filename);
|
|
283
|
-
await this.
|
|
241
|
+
await this.node.fetch(`/files/upload?directory=${encodeURIComponent(path)}`, { method: 'POST', body: form });
|
|
284
242
|
}
|
|
285
243
|
}
|
|
286
244
|
exports.ServerFilesManager = ServerFilesManager;
|