From 4dc88990862fa36f4f7a32317319a1884af34c67 Mon Sep 17 00:00:00 2001 From: ouyangxq <775153912@qq.com> Date: Sun, 20 Sep 2026 14:43:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/overseas.js | 4 +++- tests/overseas-request.test.mjs | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/api/overseas.js b/src/api/overseas.js index f1c7d97..3282d7e 100644 --- a/src/api/overseas.js +++ b/src/api/overseas.js @@ -174,7 +174,9 @@ export async function overseasDownload(path, options = {}) { throw errorFrom({ ...response, data: {} }, '签收照片下载失败') } 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: {} }, '照片服务返回了无效内容,请稍后重试') } return response.tempFilePath diff --git a/tests/overseas-request.test.mjs b/tests/overseas-request.test.mjs index 90b1b7d..24c2010 100644 --- a/tests/overseas-request.test.mjs +++ b/tests/overseas-request.test.mjs @@ -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}`) }) +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 () => { prepareSession() globalThis.uni.downloadFile = (options) => options.success({