Skip to content

feat: handle proxy origin for Cloudflare Pages in mpFileUpload #639

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 19, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/utils/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,16 @@ async function getMpToken(appID: string, appsecret: string, proxyOrigin: string)
}
return ``
}
// Cloudflare Pages 环境
const isCfPage = import.meta.env.CF_PAGES === `1`
async function mpFileUpload(file: File) {
const { appID, appsecret, proxyOrigin } = JSON.parse(
let { appID, appsecret, proxyOrigin } = JSON.parse(
localStorage.getItem(`mpConfig`)!,
)

// 未填写代理域名且是cfpages环境
if (!proxyOrigin && isCfPage) {
proxyOrigin = window.location.origin
}
const access_token = await getMpToken(appID, appsecret, proxyOrigin)
if (!access_token) {
throw new Error(`获取 access_token 失败`)
Expand Down