refactor: move DokkuResponse to types

This commit is contained in:
James Murdza 2024-10-24 15:59:21 -06:00
parent 76f6e4b0bb
commit 67f3efa038
2 changed files with 44 additions and 53 deletions

View File

@ -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,16 +296,8 @@ 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",
async (callback: (response: CallbackResponse) => void) => {
console.log("Retrieving apps list...") console.log("Retrieving apps list...")
try { try {
if (!client) if (!client)
@ -320,26 +312,21 @@ io.on("connection", async (socket) => {
message: "Failed to retrieve apps list", 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",
async (callback: (response: CallbackResponse) => void) => {
try { try {
// Push the project files to the Dokku server // Push the project files to the Dokku server
console.log("Deploying project ${data.sandboxId}...") console.log("Deploying project ${data.sandboxId}...")
if (!git) throw Error("Failed to retrieve apps list: No git client") if (!git) throw Error("Failed to retrieve apps list: No git client")
// Remove the /project/[id]/ component of each file path: // Remove the /project/[id]/ component of each file path:
const fixedFilePaths = fileManager.sandboxFiles.fileData.map( const fixedFilePaths = fileManager.sandboxFiles.fileData.map((file) => {
(file) => {
return { return {
...file, ...file,
id: file.id.split("/").slice(2).join("/"), id: file.id.split("/").slice(2).join("/"),
} }
} })
)
// Push all files to Dokku. // Push all files to Dokku.
await git.pushFiles(fixedFilePaths, data.sandboxId) await git.pushFiles(fixedFilePaths, data.sandboxId)
callback({ callback({
@ -351,8 +338,7 @@ io.on("connection", async (socket) => {
message: "Failed to deploy project: " + error, 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) => {

View File

@ -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
}