feat: add companion API and Android APK shell
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import type { FastifyInstance } from 'fastify';
|
||||
import { terminalRunRequestSchema, terminalRunResponseSchema } from '@hermes-mobile/shared';
|
||||
import type { CompanionConfig } from '../config/companionConfig.js';
|
||||
import { toSafeAbsolutePath, toWorkspacePath } from '../config/paths.js';
|
||||
import { runProcess } from '../system/processes.js';
|
||||
|
||||
export async function registerTerminalRoutes(app: FastifyInstance, config: CompanionConfig): Promise<void> {
|
||||
app.post('/api/terminal/run', async (request) => {
|
||||
const body = terminalRunRequestSchema.parse(request.body);
|
||||
const cwd = toSafeAbsolutePath(config.workspaceRoot, body.cwd ?? '.');
|
||||
const result = await runProcess('/bin/sh', ['-lc', body.command], {
|
||||
cwd,
|
||||
timeoutMs: body.timeoutMs ?? 10000,
|
||||
});
|
||||
|
||||
return terminalRunResponseSchema.parse({
|
||||
cwd: toWorkspacePath(config.workspaceRoot, cwd),
|
||||
command: body.command,
|
||||
stdout: result.stdout,
|
||||
stderr: result.stderr,
|
||||
exitCode: result.exitCode,
|
||||
timedOut: result.timedOut,
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user