优化
This commit is contained in:
+2
-2
@@ -17,8 +17,8 @@ export const getCurrentWarehouseProfile = () => {
|
|||||||
export const getReceivingContainer = async (containerNo) => normalizeReceivingSession(await overseasRequest('GET', `${RECEIVING_BASE}/${encodeURIComponent(containerNo)}`))
|
export const getReceivingContainer = async (containerNo) => normalizeReceivingSession(await overseasRequest('GET', `${RECEIVING_BASE}/${encodeURIComponent(containerNo)}`))
|
||||||
export const prepareReceivingContainer = async (containerNo, request) => normalizeReceivingSession(await overseasRequest('POST', `${RECEIVING_BASE}/${encodeURIComponent(containerNo)}/prepare`, request))
|
export const prepareReceivingContainer = async (containerNo, request) => normalizeReceivingSession(await overseasRequest('POST', `${RECEIVING_BASE}/${encodeURIComponent(containerNo)}/prepare`, request))
|
||||||
export const uploadCurrentUnloadPhoto = (filePath) => overseasUpload(current('/unload-photos/files'), filePath)
|
export const uploadCurrentUnloadPhoto = (filePath) => overseasUpload(current('/unload-photos/files'), filePath)
|
||||||
export const downloadCurrentUnloadPhoto = (downloadPath) => overseasDownload(downloadPath)
|
export const downloadCurrentUnloadPhoto = (downloadPath) => overseasDownload(downloadPath, { expectedContentTypePrefix: 'image/' })
|
||||||
export const downloadCurrentDomesticLoadingPhoto = (downloadPath) => overseasDownload(downloadPath)
|
export const downloadCurrentDomesticLoadingPhoto = (downloadPath) => overseasDownload(downloadPath, { expectedContentTypePrefix: 'image/' })
|
||||||
export const signCurrentReceiving = async (request) => normalizeReceivingSession(await overseasRequest('POST', current('/sign'), request))
|
export const signCurrentReceiving = async (request) => normalizeReceivingSession(await overseasRequest('POST', current('/sign'), request))
|
||||||
export const getCurrentReceiving = async () => normalizeReceivingSession(await overseasRequest('GET', current()))
|
export const getCurrentReceiving = async () => normalizeReceivingSession(await overseasRequest('GET', current()))
|
||||||
export const resolveCurrentCarton = async (cartonMark) => normalizeReceivingInbound(await overseasRequest('POST', current('/cartons/resolve'), { cartonMark }))
|
export const resolveCurrentCarton = async (cartonMark) => normalizeReceivingInbound(await overseasRequest('POST', current('/cartons/resolve'), { cartonMark }))
|
||||||
|
|||||||
+6
-1
@@ -116,7 +116,8 @@ export async function overseasUpload(path, filePath, name = 'file', retry = true
|
|||||||
return body.data
|
return body.data
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function overseasDownload(path, retry = true) {
|
export async function overseasDownload(path, options = {}) {
|
||||||
|
const { retry = true, expectedContentTypePrefix = '' } = options
|
||||||
const attemptedToken = session.token
|
const attemptedToken = session.token
|
||||||
let response = await rawDownload(path, attemptedToken)
|
let response = await rawDownload(path, attemptedToken)
|
||||||
if (retry && unauthorized(response)) {
|
if (retry && unauthorized(response)) {
|
||||||
@@ -126,6 +127,10 @@ export async function overseasDownload(path, retry = true) {
|
|||||||
if (response?.statusCode !== 200 || !response?.tempFilePath) {
|
if (response?.statusCode !== 200 || !response?.tempFilePath) {
|
||||||
throw errorFrom({ ...response, data: {} }, '签收照片下载失败')
|
throw errorFrom({ ...response, data: {} }, '签收照片下载失败')
|
||||||
}
|
}
|
||||||
|
const contentType = String(response?.header?.['content-type'] || response?.header?.['Content-Type'] || '').toLowerCase()
|
||||||
|
if (expectedContentTypePrefix && !contentType.startsWith(expectedContentTypePrefix.toLowerCase())) {
|
||||||
|
throw errorFrom({ ...response, data: {} }, '照片服务返回了无效内容,请稍后重试')
|
||||||
|
}
|
||||||
return response.tempFilePath
|
return response.tempFilePath
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -49,4 +49,4 @@ export const reportRelabelException = (relabelNo, request) => detailAction(relab
|
|||||||
export const completeRelabelTask = (relabelNo, request) => detailAction(relabelNo, '/complete', request)
|
export const completeRelabelTask = (relabelNo, request) => detailAction(relabelNo, '/complete', request)
|
||||||
export const reviewRelabelTask = (relabelNo, request) => detailAction(relabelNo, '/review', request)
|
export const reviewRelabelTask = (relabelNo, request) => detailAction(relabelNo, '/review', request)
|
||||||
export const uploadRelabelPhoto = (relabelNo, filePath) => overseasUpload(`${BASE}/${encoded(relabelNo)}/photos/files`, filePath)
|
export const uploadRelabelPhoto = (relabelNo, filePath) => overseasUpload(`${BASE}/${encoded(relabelNo)}/photos/files`, filePath)
|
||||||
export const downloadRelabelPhoto = (relabelNo, fileId) => overseasDownload(`${BASE}/${encoded(relabelNo)}/photos/files/${encoded(fileId)}/download`)
|
export const downloadRelabelPhoto = (relabelNo, fileId) => overseasDownload(`${BASE}/${encoded(relabelNo)}/photos/files/${encoded(fileId)}/download`, { expectedContentTypePrefix: 'image/' })
|
||||||
|
|||||||
@@ -174,6 +174,21 @@ 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('image download rejects a JSON error envelope returned with HTTP 200', async () => {
|
||||||
|
prepareSession()
|
||||||
|
globalThis.uni.downloadFile = (options) => options.success({
|
||||||
|
statusCode: 200,
|
||||||
|
tempFilePath: '/tmp/error.json',
|
||||||
|
header: { 'Content-Type': 'application/json', 'X-Request-Id': 'photo-request', 'X-Trace-Id': 'photo-trace' }
|
||||||
|
})
|
||||||
|
|
||||||
|
await assert.rejects(
|
||||||
|
overseasDownload('/api/pda/v1/last-leg/photo', { expectedContentTypePrefix: 'image/' }),
|
||||||
|
(error) => error.message === '照片服务返回了无效内容,请稍后重试'
|
||||||
|
&& error.requestId === 'photo-request' && error.traceId === 'photo-trace'
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
test('business and network errors retain diagnostics without refreshing or clearing a valid session', async () => {
|
test('business and network errors retain diagnostics without refreshing or clearing a valid session', async () => {
|
||||||
prepareSession(); let refreshCount = 0
|
prepareSession(); let refreshCount = 0
|
||||||
globalThis.uni.request = (options) => {
|
globalThis.uni.request = (options) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user