refactor: move DokkuResponse to types
This commit is contained in:
parent
76f6e4b0bb
commit
67f3efa038
@ -18,7 +18,7 @@ import {
|
|||||||
} from "./ratelimit"
|
} from "./ratelimit"
|
||||||
import { SecureGitClient } from "./SecureGitClient"
|
import { SecureGitClient } from "./SecureGitClient"
|
||||||
import { TerminalManager } from "./TerminalManager"
|
import { TerminalManager } from "./TerminalManager"
|
||||||
import { User } from "./types"
|
import { DokkuResponse, User } from "./types"
|
||||||
import { LockManager } from "./utils"
|
import { LockManager } from "./utils"
|
||||||
|
|
||||||
// Handle uncaught exceptions
|
// Handle uncaught exceptions
|
||||||
@ -296,63 +296,49 @@ io.on("connection", async (socket) => {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
interface CallbackResponse {
|
|
||||||
success: boolean
|
|
||||||
apps?: string[]
|
|
||||||
message?: string
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle request to list apps
|
// Handle request to list apps
|
||||||
socket.on(
|
socket.on("list", async (callback: (response: DokkuResponse) => void) => {
|
||||||
"list",
|
console.log("Retrieving apps list...")
|
||||||
async (callback: (response: CallbackResponse) => void) => {
|
try {
|
||||||
console.log("Retrieving apps list...")
|
if (!client)
|
||||||
try {
|
throw Error("Failed to retrieve apps list: No Dokku client")
|
||||||
if (!client)
|
callback({
|
||||||
throw Error("Failed to retrieve apps list: No Dokku client")
|
success: true,
|
||||||
callback({
|
apps: await client.listApps(),
|
||||||
success: true,
|
})
|
||||||
apps: await client.listApps(),
|
} catch (error) {
|
||||||
})
|
callback({
|
||||||
} catch (error) {
|
success: false,
|
||||||
callback({
|
message: "Failed to retrieve apps list",
|
||||||
success: false,
|
})
|
||||||
message: "Failed to retrieve apps list",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
)
|
})
|
||||||
|
|
||||||
// Handle request to deploy project
|
// Handle request to deploy project
|
||||||
socket.on(
|
socket.on("deploy", async (callback: (response: DokkuResponse) => void) => {
|
||||||
"deploy",
|
try {
|
||||||
async (callback: (response: CallbackResponse) => void) => {
|
// Push the project files to the Dokku server
|
||||||
try {
|
console.log("Deploying project ${data.sandboxId}...")
|
||||||
// Push the project files to the Dokku server
|
if (!git) throw Error("Failed to retrieve apps list: No git client")
|
||||||
console.log("Deploying project ${data.sandboxId}...")
|
// Remove the /project/[id]/ component of each file path:
|
||||||
if (!git) throw Error("Failed to retrieve apps list: No git client")
|
const fixedFilePaths = fileManager.sandboxFiles.fileData.map((file) => {
|
||||||
// Remove the /project/[id]/ component of each file path:
|
return {
|
||||||
const fixedFilePaths = fileManager.sandboxFiles.fileData.map(
|
...file,
|
||||||
(file) => {
|
id: file.id.split("/").slice(2).join("/"),
|
||||||
return {
|
}
|
||||||
...file,
|
})
|
||||||
id: file.id.split("/").slice(2).join("/"),
|
// Push all files to Dokku.
|
||||||
}
|
await git.pushFiles(fixedFilePaths, data.sandboxId)
|
||||||
}
|
callback({
|
||||||
)
|
success: true,
|
||||||
// Push all files to Dokku.
|
})
|
||||||
await git.pushFiles(fixedFilePaths, data.sandboxId)
|
} catch (error) {
|
||||||
callback({
|
callback({
|
||||||
success: true,
|
success: false,
|
||||||
})
|
message: "Failed to deploy project: " + error,
|
||||||
} catch (error) {
|
})
|
||||||
callback({
|
|
||||||
success: false,
|
|
||||||
message: "Failed to deploy project: " + error,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
)
|
})
|
||||||
|
|
||||||
// Handle request to create a new file
|
// Handle request to create a new file
|
||||||
socket.on("createFile", async (name: string, callback) => {
|
socket.on("createFile", async (name: string, callback) => {
|
||||||
|
@ -68,3 +68,8 @@ export type R2FileBody = R2FileData & {
|
|||||||
json: Promise<any>
|
json: Promise<any>
|
||||||
blob: Promise<Blob>
|
blob: Promise<Blob>
|
||||||
}
|
}
|
||||||
|
export interface DokkuResponse {
|
||||||
|
success: boolean
|
||||||
|
apps?: string[]
|
||||||
|
message?: string
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user