mirror of
https://github.com/logancyang/obsidian-copilot.git
synced 2026-07-22 07:50:24 +00:00
fix: use safeFetchNoThrow in BrevilabsClient to bypass CORS errors (#2213)
Replace native fetch() with safeFetchNoThrow() in makeRequest() so API calls route through Obsidian's requestUrl (Electron/Node layer) instead of Chromium's network stack, eliminating intermittent CORS failures. makeFormDataRequest retains native fetch() because safeFetch hardcodes Content-Type: application/json and calls body.toString(), which breaks FormData payloads. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
9b9bf151c1
commit
f086ad76dc
1 changed files with 10 additions and 8 deletions
|
|
@ -4,6 +4,7 @@ import { MissingPlusLicenseError } from "@/error";
|
|||
import { logInfo } from "@/logger";
|
||||
import { turnOffPlus, turnOnPlus } from "@/plusUtils";
|
||||
import { getSettings } from "@/settings/model";
|
||||
import { safeFetchNoThrow } from "@/utils";
|
||||
import { arrayBufferToBase64 } from "@/utils/base64";
|
||||
|
||||
export interface RerankResponse {
|
||||
|
|
@ -115,15 +116,16 @@ export class BrevilabsClient {
|
|||
url.searchParams.append(key, value as string);
|
||||
});
|
||||
}
|
||||
const response = await fetch(url.toString(), {
|
||||
const headers: Record<string, string> = {
|
||||
"Content-Type": "application/json",
|
||||
"X-Client-Version": this.pluginVersion,
|
||||
};
|
||||
if (!excludeAuthHeader) {
|
||||
headers.Authorization = `Bearer ${await getDecryptedKey(getSettings().plusLicenseKey)}`;
|
||||
}
|
||||
const response = await safeFetchNoThrow(url.toString(), {
|
||||
method,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
...(!excludeAuthHeader && {
|
||||
Authorization: `Bearer ${await getDecryptedKey(getSettings().plusLicenseKey)}`,
|
||||
}),
|
||||
"X-Client-Version": this.pluginVersion,
|
||||
},
|
||||
headers,
|
||||
...(method === "POST" && { body: JSON.stringify(body) }),
|
||||
});
|
||||
const data = await response.json();
|
||||
|
|
|
|||
Loading…
Reference in a new issue