Files
plainleaf/client/plugos/proxy_fetch.ts
T
wushenghuaandCodex db73584e2b
CI / config (push) Canceled after 0s
CI / test-frontend (push) Canceled after 0s
CI / test-rust (push) Canceled after 0s
CI / test-e2e (push) Canceled after 0s
CI / test-e2e-release (push) Canceled after 0s
CI / build (push) Canceled after 0s
CI / release (push) Canceled after 0s
CI / docker (push) Canceled after 0s
CI / docker-website (push) Canceled after 0s
feat: 完善账号管理与扩展体验
补齐普通用户自助账号、中文设置与快捷键提示,修复大型扩展安装和移动端弹窗,并按服务器能力限制不兼容扩展。

Co-Authored-By: Codex <noreply@anthropic.com>
2026-08-12 22:13:23 +08:00

56 lines
1.5 KiB
TypeScript

import { base64Decode, base64Encode } from "../../plug-api/lib/crypto.ts";
export type ProxyFetchRequest64 = {
method?: string;
headers?: Record<string, string>;
base64Body?: string;
};
export type ProxyFetchResponse64 = {
ok: boolean;
status: number;
headers: Record<string, string>;
// We base64 encode the body because the body can be binary data that we have to push through the worker boundary
base64Body: string;
};
export type ProxyFetchRequest = {
method?: string;
headers?: Record<string, string>;
responseEncoding?: string;
timeout?: number;
body?: Uint8Array | string | any;
};
export type ProxyFetchResponse = {
ok: boolean;
status: number;
headers: Record<string, string>;
// We base64 encode the body because the body can be binary data that we have to push through the worker boundary
body: Uint8Array | string | any;
};
export async function performLocalFetch(
url: string,
req: ProxyFetchRequest64,
): Promise<ProxyFetchResponse64> {
const result = await fetch(
url,
req &&
({
method: req.method,
headers: req.headers,
body: req.base64Body && base64Decode(req.base64Body),
// Casting to any due to TypeScript fetch type limitations
} as any),
);
return {
ok: result.ok,
status: result.status,
headers: Object.fromEntries(result.headers.entries()),
base64Body: base64Encode(
new Uint8Array(await (await result.blob()).arrayBuffer()),
),
};
}