mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-21 06:02:13 +00:00
31 lines
917 B
TypeScript
31 lines
917 B
TypeScript
import { buildOutboundMediaLoadOptions, type OutboundMediaAccess } from "./load-options.js";
|
|
import { saveMediaBuffer } from "./store.js";
|
|
import { loadWebMedia } from "./web-media.js";
|
|
|
|
export async function resolveOutboundAttachmentFromUrl(
|
|
mediaUrl: string,
|
|
maxBytes: number,
|
|
options?: {
|
|
mediaAccess?: OutboundMediaAccess;
|
|
localRoots?: readonly string[];
|
|
readFile?: (filePath: string) => Promise<Buffer>;
|
|
},
|
|
): Promise<{ path: string; contentType?: string }> {
|
|
const media = await loadWebMedia(
|
|
mediaUrl,
|
|
buildOutboundMediaLoadOptions({
|
|
maxBytes,
|
|
mediaAccess: options?.mediaAccess,
|
|
mediaLocalRoots: options?.localRoots,
|
|
mediaReadFile: options?.readFile,
|
|
}),
|
|
);
|
|
const saved = await saveMediaBuffer(
|
|
media.buffer,
|
|
media.contentType ?? undefined,
|
|
"outbound",
|
|
maxBytes,
|
|
);
|
|
return { path: saved.path, contentType: saved.contentType };
|
|
}
|