mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-17 02:10:47 +00:00
[codex] Extract filesystem safety primitives (#77918)
* refactor: extract filesystem safety primitives * refactor: use fs-safe for file access helpers * refactor: reuse fs-safe for media reads * refactor: use fs-safe for image reads * refactor: reuse fs-safe in qqbot media opener * refactor: reuse fs-safe for local media checks * refactor: consume cleaner fs-safe api * refactor: align fs-safe json option names * fix: preserve fs-safe migration contracts * refactor: use fs-safe primitive subpaths * refactor: use grouped fs-safe subpaths * refactor: align fs-safe api usage * refactor: adapt private state store api * chore: refresh proof gate * refactor: follow fs-safe json api split * refactor: follow reduced fs-safe surface * build: default fs-safe python helper off * fix: preserve fs-safe plugin sdk aliases * refactor: consolidate fs-safe usage * refactor: unify fs-safe store usage * refactor: trim fs-safe temp workspace usage * refactor: hide low-level fs-safe primitives * build: use published fs-safe package * fix: preserve outbound recovery durability after rebase * chore: refresh pr checks
This commit is contained in:
committed by
GitHub
parent
61481eb34f
commit
538605ff44
@@ -1,7 +1,5 @@
|
||||
import { spawn } from "node:child_process";
|
||||
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { resolvePreferredOpenClawTmpDir } from "openclaw/plugin-sdk/sandbox";
|
||||
import { tempWorkspaceSync, resolvePreferredOpenClawTmpDir } from "openclaw/plugin-sdk/sandbox";
|
||||
|
||||
type TranscodeOutcome =
|
||||
| { ok: true; buffer: Buffer }
|
||||
@@ -54,13 +52,13 @@ export async function transcodeAudioBuffer(params: {
|
||||
return { ok: false, reason: "platform-unsupported" };
|
||||
}
|
||||
|
||||
const tmpRoot = resolvePreferredOpenClawTmpDir();
|
||||
mkdirSync(tmpRoot, { recursive: true, mode: 0o700 });
|
||||
const tmpDir = mkdtempSync(join(tmpRoot, "tts-transcode-"));
|
||||
const inPath = join(tmpDir, `in.${source}`);
|
||||
const outPath = join(tmpDir, `out.${target}`);
|
||||
const tmp = tempWorkspaceSync({
|
||||
rootDir: resolvePreferredOpenClawTmpDir(),
|
||||
prefix: "tts-transcode-",
|
||||
});
|
||||
const inPath = tmp.write(`in.${source}`, params.audioBuffer);
|
||||
const outPath = tmp.path(`out.${target}`);
|
||||
try {
|
||||
writeFileSync(inPath, params.audioBuffer, { mode: 0o600 });
|
||||
const result = await runAfconvert({
|
||||
args: [...recipe, inPath, outPath],
|
||||
timeoutMs: params.timeoutMs ?? 5000,
|
||||
@@ -68,15 +66,11 @@ export async function transcodeAudioBuffer(params: {
|
||||
if (!result.ok) {
|
||||
return { ok: false, reason: "transcoder-failed", detail: result.detail };
|
||||
}
|
||||
return { ok: true, buffer: readFileSync(outPath) };
|
||||
return { ok: true, buffer: tmp.read(`out.${target}`) };
|
||||
} catch (err) {
|
||||
return { ok: false, reason: "transcoder-failed", detail: (err as Error).message };
|
||||
} finally {
|
||||
try {
|
||||
rmSync(tmpDir, { recursive: true, force: true });
|
||||
} catch {
|
||||
// best-effort cleanup
|
||||
}
|
||||
tmp.cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user