chore(repo): restructure as monorepo with server and client workspaces
- move NestJS app into server/ subdirectory - add client/ React+TypeScript (Vite) app with Hello World - update docker-compose to build and run both services - add root package.json declaring npm workspaces - update .gitignore to cover node_modules and dist at all depths
This commit is contained in:
1 parent
afc4627353
commit
5cc16725fb
88 files changed
+12637
-405
No files matched your search
@@ -0,0 +1,61 @@
|
||||
import { Body, Controller, Post } from "@nestjs/common";
|
||||
import { ApiOperation, ApiResponse, ApiTags } from "@nestjs/swagger";
|
||||
import { BrowserService, ExecResult, OpenResult } from "./browser.service";
|
||||
import { CodeExecutorService } from "../code-executor/code-executor.service";
|
||||
import { OpenDto } from "./dto/open.dto";
|
||||
import { ExecDto } from "./dto/exec.dto";
|
||||
|
||||
@ApiTags("browser")
|
||||
@Controller()
|
||||
export class BrowserController {
|
||||
constructor(
|
||||
private readonly browserService: BrowserService,
|
||||
private readonly codeExecutor: CodeExecutorService,
|
||||
) {}
|
||||
|
||||
@Post("open")
|
||||
@ApiOperation({
|
||||
summary: "Open a URL with a stored session (cookies + localStorage)",
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 201,
|
||||
description: "Page loaded successfully",
|
||||
schema: {
|
||||
properties: {
|
||||
url: { type: "string" },
|
||||
title: { type: "string" },
|
||||
content: { type: "string" },
|
||||
},
|
||||
},
|
||||
})
|
||||
@ApiResponse({ status: 400, description: "Invalid input" })
|
||||
@ApiResponse({ status: 404, description: "Session not found" })
|
||||
@ApiResponse({ status: 500, description: "Browser automation failed" })
|
||||
open(@Body() dto: OpenDto): Promise<OpenResult> {
|
||||
return this.browserService.open(
|
||||
dto.sessionName,
|
||||
dto.url,
|
||||
dto.readerMode ?? false,
|
||||
dto.selector,
|
||||
);
|
||||
}
|
||||
|
||||
@Post("exec")
|
||||
@ApiOperation({
|
||||
summary: "Execute custom Playwright JavaScript within a stored session",
|
||||
description:
|
||||
"The `code` string is executed as an async function body with `page` (Playwright Page) and `context` (BrowserContext) in scope. The return value is serialised and returned as `result`.",
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 201,
|
||||
description: "Code executed successfully",
|
||||
schema: { properties: { result: {} } },
|
||||
})
|
||||
@ApiResponse({ status: 400, description: "Invalid input" })
|
||||
@ApiResponse({ status: 404, description: "Session not found" })
|
||||
@ApiResponse({ status: 500, description: "Execution failed" })
|
||||
exec(@Body() dto: ExecDto): Promise<ExecResult> {
|
||||
this.codeExecutor.validate(dto.code);
|
||||
return this.browserService.exec(dto.sessionName, dto.code, dto.url);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user