mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-12 14:30:43 +00:00
* Add proxy capture core and CLI * Expand transport capture coverage * Add QA Lab capture backend * Refine QA Lab capture UI * Fix proxy capture review feedback * Fix proxy run cleanup and TTS capture * Fix proxy capture transport follow-ups * Fix debug proxy CONNECT target parsing * Harden QA Lab asset path containment
36 lines
1.0 KiB
TypeScript
36 lines
1.0 KiB
TypeScript
import { createHash } from "node:crypto";
|
|
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import { gzipSync, gunzipSync } from "node:zlib";
|
|
import type { CaptureBlobRecord } from "./types.js";
|
|
|
|
function ensureDir(dir: string) {
|
|
fs.mkdirSync(dir, { recursive: true });
|
|
}
|
|
|
|
export function writeCaptureBlob(params: {
|
|
blobDir: string;
|
|
data: Buffer;
|
|
contentType?: string;
|
|
}): CaptureBlobRecord {
|
|
ensureDir(params.blobDir);
|
|
const sha256 = createHash("sha256").update(params.data).digest("hex");
|
|
const blobId = sha256.slice(0, 24);
|
|
const outputPath = path.join(params.blobDir, `${blobId}.bin.gz`);
|
|
if (!fs.existsSync(outputPath)) {
|
|
fs.writeFileSync(outputPath, gzipSync(params.data));
|
|
}
|
|
return {
|
|
blobId,
|
|
path: outputPath,
|
|
encoding: "gzip",
|
|
sizeBytes: params.data.byteLength,
|
|
sha256,
|
|
...(params.contentType ? { contentType: params.contentType } : {}),
|
|
};
|
|
}
|
|
|
|
export function readCaptureBlobText(blobPath: string): string {
|
|
return gunzipSync(fs.readFileSync(blobPath)).toString("utf8");
|
|
}
|