fix: serverless adapter binary body support, hide phone number in register

- Keep body as Buffer instead of utf8 string for multipart/form-data
- Set content-length header for multer compatibility
- Phone authorization shows '已授权' instead of actual number
这个提交包含在:
Guoguo
2026-05-07 05:58:41 -07:00
父节点 8427d35fb3
当前提交 9019573662
修改 2 个文件,包含 10 行新增3 行删除
+9 -2
查看文件
@@ -10,7 +10,11 @@ module.exports = function serverless(app) {
const url = path + (qsStr ? '?' + qsStr : '')
let rawBody = event.body || ''
if (event.isBase64Encoded && rawBody) rawBody = Buffer.from(rawBody, 'base64').toString('utf8')
if (event.isBase64Encoded && rawBody) {
rawBody = Buffer.from(rawBody, 'base64')
} else if (typeof rawBody === 'string') {
rawBody = Buffer.from(rawBody, 'utf8')
}
return new Promise((resolve) => {
const req = new http.IncomingMessage()
@@ -21,6 +25,9 @@ module.exports = function serverless(app) {
if (event.requestContext && event.requestContext.sourceIp) {
req.headers['x-forwarded-for'] = req.headers['x-forwarded-for'] || event.requestContext.sourceIp
}
if (rawBody.length > 0) {
req.headers['content-length'] = String(rawBody.length)
}
const res = new http.ServerResponse(req)
let body = ''
@@ -52,7 +59,7 @@ module.exports = function serverless(app) {
res.write = function (chunk) { body += chunk }
if (rawBody) {
if (rawBody.length > 0) {
req.push(rawBody)
}
req.push(null)