refactor(cli): extract shared node media helpers

This commit is contained in:
Peter Steinberger
2026-02-18 23:32:32 +00:00
parent 65ef7fb4a4
commit 3b7c8fe79a
5 changed files with 76 additions and 47 deletions

View File

@@ -1,7 +1,6 @@
import { randomUUID } from "node:crypto";
import * as os from "node:os";
import * as path from "node:path";
import { writeBase64ToFile } from "./nodes-camera.js";
import { asRecord, asString, resolveTempPathParts } from "./nodes-media-utils.js";
export type ScreenRecordPayload = {
format: string;
@@ -12,14 +11,6 @@ export type ScreenRecordPayload = {
hasAudio?: boolean;
};
function asRecord(value: unknown): Record<string, unknown> {
return typeof value === "object" && value !== null ? (value as Record<string, unknown>) : {};
}
function asString(value: unknown): string | undefined {
return typeof value === "string" ? value : undefined;
}
export function parseScreenRecordPayload(value: unknown): ScreenRecordPayload {
const obj = asRecord(value);
const format = asString(obj.format);
@@ -38,9 +29,7 @@ export function parseScreenRecordPayload(value: unknown): ScreenRecordPayload {
}
export function screenRecordTempPath(opts: { ext: string; tmpDir?: string; id?: string }) {
const tmpDir = opts.tmpDir ?? os.tmpdir();
const id = opts.id ?? randomUUID();
const ext = opts.ext.startsWith(".") ? opts.ext : `.${opts.ext}`;
const { tmpDir, id, ext } = resolveTempPathParts(opts);
return path.join(tmpDir, `openclaw-screen-record-${id}${ext}`);
}