fix(media): align outbound sends with fs read capability

This commit is contained in:
Peter Steinberger
2026-04-01 00:07:38 +09:00
parent 56b5ba0dcb
commit 3bb02d3338
51 changed files with 375 additions and 25 deletions

View File

@@ -17,6 +17,7 @@ export type IMessageSendOpts = {
replyToId?: string;
mediaUrl?: string;
mediaLocalRoots?: readonly string[];
mediaReadFile?: (filePath: string) => Promise<Buffer>;
maxBytes?: number;
timeoutMs?: number;
chatId?: number;
@@ -26,7 +27,10 @@ export type IMessageSendOpts = {
resolveAttachmentImpl?: (
mediaUrl: string,
maxBytes: number,
options?: { localRoots?: readonly string[] },
options?: {
localRoots?: readonly string[];
readFile?: (filePath: string) => Promise<Buffer>;
},
) => Promise<{ path: string; contentType?: string }>;
createClient?: (params: { cliPath: string; dbPath?: string }) => Promise<IMessageRpcClient>;
};
@@ -123,6 +127,7 @@ export async function sendMessageIMessage(
const resolveAttachmentFn = opts.resolveAttachmentImpl ?? resolveOutboundAttachmentFromUrl;
const resolved = await resolveAttachmentFn(opts.mediaUrl.trim(), maxBytes, {
localRoots: opts.mediaLocalRoots,
readFile: opts.mediaReadFile,
});
filePath = resolved.path;
message = resolveDeliveredIMessageText(message, resolved.contentType ?? undefined);