UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

52 lines (51 loc) • 1.68 kB
import { n as resolveFilesystemPath } from "./home-dir-EKmgmdPG.mjs"; import { d as normalizeMimeType, n as detectMime, r as extensionForMime } from "./mime-D2wVBzpa.mjs"; import { t as publishOutputFileAtomically } from "./output-file.runtime.js"; import { d as saveMediaBuffer } from "./store-zsTAVy24.mjs"; import path from "node:path"; import fs from "node:fs/promises"; //#region src/cli/media-output.ts async function writeOutputAsset(e) { if (!e.outputPath) { const t = await saveMediaBuffer(e.buffer, e.mimeType, e.subdir, Number.MAX_SAFE_INTEGER, e.originalFilename); return { path: t.path, mimeType: t.contentType, size: t.size }; } const t = resolveFilesystemPath(e.outputPath); const n = path.parse(t); const r = await detectMime({ buffer: e.buffer, headerMime: e.mimeType }) ?? e.mimeType; const i = normalizeMimeType(await detectMime({ filePath: t })); const a = normalizeMimeType(r); const o = extensionForMime(a); const s = n.ext || path.extname(e.originalFilename ?? "") || ""; const c = n.ext && i === a ? n.ext : o ?? s; const l = e.outputCount <= 1 ? path.join(n.dir, `${n.name}${c}`) : path.join(n.dir, `${n.name}-${String(e.outputIndex + 1)}${c}`); await publishOutputFileAtomically({ filePath: l, writeTemp: async (t) => { await fs.writeFile(t, e.buffer, { flag: "wx" }); } }); return { path: l, mimeType: a ?? e.mimeType, size: e.buffer.byteLength }; } async function readInputFiles(e) { return await Promise.all(e.map(async (e) => { const t = resolveFilesystemPath(e); return { path: t, buffer: await fs.readFile(t) }; })); } //#endregion export { writeOutputAsset as n, readInputFiles as t };