Skip to content

Commit f436d58

Browse files
authored
feat: update mp oss to save quota (doocs#564)
1 parent f303041 commit f436d58

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/utils/file.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,13 @@ async function mpFileUpload(file: File) {
360360
}
361361

362362
let url = `https://api.weixin.qq.com/cgi-bin/material/add_material?access_token=${access_token}&type=image`
363+
const fileSizeInMB = file.size / (1024 * 1024)
364+
const fileType = file.type.toLowerCase()
365+
if (fileSizeInMB < 1 && (fileType === `image/jpeg` || fileType === `image/png`)) {
366+
url = `https://api.weixin.qq.com/cgi-bin/media/uploadimg?access_token=${access_token}`
367+
}
363368
if (proxyOrigin) {
364-
url = `${proxyOrigin}/cgi-bin/material/add_material?access_token=${access_token}&type=image`
369+
url = url.replace(`https://api.weixin.qq.com`, proxyOrigin)
365370
}
366371

367372
const res = await fetch<any, { url: string }>(url, requestOptions)

0 commit comments

Comments
 (0)