fix(discord): bound PluralKit and voice-message JSON reads

(cherry picked from commit 597a0ba43c)
This commit is contained in:
cxbAsDev
2026-06-30 01:36:16 +08:00
committed by Dallin Romney
parent 9b4549738d
commit d08f93efdf
3 changed files with 15 additions and 4 deletions
+4
View File
@@ -7,6 +7,8 @@ type MockResponse = {
ok: boolean;
text: () => Promise<string>;
json: () => Promise<unknown>;
body: null;
arrayBuffer: () => Promise<Buffer>;
};
const buildResponse = (params: { status: number; body?: unknown }): MockResponse => {
@@ -17,6 +19,8 @@ const buildResponse = (params: { status: number; body?: unknown }): MockResponse
ok: params.status >= 200 && params.status < 300,
text: async () => textPayload,
json: async () => body ?? {},
body: null,
arrayBuffer: async () => Buffer.from(textPayload),
};
};
+5 -2
View File
@@ -1,6 +1,9 @@
// Discord plugin module implements pluralkit behavior.
import { resolveFetch } from "openclaw/plugin-sdk/fetch-runtime";
import { readResponseTextLimited } from "openclaw/plugin-sdk/provider-http";
import {
readProviderJsonResponse,
readResponseTextLimited,
} from "openclaw/plugin-sdk/provider-http";
const PLURALKIT_API_BASE = "https://api.pluralkit.me/v2";
const PLURALKIT_ERROR_BODY_LIMIT_BYTES = 8 * 1024;
@@ -59,5 +62,5 @@ export async function fetchPluralKitMessageInfo(params: {
const detail = text.trim() ? `: ${text.trim()}` : "";
throw new Error(`PluralKit API failed (${res.status})${detail}`);
}
return (await res.json()) as PluralKitMessageInfo;
return await readProviderJsonResponse<PluralKitMessageInfo>(res, "PluralKit message");
}
+6 -2
View File
@@ -22,7 +22,11 @@ import {
import { MEDIA_FFMPEG_MAX_AUDIO_DURATION_SECS } from "openclaw/plugin-sdk/media-runtime";
import { unlinkIfExists } from "openclaw/plugin-sdk/media-runtime";
import { parseStrictFiniteNumber } from "openclaw/plugin-sdk/number-runtime";
import { readResponseTextLimited } from "openclaw/plugin-sdk/provider-http";
import {
readProviderJsonResponse,
readResponseTextLimited,
} from "openclaw/plugin-sdk/provider-http";
import type { RetryRunner } from "openclaw/plugin-sdk/retry-runtime";
import { writeExternalFileWithinRoot } from "openclaw/plugin-sdk/security-runtime";
import { fetchWithSsrFGuard, type SsrFPolicy } from "openclaw/plugin-sdk/ssrf-runtime";
import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/string-coerce-runtime";
@@ -352,7 +356,7 @@ async function requestVoiceUploadUrl(params: {
if (!res.ok) {
throw await createVoiceRequestError(res, "Upload URL request failed");
}
return (await res.json()) as UploadUrlResponse;
return await readProviderJsonResponse<UploadUrlResponse>(res, "discord.voice.upload-url");
} finally {
await release();
}