mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 21:11:26 +00:00
refactor(cli): extract shared node media helpers
This commit is contained in:
@@ -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}`);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user