wispjs 2.4.0 → 3.0.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/dist/wisp_api/index.d.ts +6 -0
- package/dist/wisp_api/index.js +8 -0
- package/dist/wisp_socket/filesystem.d.ts +60 -0
- package/dist/wisp_socket/filesystem.js +97 -0
- package/dist/wisp_socket/git.d.ts +57 -0
- package/dist/wisp_socket/git.js +76 -0
- package/dist/wisp_socket/index.d.ts +37 -18
- package/dist/wisp_socket/index.js +102 -157
- package/dist/wisp_socket/pool.d.ts +192 -48
- package/dist/wisp_socket/pool.js +132 -33
- package/dist/wisp_socket/ws_adapter.d.ts +72 -0
- package/dist/wisp_socket/ws_adapter.js +130 -0
- package/package.json +5 -4
- package/.github/workflows/release.yml +0 -77
- package/tsconfig.json +0 -19
- package/wisp.ts +0 -43
- package/wisp_api/apis/allocations.ts +0 -71
- package/wisp_api/apis/audit_log.ts +0 -81
- package/wisp_api/apis/backups.ts +0 -168
- package/wisp_api/apis/databases.ts +0 -80
- package/wisp_api/apis/fastdl.ts +0 -22
- package/wisp_api/apis/filesystem.ts +0 -291
- package/wisp_api/apis/index.ts +0 -135
- package/wisp_api/apis/mods.ts +0 -53
- package/wisp_api/apis/schedules.ts +0 -270
- package/wisp_api/apis/servers.ts +0 -155
- package/wisp_api/apis/startup.ts +0 -65
- package/wisp_api/apis/subusers.ts +0 -159
- package/wisp_api/index.ts +0 -57
- package/wisp_socket/index.ts +0 -495
- package/wisp_socket/pool.ts +0 -369
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { WispAPICore } from "./index";
|
|
2
|
-
import type { PaginationData } from "./index";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* An Allocation object
|
|
6
|
-
*
|
|
7
|
-
* @internal
|
|
8
|
-
*/
|
|
9
|
-
export interface Allocation {
|
|
10
|
-
object: "allocation";
|
|
11
|
-
attributes: {
|
|
12
|
-
id: number;
|
|
13
|
-
/** Whether or not this Allocation is the primary one for the Server */
|
|
14
|
-
primary: boolean;
|
|
15
|
-
ip: string;
|
|
16
|
-
port: number;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* The response object from the GetAllocations call
|
|
22
|
-
*
|
|
23
|
-
* @remarks
|
|
24
|
-
* Used in {@link AllocationsAPI.List}
|
|
25
|
-
*
|
|
26
|
-
* @public
|
|
27
|
-
*/
|
|
28
|
-
export interface GetAllocationsResponse {
|
|
29
|
-
object: "list";
|
|
30
|
-
data: Allocation[];
|
|
31
|
-
meta: {
|
|
32
|
-
pagination: PaginationData;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Handles the listing and updating of a Server's IP/Port Allocations
|
|
38
|
-
*
|
|
39
|
-
* @public
|
|
40
|
-
*/
|
|
41
|
-
export class AllocationsAPI {
|
|
42
|
-
constructor(private core: WispAPICore) {}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Lists all Allocations for the Server
|
|
47
|
-
*
|
|
48
|
-
* @public
|
|
49
|
-
*/
|
|
50
|
-
async List(): Promise<GetAllocationsResponse> {
|
|
51
|
-
const response = await this.core.makeRequest("GET", "allocations");
|
|
52
|
-
const data: GetAllocationsResponse = await response.json()
|
|
53
|
-
|
|
54
|
-
return data;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Sets the new primary Allocation for the server
|
|
60
|
-
*
|
|
61
|
-
* @param id Allocation ID of the new primary allocation
|
|
62
|
-
*
|
|
63
|
-
* @public
|
|
64
|
-
*/
|
|
65
|
-
async Update(id: string): Promise<Allocation> {
|
|
66
|
-
const response = await this.core.makeRequest("PUT", `allocations/${id}`);
|
|
67
|
-
const data: Allocation = await response.json()
|
|
68
|
-
|
|
69
|
-
return data;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { WispAPICore } from "./index";
|
|
2
|
-
import type { PaginationData } from "./index";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Device information
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```json
|
|
9
|
-
* {
|
|
10
|
-
* "city_name": "Seattle",
|
|
11
|
-
* "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:120.0) Gecko/20100101 Firefox/120.0",
|
|
12
|
-
* "country_name": "US",
|
|
13
|
-
* "country_iso_code": "US"
|
|
14
|
-
* }
|
|
15
|
-
* ```
|
|
16
|
-
*
|
|
17
|
-
* @internal
|
|
18
|
-
*/
|
|
19
|
-
export interface Device {
|
|
20
|
-
city_name: string;
|
|
21
|
-
user_agent: string;
|
|
22
|
-
country_name: string;
|
|
23
|
-
country_iso_code: string;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// TODO: Fully define the audit log type
|
|
27
|
-
/**
|
|
28
|
-
* An Audit Log struct
|
|
29
|
-
*
|
|
30
|
-
* @internal
|
|
31
|
-
*/
|
|
32
|
-
export interface AuditLog {
|
|
33
|
-
object: "audit_log";
|
|
34
|
-
attributes: {
|
|
35
|
-
action: string;
|
|
36
|
-
subaction: string;
|
|
37
|
-
device: Device | undefined;
|
|
38
|
-
metadata: any;
|
|
39
|
-
created_at: string;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* The respones object from the GetAuditLogs call
|
|
45
|
-
*
|
|
46
|
-
* @remarks
|
|
47
|
-
* Used in {@link AuditLogsAPI.List}
|
|
48
|
-
*
|
|
49
|
-
* @public
|
|
50
|
-
*/
|
|
51
|
-
export interface GetAuditLogsResponse {
|
|
52
|
-
object: "list";
|
|
53
|
-
data: AuditLog[];
|
|
54
|
-
meta: {
|
|
55
|
-
pagination: PaginationData;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Interface that handles Listing of all Audit Logs
|
|
62
|
-
*
|
|
63
|
-
* @public
|
|
64
|
-
*/
|
|
65
|
-
export class AuditLogsAPI {
|
|
66
|
-
constructor(private core: WispAPICore) {}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
// TODO: Handle pagination
|
|
70
|
-
/**
|
|
71
|
-
* List all Audit Log events for the server
|
|
72
|
-
*
|
|
73
|
-
* @public
|
|
74
|
-
*/
|
|
75
|
-
async List(): Promise<GetAuditLogsResponse> {
|
|
76
|
-
const response = await this.core.makeRequest("GET", "audit-logs");
|
|
77
|
-
const data: GetAuditLogsResponse = await response.json();
|
|
78
|
-
|
|
79
|
-
return data;
|
|
80
|
-
}
|
|
81
|
-
}
|
package/wisp_api/apis/backups.ts
DELETED
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
import { WispAPICore } from "./index";
|
|
2
|
-
import type { PaginationData } from "./index";
|
|
3
|
-
import type { DownloadFileResponse } from "./filesystem";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* A Backup Object
|
|
7
|
-
* @example
|
|
8
|
-
* ```json
|
|
9
|
-
* {
|
|
10
|
-
* "object": "backup",
|
|
11
|
-
* "attributes": {
|
|
12
|
-
* "uuid": "26adeafc-74af-43fd-93a5-9afa0486b21b",
|
|
13
|
-
* "uuid_short": "26adeafc",
|
|
14
|
-
* "name": "test-1",
|
|
15
|
-
* "sha256_hash": "56d2965e9167c785647878a391dfe24460c3aa5e1111b385708094bd8837b487",
|
|
16
|
-
* "bytes": 3266448936,
|
|
17
|
-
* "locked": false,
|
|
18
|
-
* "creating": false,
|
|
19
|
-
* "created_at": "2023-11-28T08:37:39.000000Z"
|
|
20
|
-
* }
|
|
21
|
-
* }
|
|
22
|
-
* ```
|
|
23
|
-
*
|
|
24
|
-
* @internal
|
|
25
|
-
*/
|
|
26
|
-
export interface Backup {
|
|
27
|
-
object: "backup";
|
|
28
|
-
attributes: {
|
|
29
|
-
uuid: string;
|
|
30
|
-
uuid_short: string;
|
|
31
|
-
name: string;
|
|
32
|
-
/** The hash of the Backup. May be null if the Backup is still being created. */
|
|
33
|
-
sha256_hash: string | null;
|
|
34
|
-
bytes: number;
|
|
35
|
-
locked: boolean;
|
|
36
|
-
creating: boolean;
|
|
37
|
-
created_at: string;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Response object used in the GetBackups call
|
|
43
|
-
*
|
|
44
|
-
* @remarks
|
|
45
|
-
* Used in {@link BackupsAPI.List}
|
|
46
|
-
*
|
|
47
|
-
* @internal
|
|
48
|
-
*/
|
|
49
|
-
export interface GetBackupsResponse {
|
|
50
|
-
object: "list";
|
|
51
|
-
data: Backup[];
|
|
52
|
-
meta: {
|
|
53
|
-
pagination: PaginationData;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export type BackupErrorCode = "server.backups.creation_would_exceed_limit";
|
|
58
|
-
export interface BackupError {
|
|
59
|
-
code: BackupErrorCode;
|
|
60
|
-
data: any;
|
|
61
|
-
}
|
|
62
|
-
export interface CreateBackupFailure {
|
|
63
|
-
errors: BackupError[] | undefined
|
|
64
|
-
}
|
|
65
|
-
export type CreateBackupResponse = Backup | CreateBackupFailure;
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Handles basic server backup tasks, such as creating, restoring, and deleting backups
|
|
69
|
-
*/
|
|
70
|
-
export class BackupsAPI {
|
|
71
|
-
constructor(private core: WispAPICore) {}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Lists all current backups for the server
|
|
75
|
-
*
|
|
76
|
-
* @public
|
|
77
|
-
*/
|
|
78
|
-
async List(): Promise<GetBackupsResponse> {
|
|
79
|
-
const response = await this.core.makeRequest("GET", "backups");
|
|
80
|
-
const data: GetBackupsResponse = await response.json();
|
|
81
|
-
|
|
82
|
-
return data;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Creates a new backup for the server
|
|
87
|
-
*
|
|
88
|
-
* @remarks
|
|
89
|
-
* ⚠️ This can fail to create a Backup even if the function completes successfully
|
|
90
|
-
* For example, if the backup would exceed the size limit (and the limit is not 0), the system wouldn't know it failed until it hit the limit.
|
|
91
|
-
*
|
|
92
|
-
* ⚠️ "It is recomended to stop your server before starting a backup. Backups created while the server is on can contain corupted data."
|
|
93
|
-
*
|
|
94
|
-
* Multiple Backups can exist with the same name.
|
|
95
|
-
*
|
|
96
|
-
* @param name The name of the Backup
|
|
97
|
-
*
|
|
98
|
-
* @throws {@link BackupErrorCode}
|
|
99
|
-
* If the server returns an error code, it will be thrown verbatim here
|
|
100
|
-
*
|
|
101
|
-
* @public
|
|
102
|
-
*/
|
|
103
|
-
async Create(name: string): Promise<CreateBackupResponse> {
|
|
104
|
-
const response = await this.core.makeRequest("POST", "backups", { name: name });
|
|
105
|
-
const data: CreateBackupResponse = await response.json()
|
|
106
|
-
|
|
107
|
-
if ("errors" in data && data.errors) {
|
|
108
|
-
throw new Error(data.errors[0].code);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return data
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Toggles the "Locked" status of the Backup
|
|
116
|
-
*
|
|
117
|
-
* @param id The ID of the Backup
|
|
118
|
-
*
|
|
119
|
-
* @public
|
|
120
|
-
*/
|
|
121
|
-
async ToggleLock(id: string): Promise<Backup> {
|
|
122
|
-
const response = await this.core.makeRequest("POST", `backups/${id}/locked`);
|
|
123
|
-
const data: Backup = await response.json();
|
|
124
|
-
|
|
125
|
-
return data;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Deploys the Backup to the Server
|
|
130
|
-
*
|
|
131
|
-
* @remarks
|
|
132
|
-
* **⚠️ This can be dangerous!**
|
|
133
|
-
* The Backup will overwrite the entire Server, erasing any new data since the Backup's creation
|
|
134
|
-
*
|
|
135
|
-
* @param id The ID of the Backup
|
|
136
|
-
*
|
|
137
|
-
* @public
|
|
138
|
-
*/
|
|
139
|
-
async Deploy(id: string): Promise<Response> {
|
|
140
|
-
return await this.core.makeRequest("POST", `backups/${id}/deploy`);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Retrieves a URL from which the Backup can be downloaded
|
|
145
|
-
*
|
|
146
|
-
* @param id The ID of the Backup
|
|
147
|
-
* @returns The download URL
|
|
148
|
-
*
|
|
149
|
-
* @public
|
|
150
|
-
*/
|
|
151
|
-
async GetDownloadURL(id: string): Promise<string> {
|
|
152
|
-
const response = await this.core.makeRequest("GET", `backups/${id}/download`);
|
|
153
|
-
const data: DownloadFileResponse = await response.json();
|
|
154
|
-
|
|
155
|
-
return data.url;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Deletes the Backup
|
|
160
|
-
*
|
|
161
|
-
* @param id The ID of the Backup
|
|
162
|
-
*
|
|
163
|
-
* @public
|
|
164
|
-
*/
|
|
165
|
-
async Delete(id: string): Promise<void> {
|
|
166
|
-
await this.core.makeRequest("DELETE", `backups/${id}`);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { WispAPICore } from "./index";
|
|
2
|
-
import type { PaginationData } from "./index";
|
|
3
|
-
|
|
4
|
-
export interface DatabaseRelationship {
|
|
5
|
-
object: "database_host";
|
|
6
|
-
attributes: {
|
|
7
|
-
id: number;
|
|
8
|
-
name: string;
|
|
9
|
-
host: string;
|
|
10
|
-
port: number;
|
|
11
|
-
phpmyadmin_url: string | null;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface Database {
|
|
16
|
-
object: "database";
|
|
17
|
-
attributes: {
|
|
18
|
-
id: number;
|
|
19
|
-
name: string;
|
|
20
|
-
remote: string;
|
|
21
|
-
username: string;
|
|
22
|
-
password: string;
|
|
23
|
-
relationships: DatabaseRelationship[];
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
export interface GetDatabasesResponse {
|
|
27
|
-
object: "list";
|
|
28
|
-
data: Database[];
|
|
29
|
-
meta: {
|
|
30
|
-
pagination: PaginationData;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Handles Creating, Listing, Updating, and Deleting of Databases for the Server
|
|
36
|
-
*
|
|
37
|
-
* @public
|
|
38
|
-
*/
|
|
39
|
-
export class DatabasesAPI {
|
|
40
|
-
constructor(private core: WispAPICore) {}
|
|
41
|
-
|
|
42
|
-
// TODO: Handle Pagination
|
|
43
|
-
/**
|
|
44
|
-
* Lists all Databases associated with the Server
|
|
45
|
-
*
|
|
46
|
-
* @public
|
|
47
|
-
*/
|
|
48
|
-
async List(): Promise<GetDatabasesResponse> {
|
|
49
|
-
const response = await this.core.makeRequest("GET", "databases", { include: "hosts" });
|
|
50
|
-
const data: GetDatabasesResponse = await response.json();
|
|
51
|
-
|
|
52
|
-
return data;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
// TODO: verify response
|
|
57
|
-
/**
|
|
58
|
-
* Deletes the Database from the Server
|
|
59
|
-
*
|
|
60
|
-
* @param id The ID of the Backup
|
|
61
|
-
*
|
|
62
|
-
* @public
|
|
63
|
-
*/
|
|
64
|
-
async Delete(id: string): Promise<Response> {
|
|
65
|
-
return await this.core.makeRequest("DELETE", `databases/${id}`);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
// TODO: Verify response
|
|
70
|
-
/**
|
|
71
|
-
* Rotates the password for the Backup
|
|
72
|
-
*
|
|
73
|
-
* @param id The ID of the Backup
|
|
74
|
-
*
|
|
75
|
-
* @public
|
|
76
|
-
*/
|
|
77
|
-
async RotatePassword(id: string): Promise<Response> {
|
|
78
|
-
return await this.core.makeRequest("POST", `databases/${id}`);
|
|
79
|
-
}
|
|
80
|
-
}
|
package/wisp_api/apis/fastdl.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { WispAPICore } from "./index";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Handles the syncing of the FastDL feature
|
|
5
|
-
*
|
|
6
|
-
* @public
|
|
7
|
-
*/
|
|
8
|
-
export class FastDLAPI {
|
|
9
|
-
constructor(private core: WispAPICore) {}
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Begins a FastDL Sync for the server
|
|
13
|
-
*
|
|
14
|
-
* @remarks
|
|
15
|
-
* ⚠️ If a Sync is already in progress, this function will succeed even though the process will fail.
|
|
16
|
-
*
|
|
17
|
-
* @public
|
|
18
|
-
*/
|
|
19
|
-
async Sync(): Promise<void> {
|
|
20
|
-
await this.core.makeRequest("POST", "fastdl");
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,291 +0,0 @@
|
|
|
1
|
-
import { WispAPICore } from "./index";
|
|
2
|
-
import type { PaginationData } from "./index";
|
|
3
|
-
|
|
4
|
-
// TODO: Handle the 204 vs. 200 with errors better
|
|
5
|
-
// TODO: Use the cool `never` thing for all error pieces in here
|
|
6
|
-
|
|
7
|
-
export interface DirectoryFile {
|
|
8
|
-
object: "file";
|
|
9
|
-
attributes: {
|
|
10
|
-
type: "file" | "directory";
|
|
11
|
-
name: string;
|
|
12
|
-
size: number;
|
|
13
|
-
mime: string;
|
|
14
|
-
symlink: boolean;
|
|
15
|
-
created_at: string;
|
|
16
|
-
modified_at: string;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface DirectoryContents {
|
|
21
|
-
object: "list";
|
|
22
|
-
data: DirectoryFile[]
|
|
23
|
-
meta: {
|
|
24
|
-
pagination: PaginationData | undefined;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
export type GetDirectoryContentsErrorCode = "generic.daemon_connection_exception";
|
|
28
|
-
export interface GetDirectoryContentsError {
|
|
29
|
-
code: GetDirectoryContentsErrorCode;
|
|
30
|
-
data: {
|
|
31
|
-
code: number;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
export interface GetDirectoryContentsFailure {
|
|
35
|
-
errors: GetDirectoryContentsError[] | undefined
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* The response object for the GetDirectoryContents call
|
|
40
|
-
*
|
|
41
|
-
* @remarks
|
|
42
|
-
* Used in {@link FilesystemAPI.GetDirectoryContents}
|
|
43
|
-
*
|
|
44
|
-
* @public
|
|
45
|
-
*/
|
|
46
|
-
export type GetDirectoryContentsResponse = DirectoryContents | GetDirectoryContentsFailure;
|
|
47
|
-
|
|
48
|
-
export interface FileReadError {
|
|
49
|
-
code: string;
|
|
50
|
-
data: {
|
|
51
|
-
code: number
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
export type FileReadResponse =
|
|
55
|
-
| { errors: FileReadError[]; content?: never }
|
|
56
|
-
| { content: string; errors?: never };
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
export interface FileWriteRequest {
|
|
60
|
-
path: string;
|
|
61
|
-
content: string;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export interface CopyFileRequest {
|
|
65
|
-
path: string;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export interface DownloadFileResponse {
|
|
69
|
-
url: string;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export interface RenameFileRequest {
|
|
73
|
-
path: string;
|
|
74
|
-
to: string;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export interface CompressFilesRequest {
|
|
78
|
-
paths: string[];
|
|
79
|
-
to: string;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Handles interaction with the Server's File System
|
|
84
|
-
*
|
|
85
|
-
* @public
|
|
86
|
-
*/
|
|
87
|
-
export class FilesystemAPI {
|
|
88
|
-
constructor(private core: WispAPICore) {}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Get the Contents of the given Directory
|
|
93
|
-
*
|
|
94
|
-
* @param path The path to list
|
|
95
|
-
*
|
|
96
|
-
* @throws {@link GetDirectoryContentsErrorCode}
|
|
97
|
-
*
|
|
98
|
-
* @public
|
|
99
|
-
*/
|
|
100
|
-
async GetDirectoryContents(path: string): Promise<GetDirectoryContentsResponse> {
|
|
101
|
-
const response = await this.core.makeRequest("GET", "files/directory", { path: path });
|
|
102
|
-
const data: GetDirectoryContentsResponse = await response.json();
|
|
103
|
-
|
|
104
|
-
// TODO: Also include the data.code (or handle the 404 case specifically)
|
|
105
|
-
if ("errors" in data && data.errors) {
|
|
106
|
-
throw new Error(data.errors[0].code);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return data
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Creates a Directory with the given path
|
|
115
|
-
*
|
|
116
|
-
* @remarks
|
|
117
|
-
* ⚠️ This will silently fail if the given path is present and invalid or unreachable
|
|
118
|
-
* ⚠️ This is always relative to the Server's default directory (usually /home/container)
|
|
119
|
-
*
|
|
120
|
-
* @param path The full path to the new Directory
|
|
121
|
-
*
|
|
122
|
-
* @public
|
|
123
|
-
*/
|
|
124
|
-
async CreateDirectory(path: string): Promise<void> {
|
|
125
|
-
await this.core.makeRequest("POST", "files/directory", { path: path });
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Retrieves the contents of the File at the given path
|
|
131
|
-
*
|
|
132
|
-
* @param path The full path to the File to read (After the /home/container/ part)
|
|
133
|
-
*
|
|
134
|
-
* @throws "Server returned error code: {number}"
|
|
135
|
-
* This error is often thrown if the given path doesn't exist, or is not readable. The error code would be 404.
|
|
136
|
-
*
|
|
137
|
-
* @public
|
|
138
|
-
*/
|
|
139
|
-
async ReadFile(path: string): Promise<string> {
|
|
140
|
-
const response = await this.core.makeRequest("GET", "files/read", { path: path });
|
|
141
|
-
const data: FileReadResponse = await response.json();
|
|
142
|
-
|
|
143
|
-
if (data.errors) {
|
|
144
|
-
throw new Error(`Server returned error code: ${data.errors[0].data.code}`);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
return data.content;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Writes the given content to the File at the given path
|
|
153
|
-
*
|
|
154
|
-
* @remarks
|
|
155
|
-
* ⚠️ Overwrites the file if it already exists
|
|
156
|
-
* ⚠️ This function silently fails if the target path is not writeable
|
|
157
|
-
*
|
|
158
|
-
* @param path The full path to the File
|
|
159
|
-
* @param content The full content of the File
|
|
160
|
-
*
|
|
161
|
-
* @public
|
|
162
|
-
*/
|
|
163
|
-
async WriteFile(path: string, content: string): Promise<void> {
|
|
164
|
-
const data: FileWriteRequest = { path: path, content: content };
|
|
165
|
-
await this.core.makeRequest("POST", "files/write", data);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Copies the File at the given path
|
|
171
|
-
*
|
|
172
|
-
* @remarks
|
|
173
|
-
* ⚠️ New copy will be written to the same directory, with a name such as `test.txt` -> `test.txt copy-1643810941850`
|
|
174
|
-
*
|
|
175
|
-
* @param path The full path to the File to Copy
|
|
176
|
-
*
|
|
177
|
-
* @throws "Unexpected response code, Copy may not have succeeded"
|
|
178
|
-
* If the API returns anything other than a 204, something likely went wrong. Most commonly, this is because the file path didn't exist or wasn't copyable.
|
|
179
|
-
*
|
|
180
|
-
* @public
|
|
181
|
-
*/
|
|
182
|
-
async CopyFile(path: string): Promise<void> {
|
|
183
|
-
const requestData: CopyFileRequest = { path: path };
|
|
184
|
-
const response = await this.core.makeRequest("POST", "files/copy", requestData);
|
|
185
|
-
|
|
186
|
-
if (response.status != 204) {
|
|
187
|
-
throw new Error("Unexpected response code, Copy may not have succeeded");
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* Deletes the Files at all of the given paths
|
|
194
|
-
*
|
|
195
|
-
* @param paths An array of File Paths to Delete
|
|
196
|
-
*
|
|
197
|
-
* @throws "Unexpected response code, Delete may not have succeeded"
|
|
198
|
-
* If the API returns anything other than a 204, something likely went wrong. Most commonly, this is because the file path didn't exist or wasn't deleteable.
|
|
199
|
-
*
|
|
200
|
-
* @public
|
|
201
|
-
*/
|
|
202
|
-
async DeleteFiles(paths: string[]): Promise<void> {
|
|
203
|
-
const response = await this.core.makeRequest("POST", "files/delete", { paths: paths });
|
|
204
|
-
|
|
205
|
-
if (response.status != 204) {
|
|
206
|
-
throw new Error("Unexpected response code, Delete may not have succeeded");
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* Retrieves a Download URL for a File
|
|
213
|
-
*
|
|
214
|
-
* @remarks
|
|
215
|
-
* ⚠️ This will return a Download URL even if the given file does not exist
|
|
216
|
-
*
|
|
217
|
-
* @param path The full path to the File
|
|
218
|
-
*
|
|
219
|
-
* @public
|
|
220
|
-
*/
|
|
221
|
-
async GetFileDownloadURL(path: string): Promise<string> {
|
|
222
|
-
const response = await this.core.makeRequest("GET", "files/download", { path: path });
|
|
223
|
-
const data: DownloadFileResponse = await response.json();
|
|
224
|
-
|
|
225
|
-
return data.url;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* Renames (or moves) the given File
|
|
231
|
-
*
|
|
232
|
-
* @param path The full path to the File
|
|
233
|
-
* @param to The new path of the File
|
|
234
|
-
*
|
|
235
|
-
* @throws "Unexpected response code, Rename may not have succeeded"
|
|
236
|
-
* If the API returns anything other than a 204, something likely went wrong. Most commonly, this is because the source or destination path did not exist or was not reachable
|
|
237
|
-
*
|
|
238
|
-
* @public
|
|
239
|
-
*/
|
|
240
|
-
async RenameFile(path: string, to: string): Promise<void> {
|
|
241
|
-
const requestData: RenameFileRequest = { path: path, to: to };
|
|
242
|
-
const response = await this.core.makeRequest("PATCH", "files/rename", requestData);
|
|
243
|
-
|
|
244
|
-
if (response.status != 204) {
|
|
245
|
-
throw new Error("Unexpected response code, Rename may not have succeeded");
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
* Compresses the Files at the given paths
|
|
252
|
-
*
|
|
253
|
-
* @remarks
|
|
254
|
-
* ⚠️ The resulting file appears to be unpredictably named?
|
|
255
|
-
*
|
|
256
|
-
* @param paths An array of Paths to Compress
|
|
257
|
-
* @param to The Directory to write the Compressed Files to
|
|
258
|
-
*
|
|
259
|
-
* @throws "Unexpected response code, Compress may not have succeeded"
|
|
260
|
-
* If the API returns anything other than a 204, something likely went wrong. Most commonly, this is because the source or destination path did not exist or was not Compressable
|
|
261
|
-
*
|
|
262
|
-
* @public
|
|
263
|
-
*/
|
|
264
|
-
async CompressFiles(paths: string[], to: string): Promise<void> {
|
|
265
|
-
const requestData: CompressFilesRequest = { paths: paths, to: to };
|
|
266
|
-
const response = await this.core.makeRequest("POST", "files/compress", requestData);
|
|
267
|
-
|
|
268
|
-
if (response.status != 204) {
|
|
269
|
-
throw new Error("Unexpected response code, Compress may not have succeeded");
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
/**
|
|
275
|
-
* Decompresses the File at the given path
|
|
276
|
-
*
|
|
277
|
-
* @param path The full path to the File to Decompress
|
|
278
|
-
*
|
|
279
|
-
* @throws "Unexpected response code, Decompress may not have succeeded"
|
|
280
|
-
* If the API returns anything other than a 204, something likely went wrong. Most commonly, this is because the given path did not exist or was not reachable
|
|
281
|
-
*
|
|
282
|
-
* @public
|
|
283
|
-
*/
|
|
284
|
-
async DecompressFile(path: string): Promise<void> {
|
|
285
|
-
const response = await this.core.makeRequest("POST", "files/decompress", { path: path });
|
|
286
|
-
|
|
287
|
-
if (response.status != 204) {
|
|
288
|
-
throw new Error("Unexpected response code, Decompress may not have succeeded");
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
}
|