This commit is contained in:
@@ -23,9 +23,14 @@ function preserveResponseId(rawText, payload) {
|
||||
if (!payload || typeof payload !== 'object' || !payload.data || typeof payload.data !== 'object') {
|
||||
return payload
|
||||
}
|
||||
const match = String(rawText || '').match(/"id"\s*:\s*"?(\d+)"?/)
|
||||
if (match && match[1]) {
|
||||
payload.data.id = match[1]
|
||||
const raw = String(rawText || '')
|
||||
const idMatch = raw.match(/"id"\s*:\s*"?(\d+)"?/)
|
||||
if (idMatch && idMatch[1]) {
|
||||
payload.data.id = idMatch[1]
|
||||
}
|
||||
const fileIdMatch = raw.match(/"fileId"\s*:\s*"?(\d+)"?/)
|
||||
if (fileIdMatch && fileIdMatch[1]) {
|
||||
payload.data.fileId = fileIdMatch[1]
|
||||
}
|
||||
return payload
|
||||
}
|
||||
@@ -110,6 +115,7 @@ function uploadProfileImage(filePath) {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
uploadFile,
|
||||
chooseImageFilePath,
|
||||
uploadObjectFile,
|
||||
uploadProfileImage
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
const assert = require('assert')
|
||||
|
||||
global.API_DOMAIN = 'http://127.0.0.1/api'
|
||||
global.REQUEST_TIMEOUT = 1000
|
||||
global.ENABLE_REQUEST_SIGNING = false
|
||||
|
||||
let uploadOptions
|
||||
global.wx = {
|
||||
getStorageSync: () => ({}),
|
||||
uploadFile(options) {
|
||||
uploadOptions = options
|
||||
options.success({
|
||||
statusCode: 200,
|
||||
data: '{"code":200,"data":{"fileId":9223372036854775001,"id":9223372036854775002}}'
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const { uploadFile } = require('./upload')
|
||||
|
||||
async function run() {
|
||||
const result = await uploadFile({
|
||||
url: '/user/workbench/register/avatar',
|
||||
filePath: '/tmp/avatar.png',
|
||||
name: 'file',
|
||||
formData: { registrationTicket: 'ticket' }
|
||||
})
|
||||
|
||||
assert.strictEqual(uploadOptions.url, 'http://127.0.0.1:80/api/user/workbench/register/avatar')
|
||||
assert.strictEqual(result.fileId, '9223372036854775001')
|
||||
assert.strictEqual(result.id, '9223372036854775002')
|
||||
}
|
||||
|
||||
run().catch(error => {
|
||||
console.error(error)
|
||||
process.exitCode = 1
|
||||
})
|
||||
Reference in New Issue
Block a user