Skip to content

Commit

Permalink
fix: adapt csdn for new proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Apr 9, 2024
1 parent 85ffb68 commit 1e439f1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 33 deletions.
31 changes: 3 additions & 28 deletions src/adaptors/web/base/baseWebApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,33 +223,8 @@ class BaseWebApi extends WebApi {
* @param headers - 请求的头部信息
* @param formData - 表单数据
* @param forceProxy - 是否强制使用代理
* @param payloadEncoding - 请求体的编码方式,默认为 text
* @param responseEncoding - 响应体的编码方式,默认为 text
* */
public async webFormFetch(
url: string,
headers: any[],
formData: FormData,
forceProxy: boolean = false,
payloadEncoding:
| "text"
| "base64"
| "base64-std"
| "base64-url"
| "base32"
| "base32-std"
| "base32-hex"
| "hex" = "text",
responseEncoding:
| "text"
| "base64"
| "base64-std"
| "base64-url"
| "base32"
| "base32-std"
| "base32-hex"
| "hex" = "text"
) {
public async webFormFetch(url: string, headers: any[], formData: FormData, forceProxy: boolean = false) {
// 如果没有可用的 CORS 代理或者没有强制使用代理,使用默认的自动检测机制
if (this.isUseSiyuanProxy || (!this.isUseSiyuanProxy && forceProxy) || !forceProxy) {
this.logger.info("Using legency web formFetch")
Expand All @@ -263,8 +238,8 @@ class BaseWebApi extends WebApi {
"POST",
undefined,
forceProxy,
payloadEncoding ?? "base64",
responseEncoding ?? "base64"
"base64",
"base64"
)
const resText = Base64.fromBase64(fetchResult.body)
const resJson = JsonUtil.safeParse<any>(resText, {} as any)
Expand Down
6 changes: 1 addition & 5 deletions src/composables/useProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,6 @@ const useProxy = (middlewareUrl?: string, corsProxyUrl?: string) => {
| "base32-hex"
| "hex" = "text"
) => {
// 修复参数,GET/HEAD 等方法不允许 body
if (params === "" || (typeof params === "object" && Object.keys(params).length === 0)) {
params = undefined
}

if (isUseSiyuanProxy || (!isUseSiyuanProxy && forceProxy)) {
logger.info("Using Siyuan forwardProxy")
return await siyuanProxyFetch(url, headers, params, method, contentType, payloadEncoding, responseEncoding)
Expand Down Expand Up @@ -258,6 +253,7 @@ const useProxy = (middlewareUrl?: string, corsProxyUrl?: string) => {
let payloadBuf = new ArrayBuffer(0)
// GET or HEAD cannot have request body
if (method !== "GET") {
debugger
const myRequest = new Request("", { method: method, body: body })
console.log("generate temp myRequest =>", myRequest)
payloadBuf = await myRequest.arrayBuffer()
Expand Down

0 comments on commit 1e439f1

Please sign in to comment.