@pelican.ts/sdk 0.4.0 → 0.4.1
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/.husky/pre-commit +3 -3
- package/README.md +1 -5
- package/biome.json +32 -35
- package/dist/api/index.d.mts +2 -2
- package/dist/api/index.d.ts +2 -2
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +43 -6
- package/dist/index.mjs +34 -6
- package/dist/types.d.ts +7 -7
- package/package.json +59 -59
- package/src/api/client/types/server.ts +64 -51
- package/src/api/client/types/user.ts +18 -19
- package/src/api/client/types/websocket.ts +76 -76
- package/src/api/index.ts +4 -4
- package/src/humane/Account.ts +32 -43
- package/src/humane/Client.ts +17 -16
- package/src/humane/Server.ts +86 -97
- package/src/humane/ServerAllocation.ts +11 -9
- package/src/humane/ServerBackup.ts +7 -7
- package/src/humane/ServerDatabase.ts +6 -5
- package/src/humane/ServerFile.ts +33 -18
- package/src/humane/ServerSchedule.ts +81 -47
- package/src/humane/ServerUser.ts +20 -18
- package/src/index.ts +18 -5
- package/src/utils/sized.ts +2 -3
package/src/humane/Server.ts
CHANGED
|
@@ -1,50 +1,60 @@
|
|
|
1
|
-
import type {ServerClient} from "@/api/client/server"
|
|
2
|
-
import type {ServerBackups} from "@/api/client/server_backups"
|
|
3
|
-
import type {ServerFiles} from "@/api/client/server_files"
|
|
4
|
-
import type {ServerSchedules} from "@/api/client/server_schedules"
|
|
5
|
-
import type {Server as ServerT} from "@/api/client/types/server"
|
|
6
|
-
import { ServerAllocation } from "@/humane/ServerAllocation"
|
|
7
|
-
import {ServerBackup} from "@/humane/ServerBackup"
|
|
8
|
-
import {ServerDatabase} from "@/humane/ServerDatabase"
|
|
9
|
-
import {ServerFile} from "@/humane/ServerFile"
|
|
10
|
-
import {ServerSchedule} from "@/humane/ServerSchedule"
|
|
11
|
-
import {ServerUser} from "@/humane/ServerUser"
|
|
12
|
-
import type {
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import type { ServerClient } from "@/api/client/server"
|
|
2
|
+
import type { ServerBackups } from "@/api/client/server_backups"
|
|
3
|
+
import type { ServerFiles } from "@/api/client/server_files"
|
|
4
|
+
import type { ServerSchedules } from "@/api/client/server_schedules"
|
|
5
|
+
import type { Server as ServerT } from "@/api/client/types/server"
|
|
6
|
+
import { ServerAllocation } from "@/humane/ServerAllocation"
|
|
7
|
+
import { ServerBackup } from "@/humane/ServerBackup"
|
|
8
|
+
import { ServerDatabase } from "@/humane/ServerDatabase"
|
|
9
|
+
import { ServerFile } from "@/humane/ServerFile"
|
|
10
|
+
import { ServerSchedule } from "@/humane/ServerSchedule"
|
|
11
|
+
import { ServerUser } from "@/humane/ServerUser"
|
|
12
|
+
import type {
|
|
13
|
+
EggVariable,
|
|
14
|
+
FeatureLimits,
|
|
15
|
+
ServerLimits,
|
|
16
|
+
SubuserPermission,
|
|
17
|
+
} from "@/types"
|
|
18
|
+
import type { Nullable } from "@/utils/types"
|
|
15
19
|
|
|
16
20
|
export class Server {
|
|
17
21
|
private readonly client: ServerClient
|
|
18
22
|
|
|
19
|
-
readonly ownsServer: boolean
|
|
20
|
-
readonly identifier: string
|
|
21
|
-
readonly internalId?: number
|
|
22
|
-
readonly uuid: string
|
|
23
|
-
private $name: string
|
|
24
|
-
get name() {
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
readonly ownsServer: boolean
|
|
24
|
+
readonly identifier: string
|
|
25
|
+
readonly internalId?: number
|
|
26
|
+
readonly uuid: string
|
|
27
|
+
private $name: string
|
|
28
|
+
get name() {
|
|
29
|
+
return this.$name
|
|
30
|
+
}
|
|
31
|
+
readonly node: string
|
|
32
|
+
readonly isNodeUnderMaintenance: boolean
|
|
27
33
|
readonly sftp: {
|
|
28
|
-
ip: string
|
|
29
|
-
alias: Nullable<string
|
|
34
|
+
ip: string
|
|
35
|
+
alias: Nullable<string>
|
|
30
36
|
port: number
|
|
31
|
-
}
|
|
32
|
-
private $description: string
|
|
33
|
-
get description() {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
readonly
|
|
43
|
-
readonly
|
|
37
|
+
}
|
|
38
|
+
private $description: string
|
|
39
|
+
get description() {
|
|
40
|
+
return this.$description
|
|
41
|
+
}
|
|
42
|
+
readonly limits: ServerLimits
|
|
43
|
+
readonly invocation: string
|
|
44
|
+
private $dockerImage: string
|
|
45
|
+
get dockerImage() {
|
|
46
|
+
return this.$dockerImage
|
|
47
|
+
}
|
|
48
|
+
readonly eggFeatures: Nullable<string[]>
|
|
49
|
+
readonly featureLimits: FeatureLimits
|
|
50
|
+
readonly status: unknown
|
|
51
|
+
readonly isSuspended: boolean
|
|
52
|
+
readonly isInstalling: boolean
|
|
53
|
+
readonly isTransferring: boolean
|
|
44
54
|
readonly allocations: ServerAllocation[]
|
|
45
55
|
readonly variables: EggVariable[]
|
|
46
56
|
readonly egg?: {
|
|
47
|
-
uuid: string
|
|
57
|
+
uuid: string
|
|
48
58
|
name: string
|
|
49
59
|
}
|
|
50
60
|
readonly subusers?: ServerUser[]
|
|
@@ -69,40 +79,37 @@ export class Server {
|
|
|
69
79
|
this.isSuspended = server.is_suspended
|
|
70
80
|
this.isInstalling = server.is_installing
|
|
71
81
|
this.isTransferring = server.is_transferring
|
|
72
|
-
this.allocations = server.relationships.allocations.data.map(
|
|
73
|
-
|
|
82
|
+
this.allocations = server.relationships.allocations.data.map(
|
|
83
|
+
(d) => new ServerAllocation(this.client, d.attributes),
|
|
84
|
+
)
|
|
85
|
+
this.variables = server.relationships.variables.data.map(
|
|
86
|
+
(d) => d.attributes,
|
|
87
|
+
)
|
|
74
88
|
this.egg = server.relationships.egg?.attributes
|
|
75
|
-
this.subusers = server.relationships.subusers?.data.map(
|
|
89
|
+
this.subusers = server.relationships.subusers?.data.map(
|
|
90
|
+
(d) => new ServerUser(this.client, d.attributes),
|
|
91
|
+
)
|
|
76
92
|
}
|
|
77
93
|
|
|
78
|
-
rename = async (
|
|
79
|
-
name: string
|
|
80
|
-
) => {
|
|
94
|
+
rename = async (name: string) => {
|
|
81
95
|
await this.client.settings.rename(name)
|
|
82
96
|
this.$name = name
|
|
83
97
|
}
|
|
84
98
|
|
|
85
|
-
updateDescription = async (
|
|
86
|
-
description: string
|
|
87
|
-
) => {
|
|
99
|
+
updateDescription = async (description: string) => {
|
|
88
100
|
await this.client.settings.updateDescription(description)
|
|
89
101
|
this.$description = description
|
|
90
102
|
}
|
|
91
103
|
|
|
92
104
|
reinstall = async () => this.client.settings.reinstall()
|
|
93
105
|
|
|
94
|
-
changeDockerImage = async (
|
|
95
|
-
image: string
|
|
96
|
-
) => {
|
|
106
|
+
changeDockerImage = async (image: string) => {
|
|
97
107
|
await this.client.settings.changeDockerImage(image)
|
|
98
108
|
this.$dockerImage = image
|
|
99
109
|
}
|
|
100
110
|
|
|
101
111
|
getActivityLogs = async (
|
|
102
|
-
opts: {
|
|
103
|
-
page?: number,
|
|
104
|
-
per_page?: number
|
|
105
|
-
} = {page: 1, per_page: 50}
|
|
112
|
+
opts: { page?: number; per_page?: number } = { page: 1, per_page: 50 },
|
|
106
113
|
) => this.client.activity.list(opts.page, opts.per_page)
|
|
107
114
|
|
|
108
115
|
websocket = (stripColors: boolean = false) =>
|
|
@@ -112,59 +119,47 @@ export class Server {
|
|
|
112
119
|
|
|
113
120
|
runCommand = async (command: string) => this.client.command(command)
|
|
114
121
|
|
|
115
|
-
sendPowerSignal = async (
|
|
116
|
-
signal
|
|
117
|
-
) => this.client.power(signal)
|
|
118
|
-
|
|
119
|
-
|
|
122
|
+
sendPowerSignal = async (signal: "start" | "stop" | "restart" | "kill") =>
|
|
123
|
+
this.client.power(signal)
|
|
120
124
|
|
|
121
125
|
getDatabases = async (
|
|
122
|
-
opts: {
|
|
123
|
-
include
|
|
124
|
-
page
|
|
125
|
-
}
|
|
126
|
+
opts: { include?: "password"[]; page?: number } = {
|
|
127
|
+
include: [],
|
|
128
|
+
page: 1,
|
|
129
|
+
},
|
|
126
130
|
) => {
|
|
127
131
|
const data = await this.client.databases.list(opts.include, opts.page)
|
|
128
|
-
return data.map(d => new ServerDatabase(this.client, d))
|
|
132
|
+
return data.map((d) => new ServerDatabase(this.client, d))
|
|
129
133
|
}
|
|
130
134
|
|
|
131
|
-
createDatabase = async (
|
|
132
|
-
database: string,
|
|
133
|
-
remote: string
|
|
134
|
-
) => {
|
|
135
|
+
createDatabase = async (database: string, remote: string) => {
|
|
135
136
|
const data = await this.client.databases.create(database, remote)
|
|
136
137
|
return new ServerDatabase(this.client, data)
|
|
137
138
|
}
|
|
138
139
|
|
|
139
140
|
getSchedules = async () => {
|
|
140
141
|
const data = await this.client.schedules.list()
|
|
141
|
-
return data.map(d => new ServerSchedule(this.client, d))
|
|
142
|
+
return data.map((d) => new ServerSchedule(this.client, d))
|
|
142
143
|
}
|
|
143
144
|
|
|
144
|
-
createSchedule = async (
|
|
145
|
-
...opts: Parameters<ServerSchedules["create"]>
|
|
146
|
-
) => {
|
|
145
|
+
createSchedule = async (...opts: Parameters<ServerSchedules["create"]>) => {
|
|
147
146
|
const data = await this.client.schedules.create(...opts)
|
|
148
147
|
return new ServerSchedule(this.client, data)
|
|
149
148
|
}
|
|
150
149
|
|
|
151
|
-
getBackups = async (
|
|
152
|
-
page: number = 1
|
|
153
|
-
) => {
|
|
150
|
+
getBackups = async (page: number = 1) => {
|
|
154
151
|
const data = await this.client.backups.list(page)
|
|
155
|
-
return data.map(d => new ServerBackup(this.client, d))
|
|
152
|
+
return data.map((d) => new ServerBackup(this.client, d))
|
|
156
153
|
}
|
|
157
154
|
|
|
158
|
-
createBackup = async (
|
|
159
|
-
...args: Parameters<ServerBackups["create"]>
|
|
160
|
-
) => {
|
|
155
|
+
createBackup = async (...args: Parameters<ServerBackups["create"]>) => {
|
|
161
156
|
const data = await this.client.backups.create(...args)
|
|
162
157
|
return new ServerBackup(this.client, data)
|
|
163
158
|
}
|
|
164
159
|
|
|
165
160
|
getAllocations = async () => {
|
|
166
161
|
const data = await this.client.allocations.list()
|
|
167
|
-
return data.map(d => new ServerAllocation(this.client, d))
|
|
162
|
+
return data.map((d) => new ServerAllocation(this.client, d))
|
|
168
163
|
}
|
|
169
164
|
|
|
170
165
|
createAllocation = async () => {
|
|
@@ -172,20 +167,16 @@ export class Server {
|
|
|
172
167
|
return new ServerAllocation(this.client, data)
|
|
173
168
|
}
|
|
174
169
|
|
|
175
|
-
getFiles = async (
|
|
176
|
-
path?: string
|
|
177
|
-
) => {
|
|
170
|
+
getFiles = async (path?: string) => {
|
|
178
171
|
const data = await this.client.files.list(path)
|
|
179
|
-
return data.map(d => new ServerFile(this.client, d))
|
|
172
|
+
return data.map((d) => new ServerFile(this.client, d))
|
|
180
173
|
}
|
|
181
174
|
|
|
182
|
-
createFolder = async (
|
|
183
|
-
...opts
|
|
184
|
-
) => this.client.files.createFolder(...opts)
|
|
175
|
+
createFolder = async (...opts: Parameters<ServerFiles["createFolder"]>) =>
|
|
176
|
+
this.client.files.createFolder(...opts)
|
|
185
177
|
|
|
186
|
-
uploadFile = async (
|
|
187
|
-
...opts
|
|
188
|
-
) => this.client.files.upload(...opts)
|
|
178
|
+
uploadFile = async (...opts: Parameters<ServerFiles["upload"]>) =>
|
|
179
|
+
this.client.files.upload(...opts)
|
|
189
180
|
|
|
190
181
|
uploadFileGetUrl = async (
|
|
191
182
|
...opts: Parameters<ServerFiles["uploadGetUrl"]>
|
|
@@ -197,12 +188,12 @@ export class Server {
|
|
|
197
188
|
|
|
198
189
|
getUsers = async () => {
|
|
199
190
|
const data = await this.client.users.list()
|
|
200
|
-
return data.map(d => new ServerUser(this.client, d))
|
|
191
|
+
return data.map((d) => new ServerUser(this.client, d))
|
|
201
192
|
}
|
|
202
193
|
|
|
203
194
|
createUser = async (
|
|
204
195
|
email: string,
|
|
205
|
-
permissions: SubuserPermission[] | string[]
|
|
196
|
+
permissions: SubuserPermission[] | string[],
|
|
206
197
|
) => {
|
|
207
198
|
const data = await this.client.users.create(email, permissions)
|
|
208
199
|
return new ServerUser(this.client, data)
|
|
@@ -210,8 +201,6 @@ export class Server {
|
|
|
210
201
|
|
|
211
202
|
getStartupInfo = async () => this.client.startup.list()
|
|
212
203
|
|
|
213
|
-
setStartupVariable = async (
|
|
214
|
-
key
|
|
215
|
-
|
|
216
|
-
) => this.client.startup.set(key, value)
|
|
217
|
-
}
|
|
204
|
+
setStartupVariable = async (key: string, value: string) =>
|
|
205
|
+
this.client.startup.set(key, value)
|
|
206
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {ServerClient} from "@/api/client/server"
|
|
2
|
-
import type {ServerAllocation as ServerAllocationT} from "@/api/client/types/server_allocation"
|
|
3
|
-
import type {Nullable} from "@/utils/types"
|
|
1
|
+
import type { ServerClient } from "@/api/client/server"
|
|
2
|
+
import type { ServerAllocation as ServerAllocationT } from "@/api/client/types/server_allocation"
|
|
3
|
+
import type { Nullable } from "@/utils/types"
|
|
4
4
|
|
|
5
5
|
export class ServerAllocation {
|
|
6
6
|
private readonly client: ServerClient
|
|
@@ -8,9 +8,13 @@ export class ServerAllocation {
|
|
|
8
8
|
readonly id: number
|
|
9
9
|
readonly ip: string
|
|
10
10
|
private $isDefault: boolean
|
|
11
|
-
get isDefault() {
|
|
11
|
+
get isDefault() {
|
|
12
|
+
return this.$isDefault
|
|
13
|
+
}
|
|
12
14
|
private $notes: Nullable<string>
|
|
13
|
-
get notes() {
|
|
15
|
+
get notes() {
|
|
16
|
+
return this.$notes
|
|
17
|
+
}
|
|
14
18
|
readonly port: number
|
|
15
19
|
|
|
16
20
|
constructor(client: ServerClient, alloc: ServerAllocationT) {
|
|
@@ -23,9 +27,7 @@ export class ServerAllocation {
|
|
|
23
27
|
this.port = alloc.port
|
|
24
28
|
}
|
|
25
29
|
|
|
26
|
-
setNotes = async (
|
|
27
|
-
notes: string
|
|
28
|
-
) => {
|
|
30
|
+
setNotes = async (notes: string) => {
|
|
29
31
|
const data = await this.client.allocations.setNotes(this.id, notes)
|
|
30
32
|
this.$notes = data.notes
|
|
31
33
|
}
|
|
@@ -36,4 +38,4 @@ export class ServerAllocation {
|
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
unassign = async () => this.client.allocations.unassign(this.id)
|
|
39
|
-
}
|
|
41
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import type {ServerClient} from "@/api/client/server"
|
|
2
|
-
import type {ServerBackup as ServerBackupT} from "@/api/common/types/server_backup"
|
|
3
|
-
import type {Nullable} from "@/utils/types"
|
|
4
|
-
|
|
1
|
+
import type { ServerClient } from "@/api/client/server"
|
|
2
|
+
import type { ServerBackup as ServerBackupT } from "@/api/common/types/server_backup"
|
|
3
|
+
import type { Nullable } from "@/utils/types"
|
|
5
4
|
|
|
6
5
|
export class ServerBackup {
|
|
7
6
|
private readonly client: ServerClient
|
|
@@ -19,7 +18,9 @@ export class ServerBackup {
|
|
|
19
18
|
this.client = client
|
|
20
19
|
this.bytes = backup.bytes
|
|
21
20
|
this.checksum = backup.checksum
|
|
22
|
-
this.completedAt = backup.completed_at
|
|
21
|
+
this.completedAt = backup.completed_at
|
|
22
|
+
? new Date(backup.completed_at)
|
|
23
|
+
: null
|
|
23
24
|
this.createdAt = new Date(backup.created_at)
|
|
24
25
|
this.ignoredFiles = backup.ignored_files
|
|
25
26
|
this.isLocked = backup.is_locked
|
|
@@ -27,11 +28,10 @@ export class ServerBackup {
|
|
|
27
28
|
this.name = backup.name
|
|
28
29
|
this.uuid = backup.uuid
|
|
29
30
|
}
|
|
30
|
-
|
|
31
31
|
|
|
32
32
|
downloadGetUrl = async () => this.client.backups.downloadGetUrl(this.uuid)
|
|
33
33
|
|
|
34
34
|
download = async () => this.client.backups.download(this.uuid)
|
|
35
35
|
|
|
36
36
|
delete = async () => this.client.backups.delete(this.uuid)
|
|
37
|
-
}
|
|
37
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {ServerClient} from "@/api/client/server"
|
|
2
|
-
import type {ServerDatabase as ServerDatabaseT} from "@/api/common/types/server_database"
|
|
1
|
+
import type { ServerClient } from "@/api/client/server"
|
|
2
|
+
import type { ServerDatabase as ServerDatabaseT } from "@/api/common/types/server_database"
|
|
3
3
|
// TODO: Check for validity
|
|
4
4
|
|
|
5
5
|
export class ServerDatabase {
|
|
@@ -11,7 +11,9 @@ export class ServerDatabase {
|
|
|
11
11
|
readonly maxConnections: number
|
|
12
12
|
readonly name: string
|
|
13
13
|
private $password?: string
|
|
14
|
-
get password() {
|
|
14
|
+
get password() {
|
|
15
|
+
return this.$password
|
|
16
|
+
}
|
|
15
17
|
readonly username: string
|
|
16
18
|
|
|
17
19
|
constructor(client: ServerClient, database: ServerDatabaseT) {
|
|
@@ -26,11 +28,10 @@ export class ServerDatabase {
|
|
|
26
28
|
this.username = database.username
|
|
27
29
|
}
|
|
28
30
|
|
|
29
|
-
|
|
30
31
|
rotatePassword = async () => {
|
|
31
32
|
const data = await this.client.databases.rotatePassword(this.id)
|
|
32
33
|
this.$password = data.relationships?.password.attributes.password
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
delete = async () => this.client.databases.delete(this.id)
|
|
36
|
-
}
|
|
37
|
+
}
|
package/src/humane/ServerFile.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import path from "node:path"
|
|
2
|
-
import type {ServerClient} from "@/api/client/server"
|
|
3
|
-
import type {FileObject} from "@/api/common/types/server_files"
|
|
4
|
-
|
|
1
|
+
import path from "node:path"
|
|
2
|
+
import type { ServerClient } from "@/api/client/server"
|
|
3
|
+
import type { FileObject } from "@/api/common/types/server_files"
|
|
5
4
|
|
|
6
5
|
export class ServerFile {
|
|
7
6
|
private readonly client: ServerClient
|
|
@@ -35,8 +34,14 @@ export class ServerFile {
|
|
|
35
34
|
get isArchive() {
|
|
36
35
|
// Maybe mimetype is better
|
|
37
36
|
return [
|
|
38
|
-
"zip",
|
|
39
|
-
|
|
37
|
+
"zip",
|
|
38
|
+
"tgz",
|
|
39
|
+
"tar.gz",
|
|
40
|
+
"txz",
|
|
41
|
+
"tar.xz",
|
|
42
|
+
"tbz2",
|
|
43
|
+
"tar.bz2",
|
|
44
|
+
].some((ext) => this.name.endsWith(`.${ext}`))
|
|
40
45
|
}
|
|
41
46
|
|
|
42
47
|
/**
|
|
@@ -48,26 +53,36 @@ export class ServerFile {
|
|
|
48
53
|
|
|
49
54
|
download = async () => this.client.files.download(this.path)
|
|
50
55
|
|
|
51
|
-
rename = async (
|
|
52
|
-
|
|
53
|
-
) => this.client.files.rename(this.dir, [{from: this.name, to: newName}])
|
|
56
|
+
rename = async (newName: string) =>
|
|
57
|
+
this.client.files.rename(this.dir, [{ from: this.name, to: newName }])
|
|
54
58
|
|
|
55
59
|
copy = async () => this.client.files.copy(this.path)
|
|
56
60
|
|
|
57
|
-
write = async (
|
|
58
|
-
content
|
|
59
|
-
) => this.client.files.write(this.path, content)
|
|
61
|
+
write = async (content: string) =>
|
|
62
|
+
this.client.files.write(this.path, content)
|
|
60
63
|
|
|
61
64
|
compress = async (
|
|
62
65
|
archive_name?: string,
|
|
63
|
-
extension?:
|
|
64
|
-
|
|
66
|
+
extension?:
|
|
67
|
+
| "zip"
|
|
68
|
+
| "tgz"
|
|
69
|
+
| "tar.gz"
|
|
70
|
+
| "txz"
|
|
71
|
+
| "tar.xz"
|
|
72
|
+
| "tbz2"
|
|
73
|
+
| "tar.bz2",
|
|
74
|
+
) =>
|
|
75
|
+
this.client.files.compress(
|
|
76
|
+
this.dir,
|
|
77
|
+
[this.name],
|
|
78
|
+
archive_name,
|
|
79
|
+
extension,
|
|
80
|
+
)
|
|
65
81
|
|
|
66
82
|
decompress = async () => this.client.files.decompress(this.dir, this.name)
|
|
67
83
|
|
|
68
84
|
delete = async () => this.client.files.delete(this.dir, [this.name])
|
|
69
85
|
|
|
70
|
-
chmod = async (
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
86
|
+
chmod = async (mode: number) =>
|
|
87
|
+
this.client.files.chmod(this.dir, [{ file: this.name, mode }])
|
|
88
|
+
}
|
|
@@ -1,32 +1,43 @@
|
|
|
1
|
-
import type {ServerClient} from "@/api/client/server"
|
|
2
|
-
import type {Schedule, ScheduleTask} from "@/api/common/types/server_schedule"
|
|
3
|
-
import type {Nullable, PartialBy} from "@/utils/types"
|
|
4
|
-
|
|
1
|
+
import type { ServerClient } from "@/api/client/server"
|
|
2
|
+
import type { Schedule, ScheduleTask } from "@/api/common/types/server_schedule"
|
|
3
|
+
import type { Nullable, PartialBy } from "@/utils/types"
|
|
5
4
|
|
|
6
5
|
export class ServerSchedule {
|
|
7
6
|
private readonly client: ServerClient
|
|
8
7
|
readonly createdAt: Date
|
|
9
8
|
private $cron: {
|
|
10
|
-
day_of_week: string
|
|
11
|
-
day_of_month: string
|
|
12
|
-
hour: string
|
|
9
|
+
day_of_week: string
|
|
10
|
+
day_of_month: string
|
|
11
|
+
hour: string
|
|
13
12
|
minute: string
|
|
14
13
|
}
|
|
15
|
-
get cron() {
|
|
14
|
+
get cron() {
|
|
15
|
+
return { ...this.$cron }
|
|
16
|
+
}
|
|
16
17
|
readonly id: number
|
|
17
18
|
private $isActive: boolean
|
|
18
|
-
get isActive() {
|
|
19
|
+
get isActive() {
|
|
20
|
+
return this.$isActive
|
|
21
|
+
}
|
|
19
22
|
private $isProcessing: boolean
|
|
20
|
-
get isProcessing() {
|
|
23
|
+
get isProcessing() {
|
|
24
|
+
return this.$isProcessing
|
|
25
|
+
}
|
|
21
26
|
readonly lastRunAt: Nullable<Date>
|
|
22
27
|
private $name: string
|
|
23
|
-
get name() {
|
|
28
|
+
get name() {
|
|
29
|
+
return this.$name
|
|
30
|
+
}
|
|
24
31
|
readonly nextRunAt: Date
|
|
25
32
|
private $onlyWhenOnline: boolean
|
|
26
|
-
get onlyWhenOnline() {
|
|
33
|
+
get onlyWhenOnline() {
|
|
34
|
+
return this.$onlyWhenOnline
|
|
35
|
+
}
|
|
27
36
|
readonly tasks: ServerScheduleTask[]
|
|
28
37
|
private $updatedAt: Date
|
|
29
|
-
get updatedAt() {
|
|
38
|
+
get updatedAt() {
|
|
39
|
+
return this.$updatedAt
|
|
40
|
+
}
|
|
30
41
|
|
|
31
42
|
constructor(client: ServerClient, schedule: Schedule) {
|
|
32
43
|
this.client = client
|
|
@@ -35,28 +46,28 @@ export class ServerSchedule {
|
|
|
35
46
|
this.id = schedule.id
|
|
36
47
|
this.$isActive = schedule.is_active
|
|
37
48
|
this.$isProcessing = schedule.is_processing
|
|
38
|
-
this.lastRunAt = schedule.last_run_at
|
|
49
|
+
this.lastRunAt = schedule.last_run_at
|
|
50
|
+
? new Date(schedule.last_run_at)
|
|
51
|
+
: null
|
|
39
52
|
this.$name = schedule.name
|
|
40
53
|
this.nextRunAt = new Date(schedule.next_run_at)
|
|
41
54
|
this.$onlyWhenOnline = schedule.only_when_online
|
|
42
55
|
this.tasks = schedule.relationships.tasks.data.map(
|
|
43
|
-
d => new ServerScheduleTask(this.client, this.id, d.attributes)
|
|
56
|
+
(d) => new ServerScheduleTask(this.client, this.id, d.attributes),
|
|
44
57
|
)
|
|
45
58
|
this.$updatedAt = new Date(schedule.updated_at)
|
|
46
59
|
}
|
|
47
60
|
|
|
48
|
-
update = async (
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
) => {
|
|
61
|
+
update = async (opts: {
|
|
62
|
+
name: string
|
|
63
|
+
is_active?: boolean
|
|
64
|
+
only_when_online?: boolean
|
|
65
|
+
minute: string
|
|
66
|
+
hour: string
|
|
67
|
+
day_of_week: string
|
|
68
|
+
month: string
|
|
69
|
+
day_of_month: string
|
|
70
|
+
}) => {
|
|
60
71
|
const data = await this.client.schedules.control(this.id).update(opts)
|
|
61
72
|
this.$name = data.name
|
|
62
73
|
this.$isActive = data.is_active
|
|
@@ -74,22 +85,36 @@ export class ServerSchedule {
|
|
|
74
85
|
export class ServerScheduleTask {
|
|
75
86
|
private readonly client: ServerClient
|
|
76
87
|
private readonly scheduleId: number
|
|
77
|
-
private $action: "command" | "power" | "backup" | "delete_files"
|
|
78
|
-
get action() {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
private $
|
|
88
|
-
get
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
private $
|
|
92
|
-
get
|
|
88
|
+
private $action: "command" | "power" | "backup" | "delete_files"
|
|
89
|
+
get action() {
|
|
90
|
+
return this.$action
|
|
91
|
+
}
|
|
92
|
+
private $continueOnFailure: boolean
|
|
93
|
+
get continueOnFailure() {
|
|
94
|
+
return this.$continueOnFailure
|
|
95
|
+
}
|
|
96
|
+
readonly createdAt: Date
|
|
97
|
+
readonly id: number
|
|
98
|
+
private $isQueued: boolean
|
|
99
|
+
get isQueued() {
|
|
100
|
+
return this.$isQueued
|
|
101
|
+
}
|
|
102
|
+
private $payload: string
|
|
103
|
+
get payload() {
|
|
104
|
+
return this.$payload
|
|
105
|
+
}
|
|
106
|
+
private $sequenceId: number
|
|
107
|
+
get sequenceId() {
|
|
108
|
+
return this.$sequenceId
|
|
109
|
+
}
|
|
110
|
+
private $timeOffset: number
|
|
111
|
+
get timeOffset() {
|
|
112
|
+
return this.$timeOffset
|
|
113
|
+
}
|
|
114
|
+
private $updatedAt: Nullable<Date>
|
|
115
|
+
get updatedAt() {
|
|
116
|
+
return this.$updatedAt
|
|
117
|
+
}
|
|
93
118
|
|
|
94
119
|
constructor(client: ServerClient, scheduleId: number, task: ScheduleTask) {
|
|
95
120
|
this.client = client
|
|
@@ -110,11 +135,20 @@ export class ServerScheduleTask {
|
|
|
110
135
|
|
|
111
136
|
update = async (
|
|
112
137
|
opts: PartialBy<
|
|
113
|
-
Pick<
|
|
138
|
+
Pick<
|
|
139
|
+
ScheduleTask,
|
|
140
|
+
| "action"
|
|
141
|
+
| "payload"
|
|
142
|
+
| "time_offset"
|
|
143
|
+
| "sequence_id"
|
|
144
|
+
| "continue_on_failure"
|
|
145
|
+
>,
|
|
114
146
|
"payload" | "sequence_id" | "continue_on_failure"
|
|
115
|
-
|
|
147
|
+
>,
|
|
116
148
|
) => {
|
|
117
|
-
const data = await this.client.schedules
|
|
149
|
+
const data = await this.client.schedules
|
|
150
|
+
.control(this.scheduleId)
|
|
151
|
+
.tasks.update(this.id, opts)
|
|
118
152
|
this.$action = data.action
|
|
119
153
|
this.$continueOnFailure = data.continue_on_failure
|
|
120
154
|
this.$isQueued = data.is_queued
|
|
@@ -123,4 +157,4 @@ export class ServerScheduleTask {
|
|
|
123
157
|
this.$timeOffset = data.time_offset
|
|
124
158
|
this.$updatedAt = data.updated_at ? new Date(data.updated_at) : null
|
|
125
159
|
}
|
|
126
|
-
}
|
|
160
|
+
}
|