Files
floci-ui/packages/api/src/services/lightsailDeployment.ts
T
Zakaria 91ce11274d
CI / checks (pull_request) Successful in 25m47s
chore: show TheCloud instead of Floci in console text and messages
Labels, empty states, error messages and defaults the console shows now name
TheCloud or its runtimes. Identifiers that must match the emulator (FLOCI_*
settings, the X-Floci-CSRF header, emulator-returned host names) are unchanged.
2026-10-24 14:30:44 -04:00

45 lines
2.8 KiB
TypeScript

import {httpStatusToCloudError, RuntimeUnavailableError} from '../cloud-spi/errors'
export type LightsailStaticDeployment = {status: 'deployed'; files: number}
export type LightsailNodeDeployment = {status: 'deployed'; files: number; port: number; releaseId: string}
export async function deployLightsailStaticFiles(instanceName: string, form: FormData): Promise<LightsailStaticDeployment> {
const endpoint = process.env.FLOCI_ENDPOINT
if (!endpoint) throw new RuntimeUnavailableError('TheCloud diagnostics are unavailable')
let response: Response
try {
response = await fetch(new URL(`/_floci/diagnostics/lightsail/instances/${encodeURIComponent(instanceName)}/static-files`, endpoint).toString(), {
method: 'POST', body: form, redirect: 'error', signal: AbortSignal.timeout(30_000),
})
} catch (error) {
throw new RuntimeUnavailableError('TheCloud diagnostics are unavailable', {cause: error})
}
const body = await response.json().catch(() => ({})) as {message?: unknown; files?: unknown; status?: unknown}
if (!response.ok) throw httpStatusToCloudError(response.status, typeof body.message === 'string' ? body.message : 'Static file deployment failed')
if (body.status !== 'deployed' || typeof body.files !== 'number') {
throw new RuntimeUnavailableError('TheCloud diagnostics returned an invalid deployment response')
}
return {status: 'deployed', files: body.files}
}
export async function deployLightsailNodeApplication(instanceName: string, form: FormData): Promise<LightsailNodeDeployment> {
const endpoint = process.env.FLOCI_ENDPOINT
if (!endpoint) throw new RuntimeUnavailableError('TheCloud diagnostics are unavailable')
let response: Response
try {
response = await fetch(new URL(`/_floci/diagnostics/lightsail/instances/${encodeURIComponent(instanceName)}/node-application`, endpoint).toString(), {
method: 'POST', body: form, redirect: 'error', signal: AbortSignal.timeout(360_000),
})
} catch (error) {
throw new RuntimeUnavailableError('TheCloud diagnostics are unavailable', {cause: error})
}
const body = await response.json().catch(() => ({})) as {message?: unknown; files?: unknown; status?: unknown; port?: unknown; releaseId?: unknown}
if (!response.ok) throw httpStatusToCloudError(response.status, typeof body.message === 'string' ? body.message : 'Node.js deployment failed')
if (body.status !== 'deployed' || typeof body.files !== 'number' || typeof body.port !== 'number' || typeof body.releaseId !== 'string') {
throw new RuntimeUnavailableError('TheCloud diagnostics returned an invalid Node.js deployment response')
}
return {status: 'deployed', files: body.files, port: body.port, releaseId: body.releaseId}
}