feat: correctly show whether a project has been deployed
This commit is contained in:
@ -31,9 +31,30 @@ export class DokkuClient extends SSHSocketClient {
|
||||
|
||||
// List all deployed Dokku apps
|
||||
async listApps(): Promise<string[]> {
|
||||
const response = await this.sendCommand("apps:list")
|
||||
// Split the output by newline and remove the header
|
||||
return response.output.split("\n").slice(1)
|
||||
const response = await this.sendCommand("--quiet apps:list")
|
||||
return response.output.split("\n")
|
||||
}
|
||||
|
||||
// Get the creation timestamp of an app
|
||||
async getAppCreatedAt(appName: string): Promise<number> {
|
||||
const response = await this.sendCommand(
|
||||
`apps:report --app-created-at ${appName}`
|
||||
)
|
||||
const createdAt = parseInt(response.output.trim(), 10)
|
||||
|
||||
if (isNaN(createdAt)) {
|
||||
throw new Error(
|
||||
`Failed to retrieve creation timestamp for app ${appName}`
|
||||
)
|
||||
}
|
||||
|
||||
return createdAt
|
||||
}
|
||||
|
||||
// Check if an app exists
|
||||
async appExists(appName: string): Promise<boolean> {
|
||||
const response = await this.sendCommand(`apps:exists ${appName}`)
|
||||
return response.output.includes("App") === false
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -156,6 +156,28 @@ export class Sandbox {
|
||||
return { success: true, apps: await this.dokkuClient.listApps() }
|
||||
}
|
||||
|
||||
// Handle getting app creation timestamp
|
||||
const handleGetAppCreatedAt: SocketHandler = async ({ appName }) => {
|
||||
if (!this.dokkuClient)
|
||||
throw new Error(
|
||||
"Failed to retrieve app creation timestamp: No Dokku client"
|
||||
)
|
||||
return {
|
||||
success: true,
|
||||
createdAt: await this.dokkuClient.getAppCreatedAt(appName),
|
||||
}
|
||||
}
|
||||
|
||||
// Handle checking if an app exists
|
||||
const handleAppExists: SocketHandler = async ({ appName }) => {
|
||||
if (!this.dokkuClient)
|
||||
throw new Error("Failed to check app existence: No Dokku client")
|
||||
return {
|
||||
success: true,
|
||||
exists: await this.dokkuClient.appExists(appName),
|
||||
}
|
||||
}
|
||||
|
||||
// Handle deploying code
|
||||
const handleDeploy: SocketHandler = async (_: any) => {
|
||||
if (!this.gitClient) throw Error("No git client")
|
||||
@ -253,7 +275,9 @@ export class Sandbox {
|
||||
getFolder: handleGetFolder,
|
||||
saveFile: handleSaveFile,
|
||||
moveFile: handleMoveFile,
|
||||
list: handleListApps,
|
||||
listApps: handleListApps,
|
||||
getAppCreatedAt: handleGetAppCreatedAt,
|
||||
getAppExists: handleAppExists,
|
||||
deploy: handleDeploy,
|
||||
createFile: handleCreateFile,
|
||||
createFolder: handleCreateFolder,
|
||||
|
@ -146,6 +146,8 @@ io.on("connection", async (socket) => {
|
||||
)
|
||||
})
|
||||
|
||||
socket.emit("ready")
|
||||
|
||||
// Handle disconnection event
|
||||
socket.on("disconnect", async () => {
|
||||
try {
|
||||
|
Reference in New Issue
Block a user