34 lines
883 B
TypeScript
Raw Normal View History

2024-10-19 05:25:26 -06:00
import { SSHConfig, SSHSocketClient } from "./SSHSocketClient"
export interface DokkuResponse {
2024-10-19 05:25:26 -06:00
ok: boolean
output: string
}
export class DokkuClient extends SSHSocketClient {
constructor(config: SSHConfig) {
2024-10-19 05:25:26 -06:00
super(config, "/var/run/dokku-daemon/dokku-daemon.sock")
}
async sendCommand(command: string): Promise<DokkuResponse> {
try {
2024-10-19 05:25:26 -06:00
const response = await this.sendData(command)
if (typeof response !== "string") {
2024-10-19 05:25:26 -06:00
throw new Error("Received data is not a string")
}
2024-10-19 05:25:26 -06:00
return JSON.parse(response)
} catch (error: any) {
2024-10-19 05:25:26 -06:00
throw new Error(`Failed to send command: ${error.message}`)
}
}
async listApps(): Promise<string[]> {
2024-10-19 05:25:26 -06:00
const response = await this.sendCommand("apps:list")
return response.output.split("\n").slice(1) // Split by newline and ignore the first line (header)
}
}
2024-10-19 05:25:26 -06:00
export { SSHConfig }