惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

aimingoo的专栏
aimingoo的专栏
Jina AI
Jina AI
WordPress大学
WordPress大学
Recent Announcements
Recent Announcements
G
Google Developers Blog
I
InfoQ
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Google DeepMind News
Google DeepMind News
P
Proofpoint News Feed
MyScale Blog
MyScale Blog
M
MIT News - Artificial intelligence
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
C
Check Point Blog
J
Java Code Geeks
T
Tailwind CSS Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Microsoft Security Blog
Microsoft Security Blog
MongoDB | Blog
MongoDB | Blog
V
Visual Studio Blog
人人都是产品经理
人人都是产品经理
量子位
A
About on SuperTechFans
D
DataBreaches.Net
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
refactor(media): centralize bounded remote downloads · op...
steipete · 2026-05-13 · via Recent Commits to openclaw:main

@@ -1,10 +1,6 @@

11

import { StickerFormatType, type APIAttachment, type APIStickerItem } from "discord-api-types/v10";

22

import { getFileExtension } from "openclaw/plugin-sdk/media-mime";

3-

import {

4-

fetchRemoteMedia,

5-

saveMediaBuffer,

6-

type FetchLike,

7-

} from "openclaw/plugin-sdk/media-runtime";

3+

import { saveRemoteMedia, type FetchLike } from "openclaw/plugin-sdk/media-runtime";

84

import { buildMediaPayload } from "openclaw/plugin-sdk/reply-payload";

95

import { logVerbose } from "openclaw/plugin-sdk/runtime-env";

106

import type { SsrFPolicy } from "openclaw/plugin-sdk/ssrf-runtime";

@@ -215,19 +211,23 @@ async function fetchDiscordMedia(params: {

215211

readIdleTimeoutMs?: number;

216212

totalTimeoutMs?: number;

217213

abortSignal?: AbortSignal;

214+

fallbackContentType?: string;

215+

originalFilename?: string;

218216

}) {

219217

const timeoutAbortController = params.totalTimeoutMs ? new AbortController() : undefined;

220218

const signal = mergeAbortSignals([params.abortSignal, timeoutAbortController?.signal]);

221219

let timedOut = false;

222220

let timeoutHandle: ReturnType<typeof setTimeout> | null = null;

223221224-

const fetchPromise = fetchRemoteMedia({

222+

const savePromise = saveRemoteMedia({

225223

url: params.url,

226224

filePathHint: params.filePathHint,

227225

maxBytes: params.maxBytes,

228226

fetchImpl: params.fetchImpl,

229227

ssrfPolicy: params.ssrfPolicy,

230228

readIdleTimeoutMs: params.readIdleTimeoutMs,

229+

fallbackContentType: params.fallbackContentType,

230+

originalFilename: params.originalFilename,

231231

...(signal ? { requestInit: { signal } } : {}),

232232

}).catch((error) => {

233233

if (timedOut) {

@@ -238,7 +238,7 @@ async function fetchDiscordMedia(params: {

238238239239

try {

240240

if (!params.totalTimeoutMs) {

241-

return await fetchPromise;

241+

return await savePromise;

242242

}

243243

const timeoutPromise = new Promise<never>((_, reject) => {

244244

timeoutHandle = setTimeout(() => {

@@ -248,7 +248,7 @@ async function fetchDiscordMedia(params: {

248248

}, params.totalTimeoutMs);

249249

timeoutHandle.unref?.();

250250

});

251-

return await Promise.race([fetchPromise, timeoutPromise]);

251+

return await Promise.race([savePromise, timeoutPromise]);

252252

} finally {

253253

if (timeoutHandle) {

254254

clearTimeout(timeoutHandle);

@@ -280,7 +280,7 @@ async function appendResolvedMediaFromAttachments(params: {

280280

continue;

281281

}

282282

try {

283-

const fetched = await fetchDiscordMedia({

283+

const saved = await fetchDiscordMedia({

284284

url: attachmentUrl,

285285

filePathHint: attachment.filename ?? attachmentUrl,

286286

maxBytes: params.maxBytes,

@@ -289,14 +289,9 @@ async function appendResolvedMediaFromAttachments(params: {

289289

readIdleTimeoutMs: params.readIdleTimeoutMs,

290290

totalTimeoutMs: params.totalTimeoutMs,

291291

abortSignal: params.abortSignal,

292+

fallbackContentType: attachment.content_type,

293+

originalFilename: attachment.filename,

292294

});

293-

const saved = await saveMediaBuffer(

294-

fetched.buffer,

295-

fetched.contentType ?? attachment.content_type,

296-

"inbound",

297-

params.maxBytes,

298-

attachment.filename,

299-

);

300295

params.out.push({

301296

path: saved.path,

302297

contentType: saved.contentType,

@@ -388,7 +383,7 @@ async function appendResolvedMediaFromStickers(params: {

388383

let lastError: unknown;

389384

for (const candidate of candidates) {

390385

try {

391-

const fetched = await fetchDiscordMedia({

386+

const saved = await fetchDiscordMedia({

392387

url: candidate.url,

393388

filePathHint: candidate.fileName,

394389

maxBytes: params.maxBytes,

@@ -397,14 +392,9 @@ async function appendResolvedMediaFromStickers(params: {

397392

readIdleTimeoutMs: params.readIdleTimeoutMs,

398393

totalTimeoutMs: params.totalTimeoutMs,

399394

abortSignal: params.abortSignal,

395+

fallbackContentType: inferStickerContentType(sticker),

396+

originalFilename: candidate.fileName,

400397

});

401-

const saved = await saveMediaBuffer(

402-

fetched.buffer,

403-

fetched.contentType,

404-

"inbound",

405-

params.maxBytes,

406-

candidate.fileName,

407-

);

408398

params.out.push({

409399

path: saved.path,

410400

contentType: saved.contentType,