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