fix(google): guard veo video downloads · openclaw/openclaw@b5a1b7d
steipete
·
2026-04-25
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -180,7 +180,9 @@ describe("google video generation provider", () => {
|
180 | 180 | durationSeconds: 3, |
181 | 181 | }); |
182 | 182 | |
183 | | -expect(fetchMock).toHaveBeenCalledWith( |
| 183 | +expect(fetchMock).toHaveBeenCalledTimes(1); |
| 184 | +const [[downloadUrl]] = fetchMock.mock.calls as unknown as [[string, RequestInit?]]; |
| 185 | +expect(downloadUrl).toBe( |
184 | 186 | "https://generativelanguage.googleapis.com/v1beta/files/generated-video:download?alt=media&key=google-key", |
185 | 187 | ); |
186 | 188 | expect(downloadMock).not.toHaveBeenCalled(); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -6,6 +6,7 @@ import {
|
6 | 6 | resolveProviderOperationTimeoutMs, |
7 | 7 | waitProviderOperationPollInterval, |
8 | 8 | } from "openclaw/plugin-sdk/provider-http"; |
| 9 | +import { fetchWithSsrFGuard } from "openclaw/plugin-sdk/ssrf-runtime"; |
9 | 10 | import { resolvePreferredOpenClawTmpDir } from "openclaw/plugin-sdk/temp-path"; |
10 | 11 | import { normalizeOptionalString } from "openclaw/plugin-sdk/text-runtime"; |
11 | 12 | import type { |
@@ -223,21 +224,27 @@ async function downloadGeneratedVideoFromUri(params: {
|
223 | 224 | if (!downloadUrl) { |
224 | 225 | return undefined; |
225 | 226 | } |
226 | | -const response = await fetch(downloadUrl); |
227 | | -if (!response.ok) { |
228 | | -throw new Error( |
229 | | -`Failed to download Google generated video: ${response.status} ${response.statusText}`, |
230 | | -); |
| 227 | +const { response, release } = await fetchWithSsrFGuard({ |
| 228 | +url: downloadUrl, |
| 229 | +}); |
| 230 | +try { |
| 231 | +if (!response.ok) { |
| 232 | +throw new Error( |
| 233 | +`Failed to download Google generated video: ${response.status} ${response.statusText}`, |
| 234 | +); |
| 235 | +} |
| 236 | +const buffer = Buffer.from(await response.arrayBuffer()); |
| 237 | +return { |
| 238 | + buffer, |
| 239 | +mimeType: |
| 240 | +normalizeOptionalString(response.headers.get("content-type")) || |
| 241 | +normalizeOptionalString(params.mimeType) || |
| 242 | +"video/mp4", |
| 243 | +fileName: `video-${params.index + 1}.mp4`, |
| 244 | +}; |
| 245 | +} finally { |
| 246 | +await release(); |
231 | 247 | } |
232 | | -const buffer = Buffer.from(await response.arrayBuffer()); |
233 | | -return { |
234 | | - buffer, |
235 | | -mimeType: |
236 | | -normalizeOptionalString(response.headers.get("content-type")) || |
237 | | -normalizeOptionalString(params.mimeType) || |
238 | | -"video/mp4", |
239 | | -fileName: `video-${params.index + 1}.mp4`, |
240 | | -}; |
241 | 248 | } |
242 | 249 | |
243 | 250 | function extractGoogleApiErrorCode(error: unknown): number | undefined { |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。