优化
This commit is contained in:
+3
-1
@@ -174,7 +174,9 @@ export async function overseasDownload(path, options = {}) {
|
|||||||
throw errorFrom({ ...response, data: {} }, '签收照片下载失败')
|
throw errorFrom({ ...response, data: {} }, '签收照片下载失败')
|
||||||
}
|
}
|
||||||
const contentType = String(response?.header?.['content-type'] || response?.header?.['Content-Type'] || '').toLowerCase()
|
const contentType = String(response?.header?.['content-type'] || response?.header?.['Content-Type'] || '').toLowerCase()
|
||||||
if (expectedContentTypePrefix && !contentType.startsWith(expectedContentTypePrefix.toLowerCase())) {
|
// App-Plus downloadFile may omit response headers even when the image body was downloaded successfully.
|
||||||
|
// Reject an explicit non-image response, but allow a valid temp file when Content-Type is unavailable.
|
||||||
|
if (expectedContentTypePrefix && contentType && !contentType.startsWith(expectedContentTypePrefix.toLowerCase())) {
|
||||||
throw errorFrom({ ...response, data: {} }, '照片服务返回了无效内容,请稍后重试')
|
throw errorFrom({ ...response, data: {} }, '照片服务返回了无效内容,请稍后重试')
|
||||||
}
|
}
|
||||||
return response.tempFilePath
|
return response.tempFilePath
|
||||||
|
|||||||
@@ -274,6 +274,20 @@ test('authenticated photo download maps the public api path through the H5 overs
|
|||||||
assert.equal(calls[0].header.Authorization, `Bearer ${value.overseasAccessToken}`)
|
assert.equal(calls[0].header.Authorization, `Bearer ${value.overseasAccessToken}`)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('native image download accepts a valid temp file when App-Plus omits response headers', async () => {
|
||||||
|
prepareSession()
|
||||||
|
globalThis.uni.downloadFile = (options) => options.success({
|
||||||
|
statusCode: 200,
|
||||||
|
tempFilePath: '_doc/uniapp_temp/photo.jpg',
|
||||||
|
header: {}
|
||||||
|
})
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
await overseasDownload('/api/pda/v1/last-leg/photo', { expectedContentTypePrefix: 'image/' }),
|
||||||
|
'_doc/uniapp_temp/photo.jpg'
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
test('image download rejects a JSON error envelope returned with HTTP 200', async () => {
|
test('image download rejects a JSON error envelope returned with HTTP 200', async () => {
|
||||||
prepareSession()
|
prepareSession()
|
||||||
globalThis.uni.downloadFile = (options) => options.success({
|
globalThis.uni.downloadFile = (options) => options.success({
|
||||||
|
|||||||
Reference in New Issue
Block a user