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

推荐订阅源

H
Help Net Security
腾讯CDC
爱范儿
爱范儿
Google DeepMind News
Google DeepMind News
V
V2EX
Blog — PlanetScale
Blog — PlanetScale
Engineering at Meta
Engineering at Meta
GbyAI
GbyAI
量子位
F
Fortinet All Blogs
G
Google Developers Blog
T
The Blog of Author Tim Ferriss
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Hugging Face - Blog
Hugging Face - Blog
Last Week in AI
Last Week in AI
T
Tailwind CSS Blog
J
Java Code Geeks
S
SegmentFault 最新的问题
D
Docker
博客园 - 司徒正美
The GitHub Blog
The GitHub Blog
Jina AI
Jina AI
M
MIT News - Artificial intelligence
博客园 - 【当耐特】

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: share media temp save wrapper · openclaw/opencl...
vincentkoc · 2026-05-30 · via Recent Commits to openclaw:main

@@ -379,6 +379,25 @@ function buildSavedMediaResult(params: {

379379

};

380380

}

381381382+

type SavedMediaTempWriteResult = Omit<SavedMedia, "path">;

383+384+

async function saveMediaSiblingTempFile(params: {

385+

dir: string;

386+

tempPrefix: string;

387+

writeTemp: (tempPath: string) => Promise<SavedMediaTempWriteResult>;

388+

}): Promise<SavedMedia> {

389+

const { result } = await retryAfterRecreatingDir(params.dir, () =>

390+

writeSiblingTempFile<SavedMediaTempWriteResult>({

391+

dir: params.dir,

392+

mode: MEDIA_FILE_MODE,

393+

tempPrefix: params.tempPrefix,

394+

writeTemp: params.writeTemp,

395+

resolveFinalPath: (result) => path.join(params.dir, result.id),

396+

}),

397+

);

398+

return buildSavedMediaResult({ dir: params.dir, ...result });

399+

}

400+382401

async function writeSavedMediaBuffer(params: {

383402

subdir: string;

384403

id: string;

@@ -501,36 +520,26 @@ export async function saveMediaSource(

501520

await cleanOldMedia(DEFAULT_TTL_MS, { recursive: false });

502521

const baseId = crypto.randomUUID();

503522

if (looksLikeUrl(source)) {

504-

const saved = await retryAfterRecreatingDir(dir, () =>

505-

writeSiblingTempFile({

506-

dir,

507-

mode: MEDIA_FILE_MODE,

508-

tempPrefix: `.${baseId}`,

509-

writeTemp: async (tempPath) => {

510-

const { headerMime, sniffBuffer, size } = await downloadToFile(

511-

source,

512-

tempPath,

513-

headers,

514-

5,

515-

maxBytes,

516-

);

517-

const mime = await detectMime({

518-

buffer: sniffBuffer,

519-

headerMime,

520-

filePath: source,

521-

});

522-

const ext = extensionForMime(mime) ?? path.extname(new URL(source).pathname);

523-

const id = buildSavedMediaId({ baseId, ext });

524-

return { id, size, contentType: mime };

525-

},

526-

resolveFinalPath: (result) => path.join(dir, result.id),

527-

}),

528-

);

529-

return buildSavedMediaResult({

523+

return await saveMediaSiblingTempFile({

530524

dir,

531-

id: saved.result.id,

532-

size: saved.result.size,

533-

contentType: saved.result.contentType,

525+

tempPrefix: `.${baseId}`,

526+

writeTemp: async (tempPath) => {

527+

const { headerMime, sniffBuffer, size } = await downloadToFile(

528+

source,

529+

tempPath,

530+

headers,

531+

5,

532+

maxBytes,

533+

);

534+

const mime = await detectMime({

535+

buffer: sniffBuffer,

536+

headerMime,

537+

filePath: source,

538+

});

539+

const ext = extensionForMime(mime) ?? path.extname(new URL(source).pathname);

540+

const id = buildSavedMediaId({ baseId, ext });

541+

return { id, size, contentType: mime };

542+

},

534543

});

535544

}

536545

try {

@@ -591,39 +600,29 @@ export async function saveMediaStream(

591600

await fs.mkdir(dir, { recursive: true, mode: 0o700 });

592601

const baseId = crypto.randomUUID();

593602

const headerExt = extensionForAuthoritativeHeaderMime(contentType);

594-

const saved = await retryAfterRecreatingDir(dir, () =>

595-

writeSiblingTempFile<{ id: string; size: number; contentType?: string }>({

596-

dir,

597-

mode: MEDIA_FILE_MODE,

598-

tempPrefix: `.${baseId}`,

599-

writeTemp: async (tempPath) => {

600-

const { sniffBuffer, size } = await writeMediaStreamToFile({

601-

stream,

602-

tempPath,

603-

maxBytes,

604-

});

605-

const mime = await detectMime({

606-

buffer: sniffBuffer,

607-

headerMime: contentType,

608-

filePath: originalFilename ?? detectionFilePathHint,

609-

});

610-

const ext = resolveSavedMediaExtension({

611-

detectedMime: mime,

612-

headerExt,

613-

contentType,

614-

originalFilename,

615-

});

616-

const id = buildSavedMediaId({ baseId, ext, originalFilename });

617-

return { id, size, contentType: mime };

618-

},

619-

resolveFinalPath: (result) => path.join(dir, result.id),

620-

}),

621-

);

622-

return buildSavedMediaResult({

603+

return await saveMediaSiblingTempFile({

623604

dir,

624-

id: saved.result.id,

625-

size: saved.result.size,

626-

contentType: saved.result.contentType,

605+

tempPrefix: `.${baseId}`,

606+

writeTemp: async (tempPath) => {

607+

const { sniffBuffer, size } = await writeMediaStreamToFile({

608+

stream,

609+

tempPath,

610+

maxBytes,

611+

});

612+

const mime = await detectMime({

613+

buffer: sniffBuffer,

614+

headerMime: contentType,

615+

filePath: originalFilename ?? detectionFilePathHint,

616+

});

617+

const ext = resolveSavedMediaExtension({

618+

detectedMime: mime,

619+

headerExt,

620+

contentType,

621+

originalFilename,

622+

});

623+

const id = buildSavedMediaId({ baseId, ext, originalFilename });

624+

return { id, size, contentType: mime };

625+

},

627626

});

628627

}

629628