mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 13:31:23 +00:00
fix: enforce inbound media max-bytes during remote fetch
This commit is contained in:
@@ -92,6 +92,7 @@ describe("resolveForwardedMediaList", () => {
|
||||
expect(fetchRemoteMedia).toHaveBeenCalledWith({
|
||||
url: attachment.url,
|
||||
filePathHint: attachment.filename,
|
||||
maxBytes: 512,
|
||||
});
|
||||
expect(saveMediaBuffer).toHaveBeenCalledTimes(1);
|
||||
expect(saveMediaBuffer).toHaveBeenCalledWith(expect.any(Buffer), "image/png", "inbound", 512);
|
||||
@@ -132,6 +133,7 @@ describe("resolveForwardedMediaList", () => {
|
||||
expect(fetchRemoteMedia).toHaveBeenCalledWith({
|
||||
url: "https://media.discordapp.net/stickers/sticker-1.png",
|
||||
filePathHint: "wave.png",
|
||||
maxBytes: 512,
|
||||
});
|
||||
expect(saveMediaBuffer).toHaveBeenCalledTimes(1);
|
||||
expect(saveMediaBuffer).toHaveBeenCalledWith(expect.any(Buffer), "image/png", "inbound", 512);
|
||||
@@ -198,6 +200,7 @@ describe("resolveMediaList", () => {
|
||||
expect(fetchRemoteMedia).toHaveBeenCalledWith({
|
||||
url: "https://media.discordapp.net/stickers/sticker-2.png",
|
||||
filePathHint: "hello.png",
|
||||
maxBytes: 512,
|
||||
});
|
||||
expect(saveMediaBuffer).toHaveBeenCalledTimes(1);
|
||||
expect(saveMediaBuffer).toHaveBeenCalledWith(expect.any(Buffer), "image/png", "inbound", 512);
|
||||
|
||||
@@ -218,6 +218,7 @@ async function appendResolvedMediaFromAttachments(params: {
|
||||
const fetched = await fetchRemoteMedia({
|
||||
url: attachment.url,
|
||||
filePathHint: attachment.filename ?? attachment.url,
|
||||
maxBytes: params.maxBytes,
|
||||
});
|
||||
const saved = await saveMediaBuffer(
|
||||
fetched.buffer,
|
||||
@@ -307,6 +308,7 @@ async function appendResolvedMediaFromStickers(params: {
|
||||
const fetched = await fetchRemoteMedia({
|
||||
url: candidate.url,
|
||||
filePathHint: candidate.fileName,
|
||||
maxBytes: params.maxBytes,
|
||||
});
|
||||
const saved = await saveMediaBuffer(
|
||||
fetched.buffer,
|
||||
|
||||
@@ -319,6 +319,7 @@ export async function resolveMedia(
|
||||
url,
|
||||
fetchImpl,
|
||||
filePathHint: filePath,
|
||||
maxBytes,
|
||||
});
|
||||
const originalName = fetched.fileName ?? filePath;
|
||||
return saveMediaBuffer(fetched.buffer, fetched.contentType, "inbound", maxBytes, originalName);
|
||||
|
||||
Reference in New Issue
Block a user