UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

26 lines (25 loc) • 1.01 kB
import crypto from "node:crypto"; //#region extensions/file-transfer/src/tools/fetch-payload.ts function decodeFetchPayload(e, t) { const n = e === "file.fetch"; const r = typeof t.path === "string" ? t.path : ""; const i = t[n ? "size" : "tarBytes"]; const a = typeof i === "number" ? i : -1; const o = t[n ? "base64" : "tarBase64"]; const s = n && typeof t.mimeType === "string" ? t.mimeType : ""; const c = typeof t.sha256 === "string" ? t.sha256 : ""; if (!r || a < 0 || typeof o !== "string" || !(n ? s : o) || !c) throw new Error(`invalid ${e} payload (missing fields)`); const l = Buffer.from(o, "base64"); if (l.byteLength !== a) throw new Error(`${e} size mismatch: payload says ${a} bytes, decoded ${l.byteLength}`); if (crypto.createHash("sha256").update(l).digest("hex") !== c) throw new Error(`${e} sha256 mismatch (integrity failure)`); return { canonicalPath: r, size: a, base64: o, mimeType: s, sha256: c, buffer: l }; } //#endregion export { decodeFetchPayload as t };