fix: handle downloadContent response format correctly
client.downloadContent() returns {data: Buffer, contentType: string},
not a raw Buffer. This was causing media downloads to fail with
ERR_INVALID_ARG_TYPE.
This commit is contained in:
parent
68ebaf5014
commit
73713a574d
2 changed files with 10 additions and 2 deletions
|
|
@ -358,6 +358,7 @@ export function createMatrixRoomMessageHandler(params: MatrixMonitorHandlerParam
|
|||
const contentSize =
|
||||
typeof contentInfo?.size === "number" ? contentInfo.size : undefined;
|
||||
if (mediaUrl?.startsWith("mxc://")) {
|
||||
debugWrite(`HANDLER: attempting media download url=${mediaUrl} size=${contentSize ?? "unknown"} maxBytes=${mediaMaxBytes}`);
|
||||
logVerboseMessage(`matrix: attempting media download url=${mediaUrl} size=${contentSize ?? "unknown"} maxBytes=${mediaMaxBytes}`);
|
||||
try {
|
||||
media = await downloadMatrixMedia({
|
||||
|
|
@ -368,11 +369,14 @@ export function createMatrixRoomMessageHandler(params: MatrixMonitorHandlerParam
|
|||
maxBytes: mediaMaxBytes,
|
||||
file: contentFile,
|
||||
});
|
||||
debugWrite(`HANDLER: media download SUCCESS path=${media?.path ?? "none"}`);
|
||||
logVerboseMessage(`matrix: media download success path=${media?.path ?? "none"}`);
|
||||
} catch (err) {
|
||||
debugWrite(`HANDLER: media download FAILED: ${String(err)}`);
|
||||
logVerboseMessage(`matrix: media download failed: ${String(err)}`);
|
||||
}
|
||||
} else if (mediaUrl) {
|
||||
debugWrite(`HANDLER: skipping non-mxc url=${mediaUrl}`);
|
||||
logVerboseMessage(`matrix: skipping non-mxc media url=${mediaUrl}`);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,11 +28,15 @@ async function fetchMatrixMediaBuffer(params: {
|
|||
|
||||
// Use the client's download method which handles auth
|
||||
try {
|
||||
const buffer = await params.client.downloadContent(params.mxcUrl);
|
||||
// downloadContent returns {data: Buffer, contentType: string}
|
||||
const response = await params.client.downloadContent(params.mxcUrl);
|
||||
const buffer = response.data;
|
||||
const contentType = response.contentType;
|
||||
|
||||
if (buffer.byteLength > params.maxBytes) {
|
||||
throw new Error("Matrix media exceeds configured size limit");
|
||||
}
|
||||
return { buffer: Buffer.from(buffer) };
|
||||
return { buffer: Buffer.from(buffer), headerType: contentType };
|
||||
} catch (err) {
|
||||
throw new Error(`Matrix media download failed: ${String(err)}`);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue