Lets a user pick one of three Starship presets (Nerd Font Symbols, Pastel Powerline, Tokyo Night) from the Terminal page and install Starship + a Nerd Font on the active pane's SSH host with one click, instead of running a script by hand. Idempotent on the host side, and available to all authenticated users like the rest of the SSH/Docker tooling. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019hu9pZvJY4BgmcQeAw2ugk
31 lines
1.5 KiB
TypeScript
31 lines
1.5 KiB
TypeScript
import type { FastifyInstance } from 'fastify'
|
|
import { z } from 'zod'
|
|
import { withSshClient } from '../ssh/docker.js'
|
|
import { PROMPT_PRESETS, checkPromptStatus, installPrompt, isValidPresetId } from '../ssh/shellPrompt.js'
|
|
|
|
/**
|
|
* Shell prompt setup for SSH-managed hosts: lets the Terminal page show a
|
|
* preset picker and install Starship + a Nerd Font on demand, instead of
|
|
* requiring the user to run a script by hand on every host.
|
|
*/
|
|
export async function shellPromptRoutes(app: FastifyInstance) {
|
|
app.addHook('onRequest', app.authenticate)
|
|
|
|
app.get('/api/ssh/:integrationId/shell-prompt', async (req, reply) => {
|
|
const integrationId = Number((req.params as { integrationId: string }).integrationId)
|
|
const result = await withSshClient(integrationId, (client) => checkPromptStatus(client))
|
|
if (!result.ok) return reply.code(502).send({ error: result.error })
|
|
return { presets: PROMPT_PRESETS, status: result.value }
|
|
})
|
|
|
|
app.post('/api/ssh/:integrationId/shell-prompt', async (req, reply) => {
|
|
const integrationId = Number((req.params as { integrationId: string }).integrationId)
|
|
const parsed = z.object({ presetId: z.string() }).safeParse(req.body ?? {})
|
|
if (!parsed.success || !isValidPresetId(parsed.data.presetId)) {
|
|
return reply.code(400).send({ error: 'Invalid preset' })
|
|
}
|
|
const result = await withSshClient(integrationId, (client) => installPrompt(client, parsed.data.presetId))
|
|
if (!result.ok) return reply.code(502).send({ error: result.error })
|
|
return { ok: true, log: result.value.log }
|
|
})
|
|
}
|