mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-13 04:50:35 +00:00
refactor(browser): split act route modules and dedupe path guards
This commit is contained in:
31
src/browser/routes/output-paths.ts
Normal file
31
src/browser/routes/output-paths.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import fs from "node:fs/promises";
|
||||
import { resolveWritablePathWithinRoot } from "./path-output.js";
|
||||
import type { BrowserResponse } from "./types.js";
|
||||
|
||||
export async function ensureOutputRootDir(rootDir: string): Promise<void> {
|
||||
await fs.mkdir(rootDir, { recursive: true });
|
||||
}
|
||||
|
||||
export async function resolveWritableOutputPathOrRespond(params: {
|
||||
res: BrowserResponse;
|
||||
rootDir: string;
|
||||
requestedPath: string;
|
||||
scopeLabel: string;
|
||||
defaultFileName?: string;
|
||||
ensureRootDir?: boolean;
|
||||
}): Promise<string | null> {
|
||||
if (params.ensureRootDir) {
|
||||
await ensureOutputRootDir(params.rootDir);
|
||||
}
|
||||
const pathResult = await resolveWritablePathWithinRoot({
|
||||
rootDir: params.rootDir,
|
||||
requestedPath: params.requestedPath,
|
||||
scopeLabel: params.scopeLabel,
|
||||
defaultFileName: params.defaultFileName,
|
||||
});
|
||||
if (!pathResult.ok) {
|
||||
params.res.status(400).json({ error: pathResult.error });
|
||||
return null;
|
||||
}
|
||||
return pathResult.path;
|
||||
}
|
||||
Reference in New Issue
Block a user